Skip to content

Commit 076de82

Browse files
committed
feat(wokwi-dht22/dht22-stm32): add test
1 parent d1aca46 commit 076de82

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

.github/workflows/wokwi-test.yml

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

wokwi-dht22/dht22-stm32/diagram.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version": 1,
3+
"author": "Uri Shaked",
4+
"editor": "wokwi",
5+
"parts": [
6+
{ "type": "board-st-nucleo-l031k6", "id": "nucleo", "top": 0, "left": 0, "attrs": {} },
7+
{
8+
"type": "wokwi-dht22",
9+
"id": "dht",
10+
"top": 0,
11+
"left": 300,
12+
"attrs": { "temperature": "23.5", "humidity": "45.8" }
13+
}
14+
],
15+
"connections": [
16+
[ "$serialMonitor:TX", "nucleo:VCP_RX", "", [] ],
17+
[ "$serialMonitor:RX", "nucleo:VCP_TX", "", [] ],
18+
[ "nucleo:D2", "dht:SDA", "red", [ "h-15.65", "v135.61", "h324.6" ] ],
19+
[ "nucleo:3V3", "dht:VCC", "green", [ "v1.21", "h260.25" ] ],
20+
[ "nucleo:GND.1", "dht:GND", "black", [ "h-25.25", "v154.81", "h363" ] ]
21+
],
22+
"dependencies": {}
23+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[env:nucleo_l031k6]
2+
platform = ststm32
3+
board = nucleo_l031k6
4+
framework = arduino
5+
lib_deps =
6+
adafruit/DHT sensor library@^1.4.4
7+
adafruit/Adafruit Unified Sensor@^1.1.9

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

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <Arduino.h>
2+
#include <DHT.h>
3+
4+
#define DHTPIN D2
5+
#define DHTTYPE DHT22
6+
7+
DHT dht(DHTPIN, DHTTYPE);
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
Serial.println("DHT22 test (STM32)");
12+
dht.begin();
13+
}
14+
15+
void loop() {
16+
delay(500);
17+
18+
float humidity = dht.readHumidity();
19+
float temperature = dht.readTemperature();
20+
21+
if (isnan(humidity) || isnan(temperature)) {
22+
Serial.println("Failed to read from DHT sensor!");
23+
return;
24+
}
25+
26+
Serial.print("Humidity: ");
27+
Serial.print(humidity, 2);
28+
Serial.print("% Temperature: ");
29+
Serial.print(temperature, 2);
30+
Serial.println("°C");
31+
}

wokwi-dht22/dht22-stm32/wokwi.toml

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

0 commit comments

Comments
 (0)