Created
August 6, 2015 15:59
-
-
Save ShawnHymel/084eb438f790c59685f8 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 mraa | |
import time | |
# I2C Globals | |
bus = mraa.I2c(1) | |
bus.address(0x27) | |
while True: | |
# Read from sensor | |
bus.write(bytearray([0])) | |
ans = bus.read(4) | |
# Convert temperature to Celsius | |
temp = (ans[2] << 8) + ans[3] | |
temp = temp >> 2 | |
temp = (temp * float('1.007e-2')) - 40.0 | |
temp = '{:.1f}'.format(temp) | |
# Print temperature and sleep for 1 second | |
print str(temp) + 'C’ | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment