|ESP32 In MicroPython: I2C, HTU21D and Slow Reading|
|Written by Harry Fairhead & Mike James|
|Monday, 10 July 2023|
Page 1 of 4
Using I2C with the ESP32 is easy - except when it isn't. In this example we find out how to deal with the ESP32's inability to wait for slow devices. This extract is from Programming the ESP32 in MicroPython, part of the I Programmer Library.
Programming the ESP32in MicroPython
Kindle 9.99 Paperback $10 off!!
By Harry Fairhead & Mike James
Buy from Amazon.
.In chapter but not in extract.
It is assumed that you know how basic I2C works and understand slow read protocols - clock stretching and polling. What we discover is that the ESP32 isn't well equipped for slow reads.
A Real Device
Using an I2C device has two problems - the physical connection between master and slave and figuring out what the software has to do to make it work. Here we’ll work with the HTU21D/Si7021 and the information in its datasheet to make a working temperature humidity sensor using the I2C functions we’ve just met.
If you decide to work with some other I2C device you can still follow the steps given, modifying what you do to suit it. In particular, if you select a device that only works at 5V you might need a level converter.
Given that the HTU21D has pull-up resistors you don’t need to enable the onboard pull-ups provided by the ESP32. If you notice any irregularity in the signal at higher frequencies then adding some additional pull-ups might help.
|Last Updated ( Tuesday, 11 July 2023 )|