rtc_temp.py 470 B

123456789101112131415161718
  1. import smbus
  2. import os
  3. bus = smbus.SMBus(1)
  4. address = 0x68
  5. os.system('sudo rmmod rtc_ds1307')
  6. def getTemp(address):
  7. byte_tmsb = bus.read_byte_data(address,0x11)
  8. byte_tlsb = bin(bus.read_byte_data(address,0x12))[2:].zfill(8)
  9. return byte_tmsb+int(byte_tlsb[0])*2**(-1)+int(byte_tlsb[1])*2**(-2)
  10. #print getTemp(address)
  11. Celsius = getTemp(address)
  12. Fahrenheit = 9.0/5.0 * Celsius + 32
  13. print Fahrenheit, "*F /", Celsius, "*C"
  14. os.system('sudo modprobe rtc_ds1307')