Skip to content

Commit d1aca46

Browse files
committed
feat(wokwi-dht22/dht22-pico): add test
1 parent 5ceb856 commit d1aca46

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

.github/workflows/wokwi-test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
- name: dht22-esp32
2020
path: wokwi-dht22/dht22-esp32
2121
scenario: dht22.test.yaml
22+
- name: dht22-pico
23+
path: wokwi-dht22/dht22-pico
24+
scenario: dht22.test.yaml
2225
- name: slide-potentiometer-uno
2326
path: wokwi-slide-potentiometer/pot-uno
2427
scenario: slide-potentiometer.test.yaml
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'DHT22 Sensor Test (Pi Pico)'
2+
version: 1
3+
author: 'Uri Shaked'
4+
5+
steps:
6+
- wait-serial: 'DHT22 test (Pi Pico)'
7+
# Wait for first reading
8+
- delay: 500ms
9+
# Check exact temperature and humidity values
10+
- wait-serial: 'Humidity: 45.80% Temperature: 23.50°C'
11+
# Wait for second reading to confirm consistency
12+
- delay: 500ms
13+
- wait-serial: 'Humidity: 45.80% Temperature: 23.50°C'
14+
# Set new values
15+
- set-control:
16+
part-id: dht
17+
control: temperature
18+
value: 21.5
19+
- set-control:
20+
part-id: dht
21+
control: humidity
22+
value: 66.9
23+
- delay: 500ms
24+
# Check new values
25+
- wait-serial: 'Humidity: 66.90% Temperature: 21.50°C'

wokwi-dht22/dht22-pico/diagram.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": 1,
3+
"author": "Uri Shaked",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "wokwi-pi-pico",
8+
"id": "pico",
9+
"top": 0,
10+
"left": 0,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-dht22",
15+
"id": "dht",
16+
"top": 100,
17+
"left": 100,
18+
"attrs": {
19+
"temperature": "23.5",
20+
"humidity": "45.8"
21+
}
22+
}
23+
],
24+
"connections": [
25+
["pico:GP0", "$serialMonitor:RX", "", []],
26+
["pico:GP1", "$serialMonitor:TX", "", []],
27+
["pico:GP2", "dht:SDA", "green", ["v0"]],
28+
["pico:3V3", "dht:VCC", "red", ["v0"]],
29+
["pico:GND.1", "dht:GND", "black", ["v0"]]
30+
]
31+
}

wokwi-dht22/dht22-pico/platformio.ini

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[env:pico]
2+
platform = raspberrypi
3+
board = pico
4+
framework = arduino
5+
lib_deps =
6+
adafruit/DHT sensor library@^1.4.4
7+
build_flags =
8+
-D PICO_DEFAULT_UART_TX_PIN=0
9+
-D PICO_DEFAULT_UART_RX_PIN=1

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

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <Arduino.h>
2+
#include <DHT.h>
3+
4+
#define DHTPIN 2 // 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+
Serial1.begin(115200);
11+
Serial1.println("DHT22 test (Pi Pico)");
12+
dht.begin();
13+
}
14+
15+
void loop() {
16+
delay(500);
17+
18+
float h = dht.readHumidity();
19+
float t = dht.readTemperature();
20+
21+
// Check if any reads failed and exit early (to try again)
22+
if (isnan(h) || isnan(t)) {
23+
Serial1.println("Failed to read from DHT sensor!");
24+
return;
25+
}
26+
27+
Serial1.print("Humidity: ");
28+
Serial1.print(h);
29+
Serial1.print("% Temperature: ");
30+
Serial1.print(t);
31+
Serial1.println("°C");
32+
}

wokwi-dht22/dht22-pico/wokwi.toml

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

0 commit comments

Comments
 (0)