Guest User

Untitled

a guest
Dec 11th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. from OmegaExpansion import onionI2C
  2.  
  3. #initializing I2C communication
  4. i2c = onionI2C.OnionI2C(0)
  5.  
  6. #initializing Slave's device address and a degree sign for printing
  7. devAddres = 0x08
  8. degree = unichr(176)
  9.  
  10. #reading and storing the value of the 0x00 register
  11. size = 1
  12. addr = 0x00
  13. val_cel_int =i2c.readBytes(devAddres, addr, size)
  14.  
  15. #reading and storing the value of the 0x01 register
  16. size = 1
  17. addr = 0x01
  18. val_cel_frac =i2c.readBytes(devAddres, addr, size)
  19.  
  20. #reading and storing the value of the 0x02 register
  21. size = 1
  22. addr = 0x02
  23. val_far_int = i2c.readBytes(devAddres, addr, size)
  24.  
  25. #reading and storing the value of the 0x03 register
  26. size = 1
  27. addr = 0x03
  28. val_far_frac =i2c.readBytes(devAddres, addr, size)
  29.  
  30. #formating the celsius and fahrenheit values into a single variable
  31. celsius = "%d.%02d"%(val_cel_int[0], val_cel_frac[0])
  32. fahrenheit = "%d.%02d"%(val_far_int[0], val_far_frac[0])
  33.  
  34. #printing the temperature readings
  35. print "Celsius: ", celsius + degree + "C"
  36. print "Fahrenheit: ", fahrenheit + degree + "F"
Add Comment
Please, Sign In to add comment