HDC1010 I2c with pyb1.1

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
matthiasheng
Posts: 13
Joined: Sat Oct 06, 2018 1:57 pm

HDC1010 I2c with pyb1.1

Post by matthiasheng » Sat Oct 06, 2018 2:03 pm

Hi All,

i'm new to micropython, any idea or reference for me to learn how to develop a script to read the temperature and humidity data from HDC1010 sensor through I2c interface?
http://www.ti.com/product/HDC1010
i'm confused while reading the datasheet abt registers and the methods described in micropython tutorial i2c section.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: HDC1010 I2c with pyb1.1

Post by marfis » Sun Oct 07, 2018 9:19 am

scanning through the datasheet.. . that is a standard memory mapped i2c device. so you should be fine by using any of the i2c.memread/memwrite functions.

start ln the repl, do a scan first. then try to read the device id. once that works, you should have no problems initiating the measurement functions etc

good luck!

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

Re: HDC1010 I2c with pyb1.1

Post by pythoncoder » Sun Oct 07, 2018 2:50 pm

There is a driver for HDC1008. TI state
The device has the SAME FUNCTIONALITY and PINOUT as the compared device but is NOT an exact equivalent.
So you will need to adapt the code but it might provide a starting point.
Peter Hinch
Index to my micropython libraries.

matthiasheng
Posts: 13
Joined: Sat Oct 06, 2018 1:57 pm

Re: HDC1010 I2c with pyb1.1

Post by matthiasheng » Mon Oct 22, 2018 6:37 am

Hi pythoncoder, marfis,

Thank you very much for the suggestion! It is very helpful! I will definitely spend some time to work it out soon! :D

matthiasheng
Posts: 13
Joined: Sat Oct 06, 2018 1:57 pm

Re: HDC1010 I2c with pyb1.1

Post by matthiasheng » Sun Oct 28, 2018 5:15 pm

Hi All,

Thanks for the help, i manage to make a simple script to drive HDC1010 on my ESP8266 as shown in attached screenshot. To use the driver follow the link, i just need to change 0x64 to 64.
Here are result i got with ESP32
>>> import machine
>>> i2c = machine.I2C(sda=machine.Pin(4), scl=machine.Pin(15))
>>> import time
>>> from hdc1010 import HDC1010
>>> hdc = HDC1010(i2c)
>>> hdc.reset()
>>> hdc.heater(False)
>>> print("Sensor ID: %s" % (hex(hdc.serial)))
Sensor ID: 0x3bf079fe7
>>> hdc.temp()
42.33635
>>> hdc.humi()
49.90082
>>> hdc.temp_humi()
(42.33635, 99.99847)

Here are result i got with ESP8266:
MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266
Type "help()" for more information.
>>> import machine
>>> i2c = machine.I2C(sda=machine.Pin(4), scl=machine.Pin(5))
>>> import time
>>> from hdc1010 import HDC1010
>>> hdc = HDC1010(i2c)
>>> hdc.reset()
>>> hdc.heater(False)
>>> print("Sensor ID: %s" % (hex(hdc.serial)))
Sensor ID: 0x22b069ce2
>>> hdc.temp()
27.4643
>>> hdc.humi()
45.2942
>>> hdc.temp_humi()
(27.4039, 45.1904)


The values i got from ESP32 are totally out, even the sensor id is not correct,i don't understand why ESP32 can't share the same code as ESP32? Do anyone know if i want to use the same HDC1010 with ESP32, what i can change in my code? (I understand the different pinout on them, i already handled this different)

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

Re: HDC1010 I2c with pyb1.1

Post by pythoncoder » Sun Oct 28, 2018 5:44 pm

From a software point of view the code should work identically on ESP32 and ESP8266.

If you convert those sensor ID's to binary you'll see that, for each bit that differs, the ESP32 reads 1 where the ESP8266 reads 0. This hints at a hardware issue with the ESP32 setup. It's hard to diagnose remotely but I'd check grounding and lead lengths. If you have access to an oscilloscope check the voltage levels and waveforms of data and clock lines when it's running. Check the 3.3V supply voltage statically and while running.
Peter Hinch
Index to my micropython libraries.

matthiasheng
Posts: 13
Joined: Sat Oct 06, 2018 1:57 pm

Re: HDC1010 I2c with pyb1.1

Post by matthiasheng » Wed Oct 31, 2018 7:38 am

Hi pythoncoder,

I'm actually running it with 5V, even i tried with 3V, the result are still the same. I have an logic analyzer with me and i got some screen shot to show as attached.
I'm not an expert in I2C, maybe i didn't see the problem even it look obvious, please help to check if you see any hint from the screenshot.
I have also check the 5V pin and it range from 4.985 - 4.987 when static and when running, i guess it is normal.
Attachments
Capture1.PNG
9 blocks of data
Capture1.PNG (47.27 KiB) Viewed 4503 times
Capture4.PNG
out of one of the 9 blocks of data, zoom in, the second block
Capture4.PNG (49.05 KiB) Viewed 4503 times
Capture3.PNG
out of one of the 9 blocks of data, zoom in, the first block
Capture3.PNG (50.15 KiB) Viewed 4503 times

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

Re: HDC1010 I2c with pyb1.1

Post by pythoncoder » Wed Oct 31, 2018 8:18 am

It's hard to be sure but there do seem to be some odd glitches on the SDA line where it briefly goes high. It should change state when SCL is low and stay in that state until the next time SCL is low. Excursions lasting less than a clock period are strange.

Given the symptoms (especially that it works with an ESP8266) I still suspect a problem requiring a closer look than a logic analyser provides. I'd be looking at the supply SCL and SDA lines with a 'scope: there may (for example) be glitches on the supply that a meter won't spot.
Peter Hinch
Index to my micropython libraries.

Post Reply