Page 1 of 1

### TMP75

Posted: Sun Dec 16, 2018 4:43 pm
Dear all,

Did anyone find or has written (and willing to publish this under MIT) a driver using a TMP75 I2C temperature sensor?

Beste regards,

Roland

### Re: TMP75

Posted: Mon Dec 17, 2018 2:15 am
I don't have one of these sensors, however, the interface seems simple enough.

Configure the sensor to use a specific resolution, 9,10,11 or 12 bit.
Read 12 bits from the temperature register.
Convert data from twos compliment to temperature in Celsius.

Scan the I2C bus for the device.

Code: Select all

``````from machine import I2C, Pin
i2c = I2C(scl=Pin(5), sda=Pin(4), freq= 400000)
i2c.scan()
``````
The device by default can be found at 0x48, so you should see [72].
You can change the address by pulling A0,A1,A2 to GND.

Code: Select all

``````config = i2c.readfrom_mem(0x48, 0x01, 1)
``````
bit0 = shutdown mode (power savings)
bit 1 = thermostat mode (0=comparitor, 1=interrupt)
bits 3,4 = fault queue (number of failed measurements)
bits 5,6 = resolution (00=9bit, 01=10bit, 10=11bit, 11=12bit)
bit 7 = one shot (performs one measurement then shuts down)

Set the resolution.

Code: Select all

``````resolution = 12  # allowed values are: 9,10,11,12
config &= ~0x60  # clear bits 5,6
config |= (resolution - 9) << 5  # set bits 5,6
i2c.writeto_mem(0x48, 0x01, config)
``````

Code: Select all

``````data = i2c.readfrom_mem(0x48, 0, 2)  # read 2 bytes from device 0x48 starting at address 0

# each bit represents 0.0625 degrees Celsius.
# negative numbers are represented in binary 2s complement format.
def twos_comp(val, width):
if val >= 2**width:
raise ValueError("Value: {} out of range of {} bit value".format(val, width))
else:
return val - int((val << 1) & 2**width)

temp = data[0] << 4 | data[1] >> 4  # ignore the 4 least significant bits of the 2nd byte
temp = twos_comp(temp, 12) * 0.0625  # convert to Celsius
print(temp)
``````

### Re: TMP75

Posted: Mon Dec 17, 2018 2:16 am
Should also work for other TMPx75 sensors, TMP275, TMP175 etc.

### Re: TMP75

Posted: Thu Dec 20, 2018 11:07 pm
TNX's

Happy XMAS

R