Skip to content

Commit 157adbe

Browse files
committed
feat(wokwi-dht22/dht22-uno): initial test case
0 parents  commit 157adbe

File tree

8 files changed

+127
-0
lines changed

8 files changed

+127
-0
lines changed

.github/workflows/wokwi-test.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Wokwi CI Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install PlatformIO
16+
run: |
17+
python -m pip install --upgrade pip
18+
pip install platformio
19+
20+
- name: Build with PlatformIO
21+
working-directory: wokwi-dht22/dht22-uno
22+
run: pio run
23+
24+
- name: Run Wokwi CI Server
25+
uses: wokwi/wokwi-ci-server-action@v1
26+
27+
- name: Test with Wokwi
28+
uses: wokwi/wokwi-ci-action@v1
29+
with:
30+
token: ${{ secrets.WOKWI_CLI_TOKEN }}
31+
path: wokwi-dht22/dht22-uno
32+
timeout: 10000
33+
scenario: dht22.test.yaml
34+
serial_log_file: serial.log

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env.local
2+
.pio

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Wokwi Part Tests
2+
3+
This repository contains a set of test projects for many Wokwi parts. The tests can be compiled
4+
using platformio and then run using the Wokwi CLI.

wokwi-dht22/dht22-uno/dht22.test.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'DHT22 Sensor Test'
2+
version: 1
3+
author: 'Uri Shaked'
4+
5+
steps:
6+
- wait-serial: 'DHT22 test!'
7+
# Wait for first reading
8+
- delay: 2000ms
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: 2000ms
13+
- wait-serial: 'Humidity: 45.80% Temperature: 23.50°C'

wokwi-dht22/dht22-uno/diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "Uri Shaked",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"id": "uno",
8+
"type": "wokwi-arduino-uno",
9+
"top": 160,
10+
"left": 20
11+
},
12+
{
13+
"id": "dht",
14+
"type": "wokwi-dht22",
15+
"top": 0,
16+
"left": 70,
17+
"attrs": {
18+
"temperature": "23.5",
19+
"humidity": "45.8"
20+
}
21+
}
22+
],
23+
"connections": [
24+
["uno:GND.1", "dht:GND", "black", ["v-20", "*", "v5"]],
25+
["uno:2", "dht:SDA", "green", ["v-16", "*", "h0"]],
26+
["uno:5V", "dht:VCC", "red", ["v20", "*", "h0"]]
27+
]
28+
}

wokwi-dht22/dht22-uno/platformio.ini

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[env:uno]
2+
platform = atmelavr
3+
board = uno
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-uno/src/main.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
Serial.begin(9600);
11+
Serial.println(F("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+
// Read temperature as Celsius (the default)
22+
float t = dht.readTemperature();
23+
24+
// Check if any reads failed and exit early (to try again)
25+
if (isnan(h) || isnan(t)) {
26+
Serial.println(F("Failed to read from DHT sensor!"));
27+
return;
28+
}
29+
30+
Serial.print(F("Humidity: "));
31+
Serial.print(h);
32+
Serial.print(F("% Temperature: "));
33+
Serial.print(t);
34+
Serial.println(F("°C "));
35+
}

wokwi-dht22/dht22-uno/wokwi.toml

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

0 commit comments

Comments
 (0)