Library 43- MPU-6050 6-axes gyro and accelerometer for STM32F4

MPU-6050 6-axes gyroscope and accelerometer

MPU-6050 6-axes gyroscope and accelerometer

MPU-6050 is a 3-axes accelerometer and 3-axes gyroscope MEMS sensor in one piece. It can also measure temperature. It is very cheap device but also very powerful. It can measure simultaneously three (X, Y and Z) channels for accelerometer and gyroscope at the same time with 16-bit resolution. This chip is also compatible with MPU9150, except that MPU9150 has 3axes magnetometer (or compass) included.

MPU-6050 Features

  • Accelerometer
    • 4 selectable full scales (2G, 4G, 8G and 16G)
  • Gyroscope
    • 4 selectable full scales (250°, 500°, 1000° and 2000°)
  • Temperature sensor
    • 1°C accuracy
  • I2C driven
    • Selectable LSB bit for I2C address, used with AD0 pin
      • AD0 low: I2C address is 0xD0
      • AD0 high: I2C address is 0xD2
    • Max SCL speed is 400kHz

Library

Features

  • Read accelerometer data
  • Read gyroscope data
  • Read temperature
  • Read everything above in one single function or separatelly
  • Use 2 independent MPU-6050 devices on the same I2C bus
    • Devices must have different AD0 pin state

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx I2C
  • TM
    • TM I2C
    • defines.h
MPU-6050 STM32F4 Description
SCL PA8 I2C clock line
SDA PC9 I2C data line
AD0 LSB address pin. If pin is high, address is 0xD2, otherwise 0xD0
VCC 3.3V power supply
GND GND

By default, I2C3 is used for communication. If you want to change it, open defines.h file and edit lines:

Note: If you want to connect 2 MPU6050 devices, you have to connect them to the same I2C pins but with different AD0 pin on MPU6050 device.

Functions and enumerations

Example 1

  • One MPU-6050 device is connected to pins PA8 and PC9 on STM32F4
  • AD0 of MPU6050 is connected to GND, gives us address 0xD0
  • Read is performed every 500ms, displayed on USART1 (PB6, at 115200 baud) to the computer

Example 2

  • Two MPU-6050 devices are connected to STM32F4, both to pins PA8 and PC9
  • First device has AD0 pin connected to GND, gives us 0xD0 address
  • Second device has AD0 pin connected to 3.3V, gives is 0xD2 address
  • Both devices are send to USART

Both projects are available on Github, download library below.

Icon
TM STM32F4 MPU6050 Library

MPU-6050 6-axes gyroscope and accelerometer library for STM32F4

