Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Hyungsun Yoon
2021-05-11 17:30:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b4163544f2155ffc6fd6d25d84c9ee1b53e186c6
b4163544
1 parent
b4a82776
[HW] HC-SR04 Added
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
hardware/rpi_pico/main.py
hardware/rpi_pico/ultrasonic.py
hardware/rpi_pico/main.py
View file @
b416354
...
...
@@ -5,6 +5,7 @@ import rp2
import
neopixel
import
dht
import
bluetoooth
as
bto
import
ultrasonic
# --------------------------------------------------- #
# INIT
...
...
@@ -33,6 +34,9 @@ def _run():
send_string
=
str
(
dht_data
[
0
])
+
','
+
str
(
dht_data
[
1
])
print
(
send_string
)
bto
.
send_data_bt
(
send_string
)
elif
input_data
==
'C'
:
ultasonic_data
=
ultrasonic
.
work_sr04
()
bto
.
send_data_bt
(
str
(
ultasonic_data
))
else
:
print
(
'WRONG INPUT'
)
...
...
hardware/rpi_pico/ultrasonic.py
0 → 100644
View file @
b416354
''' Original code from https://www.iottrends.tech/blog/how-to-use-ultrasonic-sensor-with-raspberry-pi-pico/
'''
from
machine
import
Pin
import
utime
trigger
=
Pin
(
26
,
Pin
.
OUT
)
echo
=
Pin
(
27
,
Pin
.
IN
)
# --------------------------------------------------- #
# FUNCTIONS
# --------------------------------------------------- #
def
work_sr04
():
trigger
.
low
()
utime
.
sleep_us
(
2
)
trigger
.
high
()
utime
.
sleep_us
(
5
)
trigger
.
low
()
while
echo
.
value
()
==
0
:
signaloff
=
utime
.
ticks_us
()
while
echo
.
value
()
==
1
:
signalon
=
utime
.
ticks_us
()
timepassed
=
signalon
-
signaloff
distance
=
(
timepassed
*
0.0330
)
/
2
return
distance
Please
register
or
login
to post a comment