Skip to content

Commit dcb12b4

Browse files
authored
Add more hw tests. (#2688)
- DS18B20 - BME280 (I2C) - DHT11
1 parent db92961 commit dcb12b4

File tree

9 files changed

+151
-15
lines changed

9 files changed

+151
-15
lines changed

tests/hw/esp32/README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,30 @@ All tests should be run once after a reboot, and then again without a reboot.
1414
The testing needs two boards and several resistors.
1515

1616
On board 1 connect as follows:
17-
1. IO12 - IO14 with 330Ohm
18-
2. IO14 - IO32 with 330Ohm
19-
3. IO32 - IO25 with 330Ohm
20-
4. IO2 and IO4 should be connected to a jumper wire but floating.
21-
6. IO18 - IO34
22-
7. IO18 (or IO34) - GND with 1MOhm (or similar high number).
23-
5. IO18 - IO19 with 330Ohm
24-
8. IO26 - IO33
25-
9. IO21 - IO19 with 330Ohm
17+
- IO12 - IO14 with 330Ohm
18+
- IO14 - IO32 with 330Ohm
19+
- IO32 - IO25 with 330Ohm
20+
- IO2 and IO4 should be connected to a jumper wire but floating.
21+
- IO18 - IO34
22+
- IO18 (or IO34) - GND with 1MOhm (or similar high number).
23+
- IO18 - IO19 with 330Ohm
24+
- IO26 - IO33
25+
- IO21 - IO19 with 330Ohm
2626

2727
IO2, IO4, and IO16 must stay unconnected.
2828

2929
Connect board 1 to board 2 as follows:
30-
1. GND - GND
31-
2. IO22 - IO23
32-
3. IO23 - IO22
30+
- GND - GND
31+
- IO22 - IO23
32+
- IO23 - IO22
3333

3434
On board2:
35-
1. IO19 -> HC-SR04 Echo
36-
2. IO18 -> HC-SR04 Trig
35+
- IO19 -> HC-SR04 Echo
36+
- IO18 -> HC-SR04 Trig
37+
- IO14 -> DHT11 Data
38+
- IO15 -> DS18B20 Data
39+
- IO32 -> bme280 SCL (yellow)
40+
- IO33 -> bme280 SDA (blue)
3741

3842
IO16 must stay unconnected.
3943

tests/hw/esp32/bme280-board1.toit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (C) 2025 Toitware ApS.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/LICENSE file.
4+
5+
import .test
6+
7+
main:
8+
// We just have a board1 test, so that the actual test runs on board2.
9+
run-test: print "nothing to do"

tests/hw/esp32/bme280-board2.toit

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2025 Toitware ApS.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/LICENSE file.
4+
5+
import bme280
6+
import expect show *
7+
import gpio
8+
import i2c
9+
10+
import .test
11+
12+
main:
13+
run-test: test
14+
15+
test:
16+
scl := gpio.Pin 32
17+
sda := gpio.Pin 33
18+
bus := i2c.Bus --scl=scl --sda=sda
19+
device := bus.device bme280.I2C-ADDRESS-ALT
20+
driver := bme280.Driver device
21+
22+
2.repeat:
23+
temperature := driver.read-temperature
24+
print temperature
25+
expect 12 < temperature < 35
26+
sleep --ms=200

tests/hw/esp32/dht11-board1.toit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (C) 2025 Toitware ApS.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/LICENSE file.
4+
5+
import .test
6+
7+
main:
8+
// We just have a board1 test, so that the actual test runs on board2.
9+
run-test: print "nothing to do"

tests/hw/esp32/dht11-board2.toit

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2025 Toitware ApS.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/LICENSE file.
4+
5+
import expect show *
6+
import gpio
7+
import dhtxx.dht11
8+
9+
import .test
10+
11+
main:
12+
run-test: test
13+
14+
test:
15+
data := gpio.Pin 14
16+
driver := dht11.Dht11 data
17+
18+
2.repeat:
19+
measurements := driver.read
20+
print measurements
21+
expect 12 < measurements.temperature < 35
22+
expect 15 < measurements.humidity < 80
23+
sleep --ms=500

tests/hw/esp32/ds18b20-board1.toit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (C) 2025 Toitware ApS.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/LICENSE file.
4+
5+
import .test
6+
7+
main:
8+
// We just have a board1 test, so that the actual test runs on board2.
9+
run-test: print "nothing to do"

tests/hw/esp32/ds18b20-board2.toit

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2025 Toitware ApS.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/LICENSE file.
4+
5+
import ds18b20
6+
import expect show *
7+
import gpio
8+
9+
import .test
10+
11+
main:
12+
run-test: test
13+
14+
test:
15+
data := gpio.Pin 15
16+
driver := ds18b20.Ds18b20 data
17+
18+
2.repeat:
19+
temperature := driver.read-temperature
20+
print temperature
21+
expect 12 < temperature < 35
22+
sleep --ms=200

tests/hw/esp32/package.lock

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
sdk: ^2.0.0-alpha.1
1+
sdk: ^2.0.0-alpha.144
22
prefixes:
3+
bme280: bme280-driver
4+
dhtxx: toit-dhtxx
5+
ds18b20: toit-ds18b20
36
hc_sr04: toit-hc-sr04
47
packages:
8+
bme280-driver:
9+
url: github.com/toitware/bme280-driver
10+
name: bme280
11+
version: 1.1.0
12+
hash: e2220d286aad8bbb78e27ffcbf558cbec0e1c687
13+
toit-1-wire:
14+
url: github.com/toitware/toit-1-wire
15+
name: one_wire
16+
version: 2.3.0
17+
hash: b341bf2f0dec80c1cbd6deb774c45c52e52f183f
18+
toit-dhtxx:
19+
url: github.com/toitware/toit-dhtxx
20+
name: dhtxx
21+
version: 1.4.0
22+
hash: bf69ad9ac348324803caf8919cf7e9f34aa3d343
23+
toit-ds18b20:
24+
url: github.com/toitware/toit-ds18b20
25+
name: ds18b20
26+
version: 2.1.0
27+
hash: 09534f8f474d595620531df23b61e9707e1f5483
28+
prefixes:
29+
one_wire: toit-1-wire
530
toit-hc-sr04:
631
url: github.com/lask/toit-hc-sr04
732
name: hc_sr04

tests/hw/esp32/package.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
dependencies:
2+
bme280:
3+
url: github.com/toitware/bme280-driver
4+
version: ^1.1.0
5+
dhtxx:
6+
url: github.com/toitware/toit-dhtxx
7+
version: ^1.4.0
8+
ds18b20:
9+
url: github.com/toitware/toit-ds18b20
10+
version: ^2.1.0
211
hc_sr04:
312
url: github.com/lask/toit-hc-sr04
413
version: ^2.1.1

0 commit comments

Comments
 (0)