simplify example code
This commit is contained in:
parent
cb341bf7d9
commit
f67f31223d
2 changed files with 20 additions and 51 deletions
38
README.md
38
README.md
|
@ -15,7 +15,7 @@ use linux_embedded_hal::{I2cdev, Delay};
|
||||||
use i2cdev::linux::LinuxI2CError;
|
use i2cdev::linux::LinuxI2CError;
|
||||||
|
|
||||||
fn main() -> Result<(), Error<LinuxI2CError>> {
|
fn main() -> Result<(), Error<LinuxI2CError>> {
|
||||||
let i2c = I2cdev::new("/dev/i2c-1") // or privide your owm on different platforms
|
let i2c = I2cdev::new("/dev/i2c-1")
|
||||||
.map_err(Error::I2c)?;
|
.map_err(Error::I2c)?;
|
||||||
|
|
||||||
let delay = Delay;
|
let delay = Delay;
|
||||||
|
@ -25,40 +25,26 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// get roll and pitch estimate
|
// get roll and pitch estimate
|
||||||
match mpu.get_acc_angles() {
|
let acc = mpu.get_acc_angles()?;
|
||||||
Ok(r) => {
|
println!("r/p: {:?}", acc);
|
||||||
println!("r/p: {:?}", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
|
|
||||||
// get temp
|
// get temp
|
||||||
match mpu.get_temp() {
|
let temp = mpu.get_temp()?;
|
||||||
Ok(r) => {
|
println!("temp: {}c", temp);
|
||||||
println!("temp: {}c", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
|
|
||||||
// get gyro data, scaled with sensitivity
|
// get gyro data, scaled with sensitivity
|
||||||
match mpu.get_gyro() {
|
let gyro = mpu.get_gyro()?;
|
||||||
Ok(r) => {
|
println!("gyro: {:?}", gyro);
|
||||||
println!("gyro: {:?}", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
|
|
||||||
// get accelerometer data, scaled with sensitivity
|
// get accelerometer data, scaled with sensitivity
|
||||||
match mpu.get_acc() {
|
let acc = mpu.get_acc()?;
|
||||||
Ok(r) => {
|
println!("acc: {:?}", acc);
|
||||||
println!("acc: {:?}", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Compile linux example (Rapsberry Pi 3B)
|
*Note*: this example uses API of version published on crates.io. If you're using code directly from master, the example may be broken
|
||||||
|
|
||||||
|
#### Compile linux example (Raspberry Pi 3B)
|
||||||
files [here](https://github.com/juliangaal/mpu6050/blob/master/example/)
|
files [here](https://github.com/juliangaal/mpu6050/blob/master/example/)
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
|
|
|
@ -10,39 +10,22 @@ fn main() -> Result<(), Error<LinuxI2CError>> {
|
||||||
|
|
||||||
let mut mpu = Mpu6050::new(i2c, delay);
|
let mut mpu = Mpu6050::new(i2c, delay);
|
||||||
mpu.init()?;
|
mpu.init()?;
|
||||||
//mpu.soft_calib(200)?;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// get roll and pitch estimate
|
// get roll and pitch estimate
|
||||||
match mpu.get_acc_angles() {
|
let acc = mpu.get_acc_angles()?;
|
||||||
Ok(r) => {
|
println!("r/p: {:?}", acc);
|
||||||
println!("r/p: {:?}", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
|
|
||||||
// get temp
|
// get temp
|
||||||
match mpu.get_temp() {
|
let temp = mpu.get_temp()?;
|
||||||
Ok(r) => {
|
println!("temp: {}c", temp);
|
||||||
println!("temp: {}c", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
|
|
||||||
// get gyro data, scaled with sensitivity
|
// get gyro data, scaled with sensitivity
|
||||||
match mpu.get_gyro() {
|
let gyro = mpu.get_gyro()?;
|
||||||
Ok(r) => {
|
println!("gyro: {:?}", gyro);
|
||||||
println!("gyro: {:?}", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
|
|
||||||
// get accelerometer data, scaled with sensitivity
|
// get accelerometer data, scaled with sensitivity
|
||||||
match mpu.get_acc() {
|
let acc = mpu.get_acc()?;
|
||||||
Ok(r) => {
|
println!("acc: {:?}", acc);
|
||||||
println!("acc: {:?}", r);
|
|
||||||
},
|
|
||||||
Err(_) => {} ,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue