Read a sensor
SHT3X over I2C: pick a part token, attach it to the bus, fetch, and read typed channels — plus a hardware test that checks the readings are sane.
Click through the files — it's the whole project
Read a sensor — Visual Studio Code
Select a file from the explorer
SHT3X · I2C 0x44 Sensor · I2C0 · testing
What's going on
- There's no per-sensor library to install.
SENSOR.sensirion_sht3xdnames the part,I2C0.device(0x44)names the bus and address, and the build produces the driver binding. fetch()takes one measurement;get()reads a channel from it. Two channels, one fetch — temperature and humidity come from the same reading.- The channels are typed to the part:
sht3x.get(CHAN.PRESS)is a build error naming the channels the SHT3XD actually serves. The wrong sensor call is caught before it ships, not when it reads garbage. - The hardware test in
test/sensor.test.tsruns on the board itself — a plausibility range check (−40 to 85 °C is the SHT3X's operating range) that catches a dead sensor or a miswired bus, which a unit test never could.
Flash and read
terminal
npx @typecad/hal create my-project --target xiao_ble/nrf52840
cd my-project
npx @typecad/hal build --compile --upload --port COM4Wire the SHT3X breakout to the board's I2C pins (SDA, SCL, 3V3, GND — the ADDR pin floating gives 0x44). Open a serial monitor at 115200 and the readings roll every two seconds:
serial monitor
21.64 C, 44.2 %RH
21.65 C, 44.3 %RHThen run the test — same board, same sensor, assertions on real hardware:
terminal
npx @typecad/hal test
Sensor
✓ reads a plausible temperature
✓ reads a plausible humidity
2 passingWhere to go next
- Sensors — the 200-part list, SPI attachments, and typed channels
- Communication buses — I2C and SPI device handles
- BLE temperature sensor — this sensor, advertised over BLE