Reading an i2c SE95 thermometer using Python, i2cset and i2cget
The SE95 is a 13 bit i2c thermometer
If you load i2ctools this gives you i2cset and i2cread
- also do i2cdetect 0 to see the address
Just my second attempt at Python - but it works!
#!/usr/bin/python import os address = sys.argv[1] # get the address argument # write a 0 to the 0 register SE95_temp = os.popen('i2cget -y 0 '+ address +' 0x00 w').read() # get the two hex bytes from the received text string (it is like 0xdc12) SE95_byte_HI_dec = int(SE95_byte_HI , 16) sign = 1 # is the temperature negative? temp_1_dec = round(temp_all, 1) if temp_1_dec == 0: temp_1_dec = sign * temp_1_dec print temp_1_dec |
The chip is SOIC surface mount so I used a SOIC to DIL8 adapter (eBay)
If you hold the chip so you can read the lable pin 1 is at bottom left
- note the sloping edge
This is my earlier Blassic basic version (for a Debian Slug) that I translated to Python for an Openwrt Slug
#!/usr/sbin/blassic address$ = PROGRAMARG$(1) 'write a 0 to the 0 register SHELL "i2cget -y 0 "+address$+" 0x00 w > /var/www/ramdisk/lm75_1.txt" PRINT "temp$ = ",temp$ print "HI$ = ",HI$ 'get the decimal value of the hex numbers sign = 1 temp_all = (HI_dec + LO_dec/256) SYSTEM |