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

#245 in Embedded development

Download history 14/week @ 2024-01-11 7/week @ 2024-02-22 4/week @ 2024-02-29 101/week @ 2024-03-07 28/week @ 2024-03-14 4/week @ 2024-03-28

133 downloads per month

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

~585KB
~12K SLoC