Skip to content

Rust drivers for Coral Environmental Sensor Board (HDC2010, OPT3002 and BMP280).

License

Notifications You must be signed in to change notification settings

bernardoaraujor/coralenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rusty Coral Envinronmental Sensors

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:

Usage

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

C bindings

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

bmp280 kernel module

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.