Last active
October 25, 2016 05:20
-
-
Save kneerunjun/b2b3b7bb92b9c4df503e907dd8bf6e80 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
#!/usr/bin/python | |
import RPi.GPIO as gpio | |
import time | |
import math | |
gpio.setmode(gpio.BOARD) | |
gpio.setwarnings(False) | |
print('Temperature oC') | |
print('-------------------') | |
while True: | |
gpio.setup (5, gpio.IN) | |
gpio.setup (3, gpio.OUT) | |
gpio.output(3, gpio.LOW) | |
time.sleep(0.08) | |
gpio.setup(3, gpio.IN) | |
starttime=time.time() | |
endtime=starttime | |
try: | |
while gpio.input(5) == gpio.LOW: | |
endtime = time.time() | |
if endtime-starttime >5: | |
raise Exception('We waited too long for the pin to turn high, did not receive the signal') | |
time_factor = (endtime-starttime)/0.00315 | |
e=2.71828 | |
up_voltage=1.32 | |
opamp_gain=4.8 | |
supply=up_voltage /(opamp_gain* (1-(math.pow(e,-time_factor)))) | |
print(supply*100) | |
except Exception as e: | |
print(str(e)) | |
continue | |
finally: | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment