RobTillaart / DHT20

Arduino library for DHT20 I2C temperature and humidity sensor.
MIT License
21 stars 6 forks source link

ESP32-C3-DevKitC-02 with DHT20 #18

Closed rrbailey27 closed 6 months ago

rrbailey27 commented 6 months ago

The ESP32-C3-DevKitC-02 doesn't have dedicated I2C. I was hoping to use the DHT20 with it - using the example code DHT20_test_esp.ino.

I wired it all up and selected 2 GPIO pins, including updating that in the code. The only line I changed was:

Wire1.begin(20, 21); // select your pin numbers here

The output is not good!

07:56:28.615 -> Type,   Status, Humidity (%),   Temperature (C)
07:56:28.615 -> DHT20,  Read time out0.0,   0.0
07:56:31.606 -> DHT20, 

Any advice? I really want/need to get these sensors working on the ESP32-C3-DevKitC-02. I am proficient in using ESP32 on the Arduino IDE, but I don't have the experience necessary to do a lot more than standard troubleshooting... More on the ESP32-C3-DevKitC-02 is here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitc-02.html

RobTillaart commented 6 months ago

Thanks for the issue, As I am rather busy I will look into this asap, it might even be next week.

(thanks for providing the link)

rrbailey27 commented 6 months ago

thanks for the quick reply. and big time thanks for all of your work on this library. fingers crossed that this one is an easy issue to resolve - e.g., perhaps just a small thing I am doing wrong.

rrbailey27 commented 6 months ago

After first making sure my DHT20 works with an Uno (With the DHT20.ino example file), I just tried what I ALWAYS tell my students not to try. I tried putting the SDA and SCL pins in every GPIO pair on the ESP32. One nice thing about the DTH20.ino file is it keeps reading every second .... so I can keep trying different pairs. Seeing reading after reading of 0.0, I was about to give up. But then I tried GPIO 8 and GPIO9 and they worked!

More specifically, DHT20 SDA pin - connect to ESP32-C3-DevKitC-02 GPIO8 DHT20 SCL pin -connect to ESP32-C3-DevKitC-02 GPIO9

This is my breathing on the sensor to see if is working:

09:09:00.014 -> DHT20   58.6        19.9        44894       OK
09:09:01.046 -> DHT20   70.2        20.2        44889       OK
09:09:02.130 -> DHT20   77.2        20.2        44887       OK
09:09:03.138 -> DHT20   81.1        20.2        44893       OK
09:09:04.179 -> DHT20   82.8        20.2        44888       OK
09:09:05.215 -> DHT20   85.9        20.6        44893       OK
09:09:06.263 -> DHT20   98.9        22.6        44888       OK
09:09:07.286 -> DHT20   100.0       23.7        44893       OK

I'd be interested in knowing what you think is the reason why these two pins worked... if you have any such insights. It seems like it must be that these pins are the "strapping pins" for the board... but I'm not totally sure what that means/how it relates to I2C.

RobTillaart commented 6 months ago

image

(Image from https://mischianti.org/esp32-c3-devkitc-02-high-resolution-pinout-and-specs/ )

Apparently if you search a bit you get mixed info about I2C on the ES32-C3. Many state it has no I2C, but this site says it has and the good news is that they match your findings.

e.g. https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitc-02.html

States no I2C.

So it might be that in a first release they did not support I2C (properly) and that it was added in a next release. These things happen also for my libraries, sort of organic growth, evolution (and some times revolution). And documentation is often lagging behind .

RobTillaart commented 6 months ago

BTW found these by googling: +ESP32-C3 +pinout

rrbailey27 commented 6 months ago

I had in fact seen both referenced pages - I just trusted the official espressif one more... so it goes! And the mischianti page alslo has the following lines,

I2C (Inter-Integrated Circuit) pins: The ESP32-C3 does not have dedicated I2C pins. However, you can implement software-based I2C (bit-banging) using any available GPIO pins. For instance, you could use GPIO12 (SPIHD) and GPIO13 (SPIWP) for the I2C SCL (clock) and SDA (data) pins, respectively.

which admittedly scared me away from thinking I could solve this just by plugging pins into GPIO8 and GPIO9.

Thanks for your help. And I hope this thread can help others in the same situation. This is the way...

RobTillaart commented 6 months ago

IF there are no more questions you may close the issue

rrbailey27 commented 6 months ago

issues closed! Thanks! I hope others find this information helpful!