You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm struggling with simulating DHT22 sensor in esphome. I'm measuring water tank level and temperature and I need to send data to shelly (cloud data for few users). I had similar simulation working with STM32 for few years but now I switched to ESP32 because I need few other sensors reporting to homeassistant.
I tried to make it with binary sensor but i don't get timing right. The problem I have is delay after falling or rising edge. I also tried to get falling edge and wait to rising edge but somehow it's always LOW in lambda. Probably because GPIO sensor is not updated while in lambda?
I was thinking about using some other method to detect input and then change to output and send data to same GPIO.
This is the protocol. Green pulses are from shelly addon and blue is the response and data.
//delayMicroseconds(18000);
delayMicroseconds(20);
// Pull the line LOW for 80us to respond
id(DHT22s).turn_on();
delayMicroseconds(80);
// Pull the line HIGH for 80us to indicate readiness
id(DHT22s).turn_off();
delayMicroseconds(80);
// Simulate sending sensor data
uint8_t humidity_integral = 50; // Example humidity integral data
uint8_t humidity_decimal = 0; // Example humidity decimal data
uint8_t temperature_integral = 25; // Example temperature integral data
uint8_t temperature_decimal = 0; // Example temperature decimal data
uint8_t checksum = humidity_integral + humidity_decimal + temperature_integral + temperature_decimal;
for (int i = 7; i >= 0; i--) {
id(DHT22s).turn_on();
delayMicroseconds(50); // Delay between bits
id(DHT22s).turn_off();
if (humidity_integral & (1 << i)) {
delayMicroseconds(70); // Delay for '1' bit
} else {
delayMicroseconds(28); // Delay for '0' bit
}
}
for (int i = 7; i >= 0; i--) {
id(DHT22s).turn_on();
delayMicroseconds(50); // Delay between bits
id(DHT22s).turn_off();
if (humidity_decimal & (1 << i)) {
delayMicroseconds(70); // Delay for '1' bit
} else {
delayMicroseconds(28); // Delay for '0' bit
}
}
for (int i = 7; i >= 0; i--) {
id(DHT22s).turn_on();
delayMicroseconds(50); // Delay between bits
id(DHT22s).turn_off();
if (temperature_integral & (1 << i)) {
delayMicroseconds(70); // Delay for '1' bit
} else {
delayMicroseconds(28); // Delay for '0' bit
}
}
for (int i = 7; i >= 0; i--) {
id(DHT22s).turn_on();
delayMicroseconds(50); // Delay between bits
id(DHT22s).turn_off();
if (temperature_decimal & (1 << i)) {
delayMicroseconds(70); // Delay for '1' bit
} else {
delayMicroseconds(28); // Delay for '0' bit
}
}
for (int i = 7; i >= 0; i--) {
id(DHT22s).turn_on();
delayMicroseconds(50); // Delay between bits
id(DHT22s).turn_off();
if (checksum & (1 << i)) {
delayMicroseconds(70); // Delay for '1' bit
} else {
delayMicroseconds(28); // Delay for '0' bit
}
}
id(DHT22s).turn_off(); // Finish transmission
//ESP_LOGD("custom", "Data Sent");`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everybody!
I'm struggling with simulating DHT22 sensor in esphome. I'm measuring water tank level and temperature and I need to send data to shelly (cloud data for few users). I had similar simulation working with STM32 for few years but now I switched to ESP32 because I need few other sensors reporting to homeassistant.
I tried to make it with binary sensor but i don't get timing right. The problem I have is delay after falling or rising edge. I also tried to get falling edge and wait to rising edge but somehow it's always LOW in lambda. Probably because GPIO sensor is not updated while in lambda?
I was thinking about using some other method to detect input and then change to output and send data to same GPIO.
This is the protocol. Green pulses are from shelly addon and blue is the response and data.
`output:
id: DHT22s
pin:
number: GPIO9
inverted: True
mode:
output: True
open_drain: True
pullup: True
binary_sensor:
id: DHT22request
name: "DHT22 Request"
pin:
number: GPIO8
mode:
input: True
pullup: True
filters:
invert:
#internal: True
on_release:
#min_length: 16ms
#max_length: 20ms
then:
lambda: |-
Beta Was this translation helpful? Give feedback.
All reactions