Skip to content

Commit 5ceb856

Browse files
committed
feat(wokwi-dht22/dht22-esp32): add test
1 parent 74517a9 commit 5ceb856

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

.github/workflows/wokwi-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
- name: dht22-uno
1717
path: wokwi-dht22/dht22-uno
1818
scenario: dht22.test.yaml
19+
- name: dht22-esp32
20+
path: wokwi-dht22/dht22-esp32
21+
scenario: dht22.test.yaml
1922
- name: slide-potentiometer-uno
2023
path: wokwi-slide-potentiometer/pot-uno
2124
scenario: slide-potentiometer.test.yaml
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'DHT22 Sensor Test (ESP32)'
2+
version: 1
3+
author: 'Uri Shaked'
4+
5+
steps:
6+
# Make sure we're running on the ESP32
7+
- wait-serial: 'ets Jul 29 2019 12:21:46'
8+
- wait-serial: 'DHT22 test!'
9+
# Wait for first reading
10+
- delay: 500ms
11+
# Check exact temperature and humidity values
12+
- wait-serial: 'Humidity: 45.80% Temperature: 23.50°C'
13+
# Wait for second reading to confirm consistency
14+
- delay: 500ms
15+
- wait-serial: 'Humidity: 45.80% Temperature: 23.50°C'
16+
# Set new values
17+
- set-control:
18+
part-id: dht
19+
control: temperature
20+
value: 21.5
21+
- set-control:
22+
part-id: dht
23+
control: humidity
24+
value: 66.9
25+
- delay: 500ms
26+
# Check new values
27+
- wait-serial: 'Humidity: 66.90% Temperature: 21.50°C'

wokwi-dht22/dht22-esp32/diagram.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"version": 1,
3+
"author": "Uri Shaked",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-devkit-c-v4",
8+
"id": "esp",
9+
"attrs": {
10+
"frequency": "240"
11+
}
12+
},
13+
{
14+
"type": "wokwi-dht22",
15+
"id": "dht",
16+
"attrs": {
17+
"temperature": "23.5",
18+
"humidity": "45.8"
19+
}
20+
}
21+
],
22+
"connections": [
23+
["esp:TX", "$serialMonitor:RX", "", []],
24+
["esp:RX", "$serialMonitor:TX", "", []],
25+
["esp:4", "dht:SDA", "green", ["v0"]],
26+
["esp:3V3", "dht:VDD", "red", ["v1"]],
27+
["esp:GND.1", "dht:GND", "black", ["v2"]]
28+
]
29+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[env:esp32dev]
2+
platform = espressif32
3+
board = esp32dev
4+
framework = arduino
5+
monitor_speed = 115200
6+
lib_deps =
7+
adafruit/DHT sensor library@^1.4.4

wokwi-dht22/dht22-esp32/src/main.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <Arduino.h>
2+
#include <DHT.h>
3+
4+
#define DHTPIN 4 // Digital pin connected to the DHT sensor
5+
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
6+
7+
DHT dht(DHTPIN, DHTTYPE);
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
Serial.println("DHT22 test!");
12+
dht.begin();
13+
}
14+
15+
void loop() {
16+
// Wait a few seconds between measurements
17+
delay(2000);
18+
19+
// Reading temperature or humidity takes about 250 milliseconds!
20+
float h = dht.readHumidity();
21+
float t = dht.readTemperature();
22+
23+
// Check if any reads failed and exit early (to try again)
24+
if (isnan(h) || isnan(t)) {
25+
Serial.println("Failed to read from DHT sensor!");
26+
return;
27+
}
28+
29+
Serial.printf("Humidity: %.2f%% Temperature: %.2f°C\n", h, t);
30+
}

wokwi-dht22/dht22-esp32/wokwi.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[wokwi]
2+
version = 1
3+
firmware = '.pio/build/esp32dev/firmware.bin'
4+
elf = '.pio/build/esp32dev/firmware.elf'

0 commit comments

Comments
 (0)