Rust drivers for the Google Coral Environmental Sensor Board. Developed on a Raspberry Pi. Provides C bindings.
The crate bundles together drivers that allow readings from:
- Humidity + Temperature: Texas Instruments HDC2010 with help from
hdc20xx
crate. - Ambient Light: Texas Instruments OPT3002 with help from
opt300x
crate. - Barometric Pressure: Bosch BMP280 with help from
bmp280
crate.
You will need to explicitly list the following under [dependencies]
in your Cargo.toml
:
coralenv = { git = "https://github.com/bernardoaraujor/coralenv", branch = "main"}
Then, simply declare extern crate coralenv;
, and call one of the four functions:
coralenv::temperature()
coralenv::humidity()
coralenv::light()
coralenv::pressure()
All functions will return a f32
with the respective reading.
For example:
extern crate coralenv;
fn main() {
println!("Temperature: {} °C", coralenv::temperature());
println!("Humidity: {} %", coralenv::humidity());
println!("Ambient Light: {} lux", coralenv::light());
println!("Pressure: {} kPa", coralenv::pressure());
}
which generates:
Temperature: 41.38214 °C
Humidity: 23.078918 %
Ambient Light: 70.72 lux
Pressure: 100.26103 kPa
Makefile
and main.c
show how to link against target/debug/libcoralenv.a
.
$ make
$ ./main
Temperature: 37.575378 °C
Humidity: 26.179504 %
Ambient Light: 70.800003 lux
Pressure: 100.337738 kPa
It might be the case that you run into the following error message:
thread '<unnamed>' panicked at 'Failed to build device: I2cError(Nix(Sys(EBUSY)))', lib.rs:47:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 2788546640
Aborted
That is because the bmp280_i2c
module has been loaded automatically into the kernel during boot.
Run the following command in order to unload the kernel module:
$ sudo rmmod bmp280_i2c
and then your code should work just fine.
Warning
I'm a total Rust n00b. This crate is just a small experiment, and things are silly and ugly. Real credit goes to natemara and eldruin for their work in the original drivers.