Temperature and Humidity sensing
DeviceScript provides a driver for the SHTC3 temperature and humidity sensor.
The driver handles the low-level I2C communication protocol to the hardware and exposes a temperature and humidity service to DeviceScript. The services are the abstraction layer to interact with hardware.
import { startSHTC3 } from "@devicescript/drivers" // temperature and humidity are clients for the sensor servers const { temperature, humidity } = await startSHTC3()
A temperature service has a reading
register that can be read
to retreive the temperature in Celcius, regardless of the underlying hardware. Registers, like the servo angle, are also writeable.
In the example below, we read the temperature and print it to the console. The console output will automatically be displayed.
import { startSHTC3 } from "@devicescript/drivers" const { temperature, humidity } = await startSHTC3() // run every 5 seconds setInterval(async () => { // read data from temperature sensor const value = await temperature.reading.read() // print sensor value console.log({ value }) }, 5000)
Text editor powered by tinymce.