Skip to content

Instantly share code, notes, and snippets.

@ShawnHymel
Created August 6, 2015 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShawnHymel/084eb438f790c59685f8 to your computer and use it in GitHub Desktop.
Save ShawnHymel/084eb438f790c59685f8 to your computer and use it in GitHub Desktop.
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