Reading TMP102 over I2C bus

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
pradeeka
Posts: 3
Joined: Sat Aug 12, 2017 1:23 am

Reading TMP102 over I2C bus

Post by pradeeka » Sat Aug 12, 2017 1:32 am

Can anyone provide me a sample MicroPython code to read temperature in Celsius/Fahrenheit from the TMP102 through micro:bit I2C? The datasheet for I2C can be found at http://www.sparkfun.com/datasheets/Sens ... tmp102.pdf.

Thanks in advance.
Pradeeka

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Reading TMP102 over I2C bus

Post by pythoncoder » Sat Aug 12, 2017 9:45 am

A quick search of this forum revealed this https://github.com/khoulihan/micropython-tmp102.
Peter Hinch
Index to my micropython libraries.

pradeeka
Posts: 3
Joined: Sat Aug 12, 2017 1:23 am

Re: Reading TMP102 over I2C bus

Post by pradeeka » Sat Aug 12, 2017 12:02 pm

Thanks for the reply. But I want to implement the code with methods mentioned in the http://microbit-micropython.readthedocs ... t/i2c.html.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Reading TMP102 over I2C bus

Post by deshipu » Sat Aug 12, 2017 12:29 pm

What's stopping you?

pradeeka
Posts: 3
Joined: Sat Aug 12, 2017 1:23 am

Re: Reading TMP102 over I2C bus

Post by pradeeka » Sun Aug 13, 2017 7:58 pm

Instead of the TMP102 sensor, I tried to read the micro:bit on board accelerator at 0x1d.
http://www.nxp.com/docs/en/data-sheet/MMA8652FC.pdf

I want to get 8-bit results for x-axis from OUT_X_MSB.

Can you verify the below code snippet?


i2c.write(0x1d, bytes([0x2a,1]), repeat=False) #To use only 8-bit results, the F_READ bit in CTRL_REG1 must
be set. When the F_READ bit is cleared, the fast read mode is disabled.

Byte = i2c.read(0x1d, 2) [1] #read from OUT_X_MSB

print(Byte * 16) #If only the 8-bit results are used, then the resolution is reduced by a factor of 16.

Post Reply