I have the TCN75A temperature sensor connected to my Raspberry Pi via SMBus and I get values from the sensor with a Python script just fine. However the values are all integers, but I want to get decimal values with two floaters. How can I do this?
The Python script I have looks like this:
import smbus
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT) #These two are LED lights, green and red
GPIO.setup(18, GPIO.OUT)
bus = smbus.SMBus(1)
address = 0x48 #This is the address found with i2cdetect in the RasPi command line.
def read():
read = bus.read_byte_data(address, 0x00) #This returns integer values.
return read
while True:
output = read()
if output < 25:
GPIO.output(12, True)
GPIO.output(18, False)
else:
GPIO.output(18, True)
GPIO.output(12, False)
print(output)