Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-104
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-104
2022-104
Commits
0263650d
Commit
0263650d
authored
Nov 14, 2022
by
P.M.P.C Bandara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New Distance measurement file added
parent
68f9a4c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
distance_new.py
distance_new.py
+66
-0
No files found.
distance_new.py
0 → 100644
View file @
0263650d
import
RPi.GPIO
as
GPIO
import
time
import
signal
import
sys
import
pandas
as
pd
from
csv
import
writer
# use Raspberry Pi board pin numbers
GPIO
.
setmode
(
GPIO
.
BCM
)
from
datetime
import
date
today
=
date
.
today
()
# set GPIO Pins
pinTrigger
=
18
pinEcho
=
25
t
=
1
def
close
(
signal
,
frame
):
print
(
"
\n
Turning off ultrasonic distance detection...
\n
"
)
GPIO
.
cleanup
()
sys
.
exit
(
0
)
signal
.
signal
(
signal
.
SIGINT
,
close
)
# set GPIO input and output channels
GPIO
.
setup
(
pinTrigger
,
GPIO
.
OUT
)
GPIO
.
setup
(
pinEcho
,
GPIO
.
IN
)
while
t
==
1
:
# set Trigger to HIGH
field_names
=
[
'Date'
,
'Height'
]
GPIO
.
output
(
pinTrigger
,
True
)
# set Trigger after 0.01ms to LOW
time
.
sleep
(
0.00001
)
GPIO
.
output
(
pinTrigger
,
False
)
startTime
=
time
.
time
()
stopTime
=
time
.
time
()
# save start time
while
0
==
GPIO
.
input
(
pinEcho
):
startTime
=
time
.
time
()
# save time of arrival
while
1
==
GPIO
.
input
(
pinEcho
):
stopTime
=
time
.
time
()
# time difference between start and arrival
TimeElapsed
=
stopTime
-
startTime
# multiply with the sonic speed (34300 cm/s)
# and divide by 2, because there and back
distance
=
(
TimeElapsed
*
34300
)
/
2
distancef
=
60.0
-
distance
print
(
"Distance:
%.1
f cm"
%
distancef
)
time
.
sleep
(
1
)
row_contents
=
[
today
,
distancef
]
with
open
(
'new.csv'
,
'a+'
,
newline
=
''
)
as
write_obj
:
csv_writer
=
writer
(
write_obj
)
csv_writer
.
writerow
(
row_contents
)
print
(
'a'
)
t
=
t
+
1
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment