Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group project 2025
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evan Jones
group project 2025
Commits
6d6c37c8
Commit
6d6c37c8
authored
4 months ago
by
Evan Jones
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
7b6d5cc9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test_components.py
+124
-0
124 additions, 0 deletions
test_components.py
with
124 additions
and
0 deletions
test_components.py
0 → 100644
+
124
−
0
View file @
6d6c37c8
import
time
import
grovepi
from
grove_rgb_lcd
import
*
# Define pin mappings
pir_pin
=
2
button_pin
=
3
led_pin
=
4
servo_pin
=
5
ultrasonic_pin
=
6
light_sensor_pin
=
0
def
pause
():
input
(
"
\n
Press ENTER to continue to the next test...
\n
"
)
# --- PIR Motion Sensor ---
def
test_pir
():
grovepi
.
pinMode
(
pir_pin
,
"
INPUT
"
)
print
(
"
[TEST 1] PIR Motion Sensor (D2)
"
)
print
(
"
Move in front of the sensor.
"
)
for
_
in
range
(
10
):
motion
=
grovepi
.
digitalRead
(
pir_pin
)
print
(
"
Motion Detected!
"
if
motion
else
"
No motion
"
)
time
.
sleep
(
1
)
# --- Button ---
def
test_button
():
grovepi
.
pinMode
(
button_pin
,
"
INPUT
"
)
print
(
"
[TEST 2] Button (D3)
"
)
print
(
"
Press the button.
"
)
for
_
in
range
(
10
):
state
=
grovepi
.
digitalRead
(
button_pin
)
print
(
"
Button Pressed!
"
if
state
else
"
Waiting...
"
)
time
.
sleep
(
0.5
)
# --- Buzzer or LED ---
def
test_led
():
grovepi
.
pinMode
(
led_pin
,
"
OUTPUT
"
)
print
(
"
[TEST 3] LED or Buzzer (D4)
"
)
print
(
"
It should flash/beep.
"
)
for
_
in
range
(
5
):
grovepi
.
digitalWrite
(
led_pin
,
1
)
time
.
sleep
(
0.5
)
grovepi
.
digitalWrite
(
led_pin
,
0
)
time
.
sleep
(
0.5
)
# --- Servo Motor ---
def
test_servo
():
grovepi
.
pinMode
(
servo_pin
,
"
OUTPUT
"
)
print
(
"
[TEST 4] Servo Motor (D5)
"
)
print
(
"
It should vibrate or move.
"
)
grovepi
.
analogWrite
(
servo_pin
,
255
)
time
.
sleep
(
2
)
grovepi
.
analogWrite
(
servo_pin
,
0
)
print
(
"
Servo test complete.
"
)
# --- Ultrasonic Ranger ---
def
test_ultrasonic
():
grovepi
.
pinMode
(
ultrasonic_pin
,
"
INPUT
"
)
print
(
"
[TEST 5] Ultrasonic Ranger (D6)
"
)
print
(
"
Move your hand closer/farther.
"
)
for
_
in
range
(
10
):
try
:
distance
=
grovepi
.
ultrasonicRead
(
ultrasonic_pin
)
print
(
f
"
Distance:
{
distance
}
cm
"
)
except
Exception
as
e
:
print
(
f
"
Error:
{
e
}
"
)
time
.
sleep
(
1
)
# --- Light Sensor ---
def
test_light
():
print
(
"
[TEST 6] Light Sensor (A0)
"
)
print
(
"
Cover and uncover the sensor.
"
)
for
_
in
range
(
10
):
try
:
light
=
grovepi
.
analogRead
(
light_sensor_pin
)
print
(
f
"
Light Level:
{
light
}
"
)
except
Exception
as
e
:
print
(
f
"
Error:
{
e
}
"
)
time
.
sleep
(
1
)
# --- LCD Display ---
def
test_lcd
():
print
(
"
[TEST 7] LCD Display (I2C)
"
)
try
:
setRGB
(
0
,
100
,
255
)
setText
(
"
LCD is working!
\n
All good :)
"
)
time
.
sleep
(
4
)
setText
(
"
Ready to deploy!
"
)
time
.
sleep
(
3
)
except
Exception
as
e
:
print
(
f
"
LCD Error:
{
e
}
"
)
# --- Run All Tests Sequentially ---
def
run_all_tests
():
print
(
"
\n
HARDWARE TEST
"
)
print
(
"
Press Ctrl+C anytime to exit.
\n
"
)
test_pir
()
pause
()
test_button
()
pause
()
test_led
()
pause
()
test_servo
()
pause
()
test_ultrasonic
()
pause
()
test_light
()
pause
()
test_lcd
()
print
(
"
\n
All tests completed!
"
)
if
__name__
==
"
__main__
"
:
try
:
run_all_tests
()
except
KeyboardInterrupt
:
print
(
"
\n
Test exited.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment