Skip to content

Commit

Permalink
Add more hw tests. (#2688)
Browse files Browse the repository at this point in the history
- DS18B20
- BME280 (I2C)
- DHT11
  • Loading branch information
floitsch authored Jan 6, 2025
1 parent db92961 commit dcb12b4
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 15 deletions.
32 changes: 18 additions & 14 deletions tests/hw/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@ All tests should be run once after a reboot, and then again without a reboot.
The testing needs two boards and several resistors.

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

IO2, IO4, and IO16 must stay unconnected.

Connect board 1 to board 2 as follows:
1. GND - GND
2. IO22 - IO23
3. IO23 - IO22
- GND - GND
- IO22 - IO23
- IO23 - IO22

On board2:
1. IO19 -> HC-SR04 Echo
2. IO18 -> HC-SR04 Trig
- IO19 -> HC-SR04 Echo
- IO18 -> HC-SR04 Trig
- IO14 -> DHT11 Data
- IO15 -> DS18B20 Data
- IO32 -> bme280 SCL (yellow)
- IO33 -> bme280 SDA (blue)

IO16 must stay unconnected.

Expand Down
9 changes: 9 additions & 0 deletions tests/hw/esp32/bme280-board1.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2025 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import .test

main:
// We just have a board1 test, so that the actual test runs on board2.
run-test: print "nothing to do"
26 changes: 26 additions & 0 deletions tests/hw/esp32/bme280-board2.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2025 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import bme280
import expect show *
import gpio
import i2c

import .test

main:
run-test: test

test:
scl := gpio.Pin 32
sda := gpio.Pin 33
bus := i2c.Bus --scl=scl --sda=sda
device := bus.device bme280.I2C-ADDRESS-ALT
driver := bme280.Driver device

2.repeat:
temperature := driver.read-temperature
print temperature
expect 12 < temperature < 35
sleep --ms=200
9 changes: 9 additions & 0 deletions tests/hw/esp32/dht11-board1.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2025 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import .test

main:
// We just have a board1 test, so that the actual test runs on board2.
run-test: print "nothing to do"
23 changes: 23 additions & 0 deletions tests/hw/esp32/dht11-board2.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2025 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import expect show *
import gpio
import dhtxx.dht11

import .test

main:
run-test: test

test:
data := gpio.Pin 14
driver := dht11.Dht11 data

2.repeat:
measurements := driver.read
print measurements
expect 12 < measurements.temperature < 35
expect 15 < measurements.humidity < 80
sleep --ms=500
9 changes: 9 additions & 0 deletions tests/hw/esp32/ds18b20-board1.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2025 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import .test

main:
// We just have a board1 test, so that the actual test runs on board2.
run-test: print "nothing to do"
22 changes: 22 additions & 0 deletions tests/hw/esp32/ds18b20-board2.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2025 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
import ds18b20
import expect show *
import gpio

import .test

main:
run-test: test

test:
data := gpio.Pin 15
driver := ds18b20.Ds18b20 data

2.repeat:
temperature := driver.read-temperature
print temperature
expect 12 < temperature < 35
sleep --ms=200
27 changes: 26 additions & 1 deletion tests/hw/esp32/package.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
sdk: ^2.0.0-alpha.1
sdk: ^2.0.0-alpha.144
prefixes:
bme280: bme280-driver
dhtxx: toit-dhtxx
ds18b20: toit-ds18b20
hc_sr04: toit-hc-sr04
packages:
bme280-driver:
url: github.com/toitware/bme280-driver
name: bme280
version: 1.1.0
hash: e2220d286aad8bbb78e27ffcbf558cbec0e1c687
toit-1-wire:
url: github.com/toitware/toit-1-wire
name: one_wire
version: 2.3.0
hash: b341bf2f0dec80c1cbd6deb774c45c52e52f183f
toit-dhtxx:
url: github.com/toitware/toit-dhtxx
name: dhtxx
version: 1.4.0
hash: bf69ad9ac348324803caf8919cf7e9f34aa3d343
toit-ds18b20:
url: github.com/toitware/toit-ds18b20
name: ds18b20
version: 2.1.0
hash: 09534f8f474d595620531df23b61e9707e1f5483
prefixes:
one_wire: toit-1-wire
toit-hc-sr04:
url: github.com/lask/toit-hc-sr04
name: hc_sr04
Expand Down
9 changes: 9 additions & 0 deletions tests/hw/esp32/package.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
dependencies:
bme280:
url: github.com/toitware/bme280-driver
version: ^1.1.0
dhtxx:
url: github.com/toitware/toit-dhtxx
version: ^1.4.0
ds18b20:
url: github.com/toitware/toit-ds18b20
version: ^2.1.0
hc_sr04:
url: github.com/lask/toit-hc-sr04
version: ^2.1.1

0 comments on commit dcb12b4

Please sign in to comment.