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
68f9a4c1
Commit
68f9a4c1
authored
Oct 10, 2022
by
P.M.P.C Bandara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Distance 2
parent
435bcf06
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
distance_2.py
distance_2.py
+86
-0
No files found.
distance_2.py
0 → 100644
View file @
68f9a4c1
import
RPi.GPIO
as
GPIO
import
time
import
signal
import
sys
import
pygsheets
import
pandas
as
pd
#authorization
gc
=
pygsheets
.
authorize
(
service_file
=
'/Users/erikrood/desktop/QS_Model/creds.json'
)
df
=
pd
.
DataFrame
()
# use Raspberry Pi board pin numbers
GPIO
.
setmode
(
GPIO
.
BCM
)
//
Include
the
Servo
library
#include <Servo.h>
//
Declare
the
Servo
pin
int
servoPin
=
13
;
//
Create
a
servo
object
Servo
Servo1
;
# set GPIO Pins
pinTrigger
=
18
pinEcho
=
25
t
=
1
SCOPES
=
[
'AKfycbwETCQ_Kz6KOTWnQj5y1_xczrK6FVbYuhko9UZMM_kHUblLl-lddju9wz30J5p7EkHfpg'
]
def
close
(
signal
,
frame
):
print
(
"
\n
Turning off ultrasonic distance detection...
\n
"
)
GPIO
.
cleanup
()
sys
.
exit
(
0
)
signal
.
signal
(
signal
.
SIGINT
,
close
)
//
Make
servo
go
to
90
degrees
Servo1
.
write
(
90
);
delay
(
1000
);
Servo1
.
write
(
0
);
delay
(
1000
);
# set GPIO input and output channels
GPIO
.
setup
(
pinTrigger
,
GPIO
.
OUT
)
GPIO
.
setup
(
pinEcho
,
GPIO
.
IN
)
while
t
==
1
:
# set Trigger to HIGH
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
=
55.3
-
distance
df
[
'height'
]
=
[
distancef
]
#open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet)
sh
=
gc
.
open
(
'PY to Gsheet Test'
)
#select the first sheet
wks
=
sh
[
0
]
#update the first sheet with df, starting at cell B2.
wks
.
set_dataframe
(
df
,(
1
,
1
))
print
(
"Distance:
%.1
f cm"
%
distancef
)
time
.
sleep
(
1
)
t
=
t
+
1
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