1

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)
2
  • What sort of values do you expect to get? There's no built-in function to return floats from SMBus, you will have to manually convert the integers. But to do that you need to know what to expect. Commented Apr 26, 2014 at 18:44
  • Have you read ww1.microchip.com/downloads/en/DeviceDoc/21935D.pdf ? Commented Apr 26, 2014 at 18:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.