1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-29 17:10:46 +02:00

1.4 KiB

Compass

We will read the temperature from an I2C compass, and log the readings to a serial port.

Hint: check the documentation for the lsm303agr and microbit-v2 crates, as well as the micro:bit hardware. The LSM303AGR Inertial Measurement Unit is connected to the internal I2C bus. TWI is another name for I2C, so the I2C master peripheral is called TWIM. You can also look at the nRF52833 datasheet if you want, but it shouldn't be necessary for this exercise.

If you have time, try displaying it on the LEDs somehow too, or use the buttons somehow.

src/main.rs:

{{#include compass/src/main.rs:top}}
use microbit::{hal::uarte::{Baudrate, Parity, Uarte}, Board};

{{#include compass/src/main.rs:main}}
    // TODO

{{#include compass/src/main.rs:loop}}
        // TODO
    }
}

Cargo.toml (you shouldn't need to change this):

{{#include compass/Cargo.toml}}

Embed.toml (you shouldn't need to change this):

{{#include compass/Embed.toml}}

.cargo/config.toml (you shouldn't need to change this):

{{#include compass/.cargo/config.toml}}

See the serial output with

picocom --baud 115200 --imap lfcrlf /dev/ttyACM0

Use Ctrl+A Ctrl+Q to quit picocom.