Code Monkey home page Code Monkey logo

mpu6050's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar juliangaal avatar nilclass avatar tfx2001 avatar timkoning17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mpu6050's Issues

example for `no_std` microcontrollers

i've just published a small example on the STM32F401RE board (i wrote this a while ago to initially test out the driver & hardware).

would you be interested in having this in your examples folder instead so that you have an example for a no_std environment?
the added value over your example is admittedly not that much - it's just a faster copy & paste approach for cortex-m based projects.

Use device without delay

Hi,

this crate has great features and runs nicely on my embedded controller (stm32f103).

However, I cannot use it, because it borrows a delay object. However, on my embedded controller I only have one delay object and using it with the mpu6050 struct prevents me from using simple delay_ms, even though I only want to use e.g. get_acc_avg.

It would be great if the functions that don't require a timer can be executed without a delay object.

(But maybe it's only me not knowing the trick to share a delay...)

Greetings!

Timeout on init()

I think something here goes into timeout, just right after setting the slave device address

Hints?

/// Init wakes MPU6050 and verifies register addr, e.g. in i2c
    pub fn init<D: DelayMs<u8>>(&mut self, delay: &mut D) -> Result<(), Mpu6050Error<E>> {
        self.wake(delay)?;
        self.verify()?;
        self.set_accel_range(AccelRange::G2)?;
        self.set_gyro_range(GyroRange::D250)?;
        self.set_accel_hpf(ACCEL_HPF::_RESET)?;
        Ok(())
    }

error[E0277]: `mpu6050::RPReading` doesn't implement `std::fmt::Display`

Trying to build an example (https://github.com/juliangaal/mpu6050/blob/dev/examples/linux.rs) for aarch64-unknown-linux-gnu
Cargo.toml

[dependencies]
mpu6050 = "*"
i2cdev = "*"
linux-embedded-hal = "*"
embedded-hal = "*"

.cargo/config

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

rustup show

Default host: x86_64-unknown-linux-gnu

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

aarch64-unknown-linux-gnu
arm-unknown-linux-gnueabihf
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.37.0-nightly (03ee55bb1 2019-06-01)

cargo build --release --target aarch64-unknown-linux-gnu

 error[E0277]: `mpu6050::RPReading` doesn't implement `std::fmt::Display`
  --> src/main.rs:22:29
   |
22 |         println!("r/p: {}", acc);
   |                             ^^^ `mpu6050::RPReading` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `mpu6050::RPReading`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`

error[E0277]: `mpu6050::RPReading` doesn't implement `std::fmt::Display`
  --> src/main.rs:26:33
   |
26 |         println!("r/p avg: {}", acc);
   |                                 ^^^ `mpu6050::RPReading` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `mpu6050::RPReading`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`

error[E0277]: `mpu6050::RotReading` doesn't implement `std::fmt::Display`
  --> src/main.rs:38:30
   |
38 |         println!("gyro: {}", gyro);
   |                              ^^^^ `mpu6050::RotReading` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `mpu6050::RotReading`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`

error[E0277]: `mpu6050::RotReading` doesn't implement `std::fmt::Display`
  --> src/main.rs:42:34
   |
42 |         println!("gyro avg: {}", gyro);
   |                                  ^^^^ `mpu6050::RotReading` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `mpu6050::RotReading`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`

error[E0277]: `mpu6050::RotReading` doesn't implement `std::fmt::Display`
  --> src/main.rs:46:29
   |
46 |         println!("acc: {}", acc);
   |                             ^^^ `mpu6050::RotReading` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `mpu6050::RotReading`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`

error[E0277]: `mpu6050::RotReading` doesn't implement `std::fmt::Display`
  --> src/main.rs:50:33
   |
50 |         println!("acc avg: {}", acc);
   |                                 ^^^ `mpu6050::RotReading` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `mpu6050::RotReading`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: required by `std::fmt::Display::fmt`

Feature request: offsets for raw readings

Since every Mpu6050 sensor is different, it is necessary to add offsets to the raw readings to calibrate the sensor.

It would be very handy if this crate has a feature for specifying these offsets, and maybe even an example to calculate these offsets, as seen in the IMU_Zero example in the arduino library by ElectronicCats.

If you need help translating the arduino code or creating the feature, let me know!

`init` method resets ranges

There are constructors that allow to set accelerometer and gyro ranges: new_with_sens and new_with_addr_and_sens. But an init method resets the ranges to AccelRange::G2 and GyroRange::D250: init

It looks strange for me as how I can understand init is required to be called. If it is true then the constructors do not make sense at all.

Issue using MPU6050 with ESP32 and esp-hal

First of all, I realise this may not be the best place to ask this question. I know this crate is for a general hal, not specifically for ESP32 and esp-hal, but maybe someone will have some intuition about this and help me find a solution. Or feel free to remove this issue.

Problem:

I'm trying to use an MPU6050 with an ESP32 using the esp-hal and this crate.

Hardware:

I'm using a breakout board like this one. Connections are very easy: power, GND, SDA and SCL connected directly to the ESP32.

I can confirm this hardware works perfectly when using the Arduino environment and the Adafruit MPU6050 library. The I2C address used is the default (0x68).

Rust software:

Using the aforementioned esp-hal crate, along with this one, I wrote this test code:

#![no_std]
#![no_main]

use core::fmt::Write;
use esp32_hal::{
    clock::ClockControl, i2c::I2C, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc, Serial, IO,
};
use esp_backtrace as _;
use mpu6050::Mpu6050;

#[xtensa_lx_rt::entry]
fn main() -> ! {
    let peripherals = Peripherals::take().unwrap();
    let mut system = peripherals.DPORT.split();
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    // Disable the RTC and TIMG watchdog timers
    let mut rtc = Rtc::new(peripherals.RTC_CNTL);
    let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
    let mut wdt0 = timer_group0.wdt;
    let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
    let mut wdt1 = timer_group1.wdt;

    rtc.rwdt.disable();
    wdt0.disable();
    wdt1.disable();

    let mut usb = Serial::new(peripherals.UART0);
    let mut delay = esp32_hal::Delay::new(&clocks);

    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

    let i2c = I2C::new(
        peripherals.I2C0,
        io.pins.gpio21,
        io.pins.gpio22,
        100u32.kHz(),
        &mut system.peripheral_clock_control,
        &clocks,
    )
    .unwrap();

    let mut mpu = Mpu6050::new(i2c);
    mpu.init(&mut delay).unwrap();
    writeln!(usb, "Got here!").unwrap();

    let mut count: u64 = 0;
    loop {
        writeln!(usb, "Serial output #{count}. This works!").unwrap();

        // get roll and pitch estimate
        let acc = mpu.get_acc_angles().unwrap();
        writeln!(usb, "r/p: {:?}", acc).unwrap();

        // get sensor temp
        let temp = mpu.get_temp().unwrap();
        writeln!(usb, "temp: {:?}c", temp).unwrap();

        // get gyro data, scaled with sensitivity
        let gyro = mpu.get_gyro().unwrap();
        writeln!(usb, "gyro: {:?}", gyro).unwrap();

        // get accelerometer data, scaled with sensitivity
        let acc = mpu.get_acc().unwrap();
        writeln!(usb, "acc: {:?}", acc).unwrap();

        delay.delay_ms(10u32);
        count += 1;
    }
}

This code is based on the cargo generate from here with the I2C additions from the example code in the esp-hal crate.

Error:

The code from above, on the exact same hardware that works on the Arduino environment, gives the following error:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0048,len:12
ho 0 tail 12 room 4
load:0x3fff0054,len:4800
load:0x40078000 [_stack_end_cpu0:??:??],len:17448
load:0x4007c428 [_stack_end_cpu0:??:??],len:4840
entry 0x4007c6a0 [_stack_end_cpu0:??:??]
 
 
!! A panic occured in 'src/main.rs', at line 44, column 26
 
PanicInfo {
    payload: Any { .. },
    message: Some(
        called `Result::unwrap()` on an `Err` value: I2c(AckCheckFailed),
    ),
    location: Location {
        file: "src/main.rs",
        line: 44,
        col: 26,
    },
    can_unwind: true,
}
 
Backtrace:
 
0x400f1d85 [core::result::unwrap_failed:[...]/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/result.rs:1814]
0x400d95e2 [core::result::Result<T,E>::unwrap:[...]/.rustup/toolchains/esp/lib/rustlib/src/rust/library/core/src/result.rs:1107]
0x400d9a2f [esp32_rust_test::__xtensa_lx_rt_main:[...]/src/main.rs:44]
0x400e1678 [Reset:[...]/.cargo/registry/src/github.com-1ecc6299db9ec823/xtensa-lx-rt-0.13.0/src/lib.rs:77]
0x400dde39 [ESP32Reset:[...]/.cargo/registry/src/github.com-1ecc6299db9ec823/esp32-hal-0.5.0/src/lib.rs:78]

Line 44 is mpu.init(&mut delay).unwrap();. I know that the very first command being sent to the MPU (self.write_byte(PWR_MGMT_1::ADDR, 0x01)?;) is not working (I tested that command specifically).

The weirdest part is that, over 100+ tries, it actually worked exactly once, randomly, with no code changes (or any other reason for it to start working, for that matter). The loop started running and outputting values. Although I didn't check the MEMS values, the temperature printed was around 25ÂēC, which is completely correct for where I am. After this one time it worked, it never worked again.

I feel like I must be missing something very obvious, but for the life of me I cannot figure it out, and ESP32 Rust examples are sparse on the internet. Any help is appreciated!

Raw gyro readings to rad/s conversion issue.

As seen in line 367 in lib.rs in function get_gyro():
gyro *= PI_180 * self.gyro_sensitivity;
the raw values are multiplied by the gyro sensitivity, while they should be divided by it, like in the corrected version:
gyro *= PI_180 / self.gyro_sensitivity;

I found this issue because I was reading -761 rad/s while the mpu6050 was laying still, which would be roughly 121 revolutions per second. That seemed a bit much for a measurement error to me.

TL;DR
Please change line 367 in lib.rs to
gyro *= PI_180 / self.gyro_sensitivity;.

Async API?

Hi, thanks for making this driver crate.

Are there plans for adding an async API to this crate? embedded-hal is working towards a 1.0 release which has async version of the traits used in this crate. Using these traits makes it much nicer to work with this crate when using the Embassy framework.

Would you be open to a PR that adds an async API? Now that embedded-hal has reached the release candidate phase it's less likely there will be breaking changes going forward so the maintenance burden shouldn't be too high.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.