我通过SMBus将TCN75A温度传感器连接到我的Raspberry Pi,我从传感器获得的值很好。但是这些值都是整数,但我希望得到两个浮点数的十进制值。我怎么能这样做?
我看起来像这样的Python脚本:
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)