src/exercises/bare-metal/compass.md
We will read the direction from an I2C compass, and log the readings to a serial port. If you have time, try displaying it on the LEDs somehow too, or use the buttons somehow.
Hints:
lsm303agr and
microbit-v2 crates, as well
as the micro:bit hardware.embedded_hal::i2c::I2c
trait. The
microbit::hal::Twim
struct implements this.microbit::Board
struct with fields for the various pins and peripherals.Download the exercise template and
look in the compass directory for the following files.
src/main.rs:
<!-- File src/main.rs --> <!-- mdbook-xgettext: skip --># // Copyright 2023 Google LLC
# // SPDX-License-Identifier: Apache-2.0
#
{{#include compass/src/main.rs:top}}
use microbit::{hal::{Delay, 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):
<!-- File Cargo.toml --> <!-- mdbook-xgettext: skip -->{{#include compass/Cargo.toml}}
Embed.toml (you shouldn't need to change this):
<!-- File Embed.toml --> <!-- mdbook-xgettext: skip -->{{#include compass/Embed.toml}}
.cargo/config.toml (you shouldn't need to change this):
<!-- File .cargo/config.toml --> <!-- mdbook-xgettext: skip -->{{#include compass/.cargo/config.toml}}
See the serial output on Linux with:
<!-- mdbook-xgettext: skip -->picocom --baud 115200 --imap lfcrlf /dev/ttyACM0
Or on Mac OS something like (the device name may be slightly different):
<!-- mdbook-xgettext: skip -->picocom --baud 115200 --imap lfcrlf /dev/tty.usbmodem14502
Use Ctrl+A Ctrl+Q to quit picocom.