tilz0R

Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Benedikt

    Nice work! Thanks.

    One question: Is there an easy possibility to prepare the values and output on the PC. Like Processing for Arduino. https://www.youtube.com/watch?v=qmd6CVrlHOM

    • you just have to probably send data with USART and you can use processing to generate your style.

  • Janice

    Hello, I’ve tried using your mpu6050 library, but I can’t get the meaning of the data. I mean the data kept changing its value even if my mpu6050 was not moving. Do I have to calibrate the data?

    • It’s a big sensitivity and that’s the reason.

      • Janice

        Oh got it. Thank you. Finally got the data I need.
        And about combining both data form accelerometer and gyro, have you made the library? like using complementary filter to get pitch roll and yaw value?

        • No, there are only raw data, nothing combined.

        • Janice, can you try new library?
          I’ve made a change how data are returned to user. Now data are returned in “g” and “°/C” format.
          Can you please check if it works for you?

          Thanks.

          • Janice

            Oh ok, I’ll check it. Thanks a lot.
            Now actually I have problems combining their data, like using digital motion processor (I’ve search on the internet this is better than complementary filter), because I need yaw value. There are few people has made DMP library, but not for STM32. I’ve been trying to convert the library to fit in STM32, but still didn’t work. Would you try it too?

          • Contact me private with more informations please.

            And thanks for testibg.

  • ryan

    Have you ever ran into an issue with a hard fault when trying to sprintf() a float? I have been trying to use sprintf with a float and my STM32f407 keeps going to a hard fault. However, if I call sprintf(buffer, “%0.2f”, 0.25F); this will work just fine, but if I say: float x = 3.14; sprintf(buffer, “%0.2f, x); this will result in hard fault. Thanks for any help

    • I’ve never heard something like this.
      Can you please share your code?

      • ryan

        #include “main.h”
        #include
        #define USE_STDPERIPH_DRIVER

        /* Global Variables */
        char buffer[50];

        int main (void)
        {
        /* Local variables */
        float cc;

        /* Initialization */
        SystemInit();
        TM_DELAY_Init();
        tCoupleInit();
        Delayms(500);

        cc = 43.27;

        sprintf(buffer, “%2.1fn”, 0.25F);
        sprintf(buffer, “%2.1fn”, cc); // hard fault occurs when trying this

        while(1){}
        }

        Makefile compiler flags and linker flags:

        CFLAGS = -Wall -fno-common -c -g -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -g $(INCLUDES)

        LDFLAGS = -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -fno-common -nostartfiles -g -v

        I am using an Olimex board with an STM32F407 chip. Your website has been very helpful and in your examples you sprintf() floats a lot, not sure why I am having such issues. Build environement is Olimex ODS (Eclipse, yagarto, zylephin)

        • I have no idea which compiler Olimex is using.
          I would suggest you Coocox or Keil uVision for that.

          Arm GCC compiler has not sprintf functions fully working inside.

          • ryan

            So it’s using the arm-none-eabi. Last night I installed the arm-eabi gcc 4.9 but still no luck. Can I just get the compiler from Coocox of Keil and integrate into my current environment?

          • Keil uses ARM compiler, you cannot integrate it in your environment.

          • ryan

            Ok thank you. And thanks for the great website.

          • ryan

            For completeness, in case anyone ever comes across your site with the same issue, this is how I fixed it:

            I downloaded a new tool chain from:
            https://launchpad.net/gcc-arm-embedded/+download

            I removed all tool chains on path and added this new one to path via my environment variables. Additionally, added the following compiler flags:
            –specs=nano.specs -u _printf_float

            Now I can sprintf() a float.

  • Glen

    Hi Majerle, I’m now having issues with I2C, which I cannot get to detect device. I have tried with numerous devices, some of which I know work because I have talked to with different MCU. I’m back to basic MPU6050 example. TM_I2C_IsDeviceConnected() is failing. I have tried different I2C pins incase of damaged pins, no luck.
    Any suggestions as to how to diagnose issue?
    Setup:
    STM32F4(07VG)Discovery + MPU6050. I2C direct connection no pullups to 3.3V.

    • Just make sure connections are OK, add external pullups and try again.

      • Glen

        I have now put a logic analyzer on the SDA and SCL lines and am not seeing any pin change state. I have tried using multiple pinpacks on I2C1 and I2C3 with no signals coming out at all. Very strange, maybe something is wrong with my CMSIS libraries.

  • Roman Deneš

    Hi Majerle, I would like to ask you for a help. I am using G-80 board (this one http://www.forkrobotics.com/2013/06/using-the-gy80-10dof-module-with-arduino/ ), which include MPU-6050, but I can’t init it. The accelerometer should be in address 0x53. I tried to change address of device 0/1 but i I didn’t help. There is no AD0 input on the board that can be changed. Any idea? Thx.

    • MPU6050 has know address, it can’t be “whatever”.

      Also, make sure your address is left aligned 7bits.

      For example (address is from my head something):
      address is: 0010110 (7bit I2C address)
      right aligned: 00010110 = 0x16
      left aligned: 00101100 = 0x2C
      you need to set “left” aligned address, so in this case it would be 0x2C.

      You can use my I2C function to “search” for all connected devices to board.

      • Roman Deneš

        Can you sent me a link? Thx.

        • nothing special.

          Like this:
          uint8_t address;
          for(address = 0x02; address < 0xFF; address += 2) {
          if (TM_I2C_IsDeviceConnected(I2Cx, address)) {
          /* Device is connected, store address here */
          /* For know address, you can use USART here to sent to computer */
          }
          }

  • Ronak Patel

    Hi Majerle, your libraries and tutorials have been really helpful. For this library in particular, will example 1 work with the STM32F407VG? If so, is there any configurations I’d have to change? And using USART, If I have a RS232 connection on my computer do I just connect the PB6 pin to the RX pin of the RS232?

  • Onur Akgün

    Hi Majerle,

    That’s a great work. Thanks for sharing. I’m newbie in Keil. When I try to compile it, I get “can not open source input file ‘stm32f4xx_rcc.h’ ” error. Where can I find ‘stm32f4xx_rcc.h’ file?

    • This is standard peripheral library.
      If you open my f4 links, you will find link to library on ST site.

      • Onur Akgün

        Thanks Majerle,

        I get different error I don’t know. How can I solve this? Thank you

        • You need startup file. Download my keil priject template and use it.

          • Onur Akgün

            Majerle, thank you so much

            I have an another error which is “Error L6218E: Undefined symbol TM_Delay_Init(referred blinky.c)”
            As I learn, the reason of error is that declarations are okay but not definitions. I don’t know how to and where to define them

          • Download my delay lib. Looks like here is a problem.

          • Onur Akgün

            Majerle, thank you

            I handled it and also a few errors but I’m stuck again. Although I added both ‘tm_stm32f4_usart.c’ and ‘tm_stm32f4_usart.h’, I get this error. How can I solve it?

          • You are missing standard peripheral drivers from ST

          • Onur Akgün

            Majerle, thank you so much

            After two days which is full of struggle, I could compile it succesfully thanks to you

          • Onur Akgün

            Hi Majerle,

            While compiling, this time I get different error. Could you help me?

            I think it could be because of stm32f4xx_conf.h settings

            /*#include “stm32f4xx_adc.h”
            #include “stm32f4xx_crc.h”
            #include “stm32f4xx_dbgmcu.h”
            #include “stm32f4xx_dma.h”
            #include “stm32f4xx_exti.h”
            #include “stm32f4xx_flash.h”
            #include “stm32f4xx_iwdg.h”
            #include “stm32f4xx_pwr.h”
            #include “stm32f4xx_rtc.h”
            #include “stm32f4xx_sdio.h”
            #include “stm32f4xx_spi.h”
            #include “stm32f4xx_syscfg.h”
            #include “stm32f4xx_wwdg.h”*/

            #include “stm32f4xx_gpio.h”
            #include “stm32f4xx_i2c.h”
            #include “stm32f4xx_rcc.h”
            #include “stm32f4xx_tim.h”
            #include “stm32f4xx_usart.h”
            #include “misc.h”

          • Onur Akgün

            Majerle,

            I have an another problem which is uncertain for me about compiling. Could you help me?

          • stm32f4xx.h file is missing in your project.
            Would you download my keil template or what? I’m done with your problems with compilation. If you don’t know how this works, download template and use it!

          • Onur Akgün

            Sorry dude,

            I had lots of practice and finally I tried it in different template and it’s done. Thank you so much, I appreciate your helps

          • Imam Fatoni

            Hi Mr.Tilen , I’m trying to run MPU6050 on STM32F4 Discovery and have some troubles.
            During initialization I2C finds device connected to pins, but then when read a gyroscope this data error , i m using library with HAL driver. i want look mpu6050 read a gyroscope yaw pitch roll like this in arduino.
            Have you ever had that kind of
            problem with Discovery and MPU6050? I’ll be very glad for any help, I’ve
            lost a month trying to find solution. thanks

          • You obviously can’t ready those values. You must calculate them later from gyro and acce data.

            So, what is a problem actually? What data error is?

  • Onur Akgün

    Hi Majerle,

    I implemented example-1 and I get 15163 value for all axis even if I turn MPU6050 different sides. Do you think what is the reason?

    Thank you

  • Jacky

    Great share, thanks. InvenSense published code sample about DMP in MSP430. Is there any way to implement it into STM?

    • Currently no, but you can do low layer stuff by yourself. It’s not so hard, you can use libs from me 🙂

      • Jacky

        I see. I have been trying to convert it but I haven’t done it yet. As I see, you need to know both STM and MSP well to convert it succesfully and to be honest, my low stuff knowledge is not enough. Is there any method to suggest me?

        • Option is for you to start learning from my libs/tutorials.
          You have a lot of libs here where you can learn how to do your stuff 🙂

  • Jacky

    Majerle,

    Can we use this library with VCP library? When I use VCP lib alone, it works but If I use vcp with mpu, It doesn’t work, actually there is no stm com port

    • Hi,

      yes you should.
      Do you have pins mismatch with USB VCP VBUS or ID with your I2C settings?
      Which thing you initialize first?

  • Pingback: All STM32F4 libraries - STM32F4 Discovery()

  • Jean-François Garcia

    Thanks for your Good library.
    I just put some few modification on pin Initialization to work with my projects and it works great. Good Job
    One question : Which simplest library can I use to compute accelerometer and gyroscope values to get a filter angular values ?
    I have read that the Kalman filter can be used, but I don’t find yet a simpliest library ? Do you know where I can find one ?

    • Jean-François Garcia

      I have found this document :
      http://web.mit.edu/~jinstone/Public/filter.pdf
      Very intersting to understand how to compute angle from gyro and accelerator values.
      I’ll try to make some functions to implement it.
      news soon. But if you have already found a existing library, please share it !

  • Matthew

    Hi,

    I’m trying to run MPU6050 on STM32F4 Discovery and have some troubles. During initialization I2C finds device connected to pins, but then not recognizes it as MPU6050 (Who I Am) and it not returns good values after trying to read sensor. AD0 pin is GND and I’m using code from example, also tried with different pinspacks.
    Have you ever had that kind of problem with Discovery and MPU6050? I’ll be very glad for any help, I’ve lost a month trying to find solution.

    • It definetelly sounds like hardware (MPU) problem.
      Can you tell me which MPU exactly you have here?
      Maybe on a market are different versions/revisions of MPU6050 device.

      • Matthew

        I’m using GY-521 with MPU6050 and SparkFun board with MPU9150.

        • kaan

          Hi,
          I got the same error. There is no problem when finding device but TM_MPU6050_Result_DeviceInvalid is returned. The address value which i read 0xD1. Have you got any suggestion? What may cause the problem?

          PS: i am using GY-88 board. http://www.dx.com/p/gy-88-mpu-6050-hmc5883l-bmp085-10dof-flight-control-sensor-module-303056#.VYgI7vntmko

          • Look strange, because MPU has 2 different addresses, depends on A0 pin selection. These 2 can be 0xD0 or 0xD2. In case of 0xD1 or 0xD3 you are trying to write. Sounds strange but something is problem here with your hardware.

            MPU was tested by other users too and no problems when hardware was OK.
            Sorry, I don’t know how to help you here. You should check your hardware.

  • Eshan Shah

    Hi!

    I am trying to connect to my MPU6050 with this library. I always get the error that the device is not connected. I have connected the SCL/SDA pins to PA8/PC9 respectively. Here is my program. I dont understand why the device is not getting recognized! Please help!

    /* Include core modules */
    #include “stm32f4xx.h”
    /* Include my libraries here */
    #include “defines.h”
    #include “delay.h”
    #include “tm_stm32f4_mpu6050.h”

    #include
    int main(void) {
    TM_MPU6050_t MPU6050_Data;
    char str[120];

    /* Initialize system */
    SystemInit();

    /* Initialize MPU6050 sensor */
    if (TM_MPU6050_Init(&MPU6050_Data, TM_MPU6050_Device_0, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_2000s) != TM_MPU6050_Result_Ok) {
    /* Display error to user */
    printf(“MPU6050 Errorn”);

    /* Infinite loop */
    while (1);
    }

    while (1) {
    /* Read all data from sensor */
    TM_MPU6050_ReadAll(&MPU6050_Data);

    /* Format data */
    printf(“Accelerometern- X:%dn- Y:%dn- Z:%dnGyroscopen- X:%dn- Y:%dn- Z:%dnTemperaturen- %3.4fnnn”,
    MPU6050_Data.Accelerometer_X,
    MPU6050_Data.Accelerometer_Y,
    MPU6050_Data.Accelerometer_Z,
    MPU6050_Data.Gyroscope_X,
    MPU6050_Data.Gyroscope_Y,
    MPU6050_Data.Gyroscope_Z,
    MPU6050_Data.Temperature
    );

    /* Little delay */
    delay_nms(500);
    }
    }

    • Hello,

      well, library works, tested on several STM devices in several different places.

      So it must be your hardware problem.

      1. Make sure that SDA is really on SDA and SCL is on SCL
      2. Make sure A0 pin is really low on MPU6050 device. (You can also try to select TM_MPU6050_Device_1 when you init your device)

      PS: Use pastebin next time please.

  • Masato Kumai

    Hi!

    I am trying to connect to my MPU6050 with this library.
    I always get the error that unresolved inclusion and .
    Where can I get the stdio.h and stdlib.h files?
    Please help!!

    • These libs are standard C libraries so every C compiler should have them.

      • Masato Kumai

        Thank you for quickly replying!!
        I have downloaded the following programs.
        1. GCC compiler and debugger
        2. CoIDE
        3. ST-LINK Utility

        Some programs operate normally, such as LEDs program, but programs that need stdio.h or stdlib.h don’t operate…

        What should I do?…

        • Maybe link below can help you:

          http://www1.coocox.org/forum/topic.php?id=122

          • Masato Kumai

            Thank you for quickly replying!!
            I will try it. If there is that I don’t know what, I contact you again!

          • Masato Kumai

            Sorry…

            This is what I’ve done.

            1.Make new file called stdio.c and copy the code written in that URL.

            2.Edit #include of stdio.c

            #include
            #include #include
            #include -> #include
            #include #include
            #include
            #include

            I added this stdio.c file to MPU6050 library, and builded.
            Surprisingly, I have succeeded build but there are some warnings. So MPU6050 doesn’t operate normally…

            In FJ_Sanchez’s replying, where is the main.c?

  • Shagas Heizenberg

    I’m getting extremely slow response times. The first TM_MPU6050_ReadAll() function takes about 0.4ms which is

    fine, but every read after that takes about 200ms!! . Does anyone have an Idea on what is going on here?

    • Sounds strange.
      Can you set one pin high before you call read function, and set it back low when you are done with function. Then put it to logic analyzer and show for example 10 read cycles.

      • Shagas Heizenberg

        I tried what you said. Upon fresh power up of MPU6050 the 10 reads happen normally with 0.4ms interval but when I press reset on the discovery board after that to repeat the procedure I get various behaviors everytime. Sometimes only 3 reads and the next one is somewhere very far away , sometimes 7 reads (within that timeframe). Sorry I don’t have a logic analyzer, only an oscilloscope so I can’t provide detailed information.
        In any case… I tried using the individual TM_MPU6050_ReadAccelerometer , gyro and temp functions and they work no problem at 100Hz rate so I’m satisfied with it. Thanks for the library

  • Bob

    I was trying out this library but am having a compiling problem. It gests through a number of lines successfully before getting this error:

    TMtm_stm32f4_i2c.c(330): error: #20: identifier “GPIO_PIN_6” is undefined
    TM_GPIO_InitAlternate(PIOB, GPIO_PIN_6 | GPIO_PIN_7, TM_GPIO_OType_OD, TM_GPIO_PuPd_UP, TM_GPIO_Speed_Medium, GPIO_AF_I2C1);
    TMtm_stm32f4_i2c.c(330): error: #20: identifier “GPIO_PIN_7” is undefined

    basically it can’t find where the gpio’s are defined, but I am confused as everything seems correct to me (can’t find anything that is not included).

    I’m using the 01-STM32F4xx_Keil_CMSIS_Default_Project template. I have included the tm_stm32f4_i2c.c, tm_stm32f4_mpu6050.c, tm_stm32f4_usart.c and their corresponding h files into the tm folder in keil.

    I have also added the stm32f4_i2c.c to the std_peripheral_drivers folder, and attributes.h to the user folder, as far as I can tell all the necessary dependencies are there, any idea what could be going wrong?

    • Hi, GPIO lib fromcme is missing.

      • Bob

        I forgot to include tm_stm32f4_gpio.c in the text but it was there. I found the problem was that the stm32f4xx_gpio.h used the syntax GPIO_Pin whereas tm_stm32f4_i2c.c used GPIO_PIN, fixing this allowed it to compile.

        I do have another question, I was hoping to test an mpu9150 using this library (the arduino driver I used for an mpu9150 was identical to the one used for the mpu6050 so I assumed it should work in this case?). When I tested It successfully initialized the mpu but the printed values for the accelerometer etc didn’t change with movement (they stayed at -271) .

        Any Idea what could be the problem?

    • Adrian Alonzo

      Im stuck at this part as well. In the tm_stm32f4_i2c.c I added in the gpio header of the standard library #include “stm32f4xx_gpio.h” but still same errors.

      • This library has nothing to do here.
        Pins are declared in tm_stm32f4_gpio.h file.

        • Adrian Alonzo

          I read the article and found 3 downloads but none of them contain the tm_stm32f4_gpio.h. Is it located on another article?

  • Christoff

    Hi,
    I have been trying to use this library for a while now, it was working at first but the I2C seems to get stuck somewhere and everything stops working, on the oscilloscope I can see the I2C is initializing but as soon as initialization is complete both SDA and SCL stays high. Any ideas on how to solve this would be appreciated?

    • How exactly you know, that I2C has stuck? Maybe you are not using read method or similar. Did you checked if I2C has detected your device?

      • Christoff

        Sometimes it detects the device, as the TM_I2C_IsDeviceConnected function does not return that the device is not connected. When the program is paused in the debugger it is always at I2C_CheckEvent in the code and returns status = Error. On other occasions the TM_I2C_IsDeviceConnected returns that the device is not connected upon initialization. I have swapped out the Gy-521 breakout board to make sure that it`s not a hardware problem and I have also tried different I2C pins for SCL and SDA on STM32F4 device.

      • Christoff

        Sometimes it detects the device, as the TM_I2C_IsDeviceConnected function does not return that the device is not connected. When the program is paused in the debugger it is always at I2C_CheckEvent in the code and returns status = Error. On other occasions the TM_I2C_IsDeviceConnected returns that the device is not connected upon initialization. I have swapped out the Gy-521 breakout board to make sure that it`s not a hardware problem and I have also tried different I2C pins for SCL and SDA on STM32F4 device.

        • Are you sure you are using library correct? Sounds you are doing something what you shouldn’t also.

          • Christoff

            I uploaded a part of my code on Pastebin under Christoff_MPU6050, maybe you can see what I`m doing wrong?

  • Jorge Del Aguila

    Hello Tilen!

    I have been able to use the MPU 6050 with your I2C Library but I have problems when I try to use the motion interrupts.

    This is the code I’m trying to use for the interrupts: http://pastebin.com/z0Qvx9Dz

    Datasheet: http://www.seeedstudio.com/wiki/images/b/b1/MPU6050.pdf

    Register map: https://www.olimex.com/Products/Modules/Sensors/MOD-MPU6050/resources/RM-MPU-60xxA_rev_4.pdf

    Then I remembered that I used once this with arduino: http://diyhacking.com/arduino-mpu-6050-imu-sensor-tutorial/

    I have checked the awesome work these people did with the library. I wonder if you have done something similiar.

    Or it isn’t that complex? Am I missing something?

    • I will port this library to HAL implementation, and will add “data rate” and “interrupt” options too. So you will be able to select at which data rate IRQ pin should be set.

  • Pingback: HAL Library 30 - MPU6050 for STM32Fxxx - STM32F4 Discovery()

  • 黃經惟

    Hi, Majerle Tilen
    Thanks for your article made me successfully read the raw data of MPU6050.
    But I only have a little problem, I try to storage the data from MPU6050.
    I have tried USART, DMA USART, but the sampling rate still depend on the amount of characters,For example,I used two MPU6050,and the sampling rate is lower than one MPU6050. Therefore, I wanna try others way to storage just 1 second or less raw data and acquire them . This way seems can observe the real sampling rate of MPU6050.
    How can I do this ? Do I storage data in the STM32F4 or SD card ?

    • You can use both options. Sdcard or flash on stm.

  • Nilo Serafim Neto

    Hi Majerle, Thank you for your library! It worked just fine.
    The data reading is taking about 200 ms long to be done, giving me a 5Hz data rate. Do you have any idea of why it isaking so long?
    I’m using the STM32f407VG (Discovery board) and the libraries you provided.

    Thank you again.

    • Too much time. First ask is, your pll configuration is how?

      • Nilo Serafim Neto

        As I´m using the Discovery kit with a 8MHz external oscillator, I`ve changed to these configurations:

        HSE_VALUE 8000000
        PLL_M 8
        PLL_N 336
        PLL_P 2
        PLL_Q 7

        I´m not totally sure about those values, but I do know that my APB1 bus is porppelly working at 42MHz.

        • Correct values if like this. I would like to see your code where you read data.

  • brownoo

    i have problem the mpu gives me fix value

  • Anar Aliyev

    Hello, i want to use your libraries with stm32f130rb, will they work?(ofc i will configure the usart, i2c etc)

    • I will if you fix low-level drivers.

      • Anar Aliyev

        hello, i have a question. i have an arduino sketch. There are i init 2 mpu devices, summarize 200 values of gyro and acc in loop and divide this sums by 200(average).In arduino this code works fine, but in stm32 it works very slow, it stops for 1-2 minutes and only then working.

  • D.K.

    First of all just wanted to thank you – not sure how many hours you saved me but it’s a lot! Got everything working w/ the mpu6050. I tried your mpu9255 project w/ HAL but too large for Keil. Just wanted to see if there was another project already completed I might be missing? Thanks!