Skip to content

Commit fde9f72

Browse files
BartMasseyeldruin
authored andcommitted
shortened i2c "magnetometer" and "accelerometer" commands
1 parent d0ed3b3 commit fde9f72

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

mdbook/src/11-i2c/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ fn main() -> ! {
7474
}
7575
}
7676

77-
if str::from_utf8(&buffer).unwrap().trim() == "accelerometer" {
77+
if str::from_utf8(&buffer).unwrap().trim() == "acc" {
7878
while !sensor.accel_status().unwrap().xyz_new_data() {
7979
timer0.delay_ms(1u32);
8080
}
8181

8282
let (x, y, z) = sensor.acceleration().unwrap().xyz_mg();
8383
write!(serial, "Accelerometer: x {} y {} z {}\r\n", x, y, z).unwrap();
84-
} else if str::from_utf8(&buffer).unwrap().trim() == "magnetometer" {
84+
} else if str::from_utf8(&buffer).unwrap().trim() == "mag" {
8585
while !sensor.mag_status().unwrap().xyz_new_data() {
8686
timer0.delay_ms(1u32);
8787
}

mdbook/src/11-i2c/the-challenge.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# The challenge
22

3-
The challenge for this chapter is, to build a small application that
4-
communicates with the outside world via the serial interface introduced
5-
in the last chapter. It should be able to receive the commands "magnetometer"
6-
as well as "accelerometer" and then print the corresponding sensor data
7-
in response. This time no template code will be provided since all you need
8-
is already provided in the [UART](../10-uart/index.md) and this chapter. However, here are a few clues:
3+
The challenge for this chapter is, to build a small application that communicates with the outside
4+
world via the serial interface introduced in the last chapter. It should be able to receive the
5+
commands "mag" for magnetometer as well as "acc" for accelerometer. It should then print the
6+
corresponding sensor data to the serial port in response. This time no template code will be
7+
provided since all you need is already provided in the [UART](../10-uart/index.md) and this
8+
chapter. However, here are a few clues:
99

10-
- You might be interested in `core::str::from_utf8` to convert the bytes in the buffer to a `&str`, since we need to compare with `"magnetometer"` and `"accelerometer"`.
10+
- You might be interested in `core::str::from_utf8` to convert the bytes in the buffer to a `&str`, since we need to compare with `"mag"` and `"acc"`.
1111
- You will have to read the documentation for the magnetometer API and functionality. While the `lsm303agr` crate provides the API interface, the [LSM303AGR datasheet](https://www.st.com/resource/en/datasheet/lsm303agr.pdf) details the sensor's magnetic field measurement parameters. See pages 13-15 for sensor characteristics and, importantly, pages 66-67 for the output register format.

0 commit comments

Comments
 (0)