5 releases (breaking)

0.5.0 Jan 12, 2024
0.4.0 Jan 11, 2024
0.3.0 Jun 4, 2023
0.2.0 Aug 11, 2022
0.1.0 Aug 1, 2022

#374 in Embedded development

MIT/Apache

37KB
777 lines

Rust SCL3300 Driver

Crates.io Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
scl3300 = "0.5"

lib.rs:

This is a driver for SCL3300 inclinometers, implemented using platform-agnostic embedded-hal traits.

Usage

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
use scl3300::{Scl3300, Acceleration, ComponentId, Inclination, MeasurementMode, Temperature};

let inclinometer = Scl3300::new(spi);

// Start the inclinometer and switch to inclination mode.
let mut inclinometer = inclinometer.start_up(MeasurementMode::Inclination)?;

// Read the component ID.
let id: ComponentId = inclinometer.read()?;
assert_eq!(id, ComponentId::WHOAMI);

// Read acceleration, inclination and temperature.
let (acc, inc, temp): (Acceleration, Inclination, Temperature) = inclinometer.read()?;

println!("Acceleration: {}g, {}g, {}g", acc.x_g(), acc.y_g(), acc.z_g());
#
println!("Inclination: {}°, {}°, {}°", inc.x_degrees(), inc.y_degrees(), inc.z_degrees());
#
println!("Temperature: {}°C", temp.degrees_celsius());

// Switch to power-down mode.
let inclinometer = inclinometer.power_down()?;

// Release the SPI peripheral again.
let spi = inclinometer.release();
drop(spi);

Dependencies

~550KB
~11K SLoC