Created
December 8, 2017 22:08
-
-
Save pavelmetrokhin/d91fd5a7cadb2c273d27e30816f32977 to your computer and use it in GitHub Desktop.
A python program to request and receive the data back from the slave (arduino)
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
from OmegaExpansion import onionI2C | |
#initializing I2C communication | |
i2c = onionI2C.OnionI2C(0) | |
#initializing Slave's device address and a degree sign for printing | |
devAddres = 0x08 | |
degree = unichr(176) | |
#reading and storing the value of the 0x00 register | |
size = 1 | |
addr = 0x00 | |
val_cel_int =i2c.readBytes(devAddres, addr, size) | |
#reading and storing the value of the 0x01 register | |
size = 1 | |
addr = 0x01 | |
val_cel_frac =i2c.readBytes(devAddres, addr, size) | |
#reading and storing the value of the 0x02 register | |
size = 1 | |
addr = 0x02 | |
val_far_int = i2c.readBytes(devAddres, addr, size) | |
#reading and storing the value of the 0x03 register | |
size = 1 | |
addr = 0x03 | |
val_far_frac =i2c.readBytes(devAddres, addr, size) | |
#formating the celsius and fahrenheit values into a single variable | |
celsius = "%d.%02d"%(val_cel_int[0], val_cel_frac[0]) | |
fahrenheit = "%d.%02d"%(val_far_int[0], val_far_frac[0]) | |
#printing the temperature readings | |
print "Celsius: ", celsius + degree + "C" | |
print "Fahrenheit: ", fahrenheit + degree + "F" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment