Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. from time import *
  2. import sqlite3 as sql
  3. import smbus
  4. bus = smbus.SMBus(1)
  5. #humidity = (((firstbyte << 8) | secondbyte)*125 / 65536.0)-6
  6. #temp = (((firstbyte << 8) + secondbyte)*175.72/65536.0)-46.85
  7. address = 0x40
  8. db = sql.connect("feucht.db")
  9. cursor = db.cursor()
  10. cursor.execute("create table if not exists messung(temp double,humidity double, ts text)")
  11. db.commit()
  12. try:
  13. while True:
  14. bus.write_byte(address,0xF5)
  15. sleep(0.3)
  16. msbRF = bus.read_byte(address)
  17. sleep(0.3)
  18. lsbR = bus.read_byte(address)
  19. sleep(0.3)
  20.  
  21. bus.write_byte(address,0xF3)
  22. sleep(0.3)
  23. msbTE = bus.read_byte(address)
  24. sleep(0.3)
  25. lsbTE = bus.read_byte(address)
  26. sleep(0.3)
  27.  
  28. temp = (((msbTE << 8) + lsbTE) * 175.72 / 65536.0) - 46.85
  29. humidity = (((msbRF << 8) + lsbR) * 125 / 65536.0) -6
  30.  
  31. cursor.execute("insert into messung values("+str(temp)+"," + str(humidity)+",date('now'))")
  32. sleep(30)
  33. #print("Temperatur: " + str(round(temp,2)) + "°C") #celsius
  34. #print("Luftfeuchtigkeit: " + str(round(humidity,2))+"%") # prozent
  35.  
  36. except KeyboardInterrupt:
  37. print("Programm beendet")
  38. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement