Created
March 10, 2017 13:58
-
-
Save Kinani/4f7c49482af467cabd819da577f3398e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
import pydocumentdb.document_client as document_client | |
masterKey = 'YOUR_PRIMARY_KEY' | |
host = 'YOUR_END_POINT' | |
client = document_client.DocumentClient(host, {'masterKey': masterKey}) | |
while True: | |
GPIO.setmode(GPIO.BCM) | |
TRIG = 23 | |
ECHO = 24 | |
print "Distance Measurement In Progress" | |
GPIO.setup(TRIG,GPIO.OUT) | |
GPIO.setup(ECHO,GPIO.IN) | |
GPIO.output(TRIG, False) | |
print "Waiting For Sensor To Settle" | |
time.sleep(2) | |
GPIO.output(TRIG, True) | |
time.sleep(0.00001) | |
GPIO.output(TRIG, False) | |
while GPIO.input(ECHO)==0: | |
pulse_start = time.time() | |
while GPIO.input(ECHO)==1: | |
pulse_end = time.time() | |
pulse_duration = pulse_end - pulse_start | |
distance = pulse_duration * 17150 | |
distance = round(distance, 2) | |
print "Distance:",distance,"cm" | |
GPIO.cleanup() | |
document_definition = {'id': '', | |
'reading' : distance} | |
created_document = client.UpsertDocument('dbs/SensorsReadings/colls/UltraSonicCollection',document_definition) | |
time.sleep(2.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment