UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266
https://esp-idf-lib.readthedocs.io/en/latest/
1.39k stars 433 forks source link

Add support for H2 chip #583

Closed rob4226 closed 10 months ago

rob4226 commented 10 months ago

Allows building for the ESP32-H2 chip. I tried it with a couple sensors and it seems to work fine.

g-chevalier commented 10 months ago

Hi @rob4226

I tried the last version of the library with a DS18B20 on an ESP32-H2 (the ESP32-H2-DevKitM-1 exactly), and it doesn't work. The exact same code is working well on an ESP32-C6- DevKitC-1. I tried with two different devices and different GPIOs. The issue starts at the very beginning: the ds18x20_scan_devices function returns 0 devices found.

Before investigating further, I just wanted to check with you if your tests included such DS18B20 device?

rob4226 commented 10 months ago

Hi @g-chevalier

No sorry, I don't have a DS18B20 so I didn't try that one. I did throughly use a DHT-11 Humidity/Temperature sensor (which also uses a 1-wire interface) with a ESP32-H2-DevKitM-1 and that worked fine. That's strange that your C6 works but not the H2 as they are somewhat similar chips (biggest difference is no Wi-Fi on the H2). I used GPIO 22 for the 1-wire communication.

g-chevalier commented 10 months ago

Hi @rob4226

Thank you for your answer.

The DHT-11 although working with a single wire is not using the Dallas 1-Wire protocol used by the DS18B20. The implementation here relies on the "onewire" library.

However, I tested a bit more and discovered that it is working on the ESP32-H2-DevKitM-1 using GPIO22. Good news, and enough for me! In comparison with GPIO 4 & 5 that I used formerly, the GPIO22 is solely a GPIO and not multiplexed with other functions on the H2. I suspect that there is something more to do during GPIO initialization in the onewire library (or before using it in my code?) to make it working in all cases.

By the way, the other test I did on the ESP32-C6-DevKitC-1 was with GPIO11, which appears also to be a "pure" GPIO (not muxed). If I find time, I'll try on another pin later with the C6.

rob4226 commented 10 months ago

@g-chevalier Nice! Glad you got it working! Yes, that is why I chose pin 22, better chance of other things not interfering with the sensor on startup. Sometimes these 1-wire type sensors (not sure about Dallas tho) need the signal pin held a certain way, for a certain amount of time, to put it into "command mode". Otherwise, they won't respond on startup.

g-chevalier commented 10 months ago

Hi all,

Finally, it works also with multiplexed GPIO such as GPIO4.

In fact, the initialization code I used was taken from the examples in the lib, which are just doing gpio_set_pull_mode(SENSOR_GPIO, GPIO_PULLUP_ONLY);

This seems to not initialize correctly the GPIO when it is one that is multiplexed between several usages. The bellow code is working with GPIO4 on the H2:

static const gpio_num_t SENSOR_GPIO = 4;

io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT;  // The Onewire lib will take care of switchin input/output
io_conf.pin_bit_mask = (1ULL << SENSOR_GPIO);
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
gpio_config(&io_conf);

Hope it may help others...