This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mpu6050 on Nrf51822

Hello

Is there any example or tutorial on how to use the mpu6050 library? I just started to program the nrf51822 and hope to find some helpful clues to get me going.

Any suggestion would be appreciated.

Nick

Update: I got the mpu-6050 working on keil, but without the mentioned examples. I did found some example on a chinese website. With some help of google translate i got to tweak it a little. For someone who is just a beginner most examples look difficult so i am already happy i got it working. And i can work forward from that base. For everyone who likes to use this very simple example. Here is my project; NRF51-MPU6050.rar

  • Hi,

    UPDATE 2016.03.30:

    I have uploaded some examples showing how you can use the MPU9150 and MPU9255 with the nRF51 here. The examples shows various features of the MPUs like free fall interrupts, data ready interrupts, and how to transmit MPU data over BLE.

    Further on, the MPU9150 and the MPU6050 are very similar and I'm quite sure that the example should work equally well, un-altered, on both sensors. However I have not tested it with the MPU6050. Feel free to try it out and give me some feedback if something is not working correctly.

    Note: The example is made for nRF51 3rd revision ICs and SDK 11.0.0 (Refer to the Compatibility Matrix. If you use older ICs it will not work. If you use a different SDK it might work, but I haven't tested it. If you use a different SDK and run into troubles please do your best to fix it yourself before you post any questions here.

    Finally, there are no good tutorials from Nordic for the MPUxxxx I'm afraid, but there are a bunch of more or less useful posts here on devzone.

  • Hi

    Brilliant it was a good morning waking up an seeing your answer. I will give it a try and report back here about the result ;)

    Nick

  • What SDK are you using? And what kind of warnings?

  • I am using the MPU6050 in a hobby project and successfully using the motion driver library. In both library files (inv_mpu.c and inv_mpu_dmp_motion_driver.c) I added the following block

    #elif defined NRF51
    #include "nrf_delay.h"
    #include "app_timer.h"
    #include "i2c.h"
    #define delay_ms    nrf_delay_ms
    static inline int get_ms(unsigned long *count) {
        static uint32_t cnt;
        app_timer_cnt_get(&cnt);
        cnt >>= 5;
        *count = cnt;
        return 0;
    }
    static inline int reg_int_cb(struct int_param_s *int_param) {
        (void) int_param;
        return 0;
    }
    #define log_i(...)     do {} while (0)
    #define log_e(...)     do {} while (0)
    //#define log_i(...)  SEGGER_RTT_WriteString(__VA_ARGS__)
    //#define log_e(...)  SEGGER_RTT_printf(0, __VA_ARGS__)
    //labs already defined in stdlib.h
    //fabsf already defined in math.h
    #define min(a,b) ((a<b)?a:b)
    

    just before

    #else
    #error  Gyro driver is missing the system layer implementations.
    #endif
    

    Due to limited board space, I'm not using the interrupt line, instead I am polling the fifo buffer of the MPU6050. Therefor the reg_int_cb function is empty.

    The i2c_read and i2c_write functions are in the following files:

    i2c.h

    i2c.c

    These functions are using the twi driver of SDK 9.0.0 and I added some error handling. In my case the data of the MPU6050 is used to drive two power LEDs in dependency of the inclination. But as soon as the SMPS Driver for either of one of the LEDs is running, the MPU6050 makes heavy use of clock stretching. This leads to acknowledge errors sometimes. The read and write functions will try again if that happens. Additionally to that these function also recovers the TWI interface if it gets stuck (I'm using HW Rev. 2 ICs)

    I hope these information helps you.

  • Thanks! Just wanted to let you know this was a huge help. I just changed the board defines as you indicated (using 9150) and the SCL and SDA pins to 7 and 30 respectively and it works great. I also tried to run on a mpu6050 (changed the board defines to MPU60x0 but no luck on that one but haven't looked into it yet.

Related