{"id":1799,"date":"2023-06-04T06:55:10","date_gmt":"2023-06-04T06:55:10","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1799"},"modified":"2023-06-04T06:55:13","modified_gmt":"2023-06-04T06:55:13","slug":"working-with-stm32-and-sensors-mpu6050","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1799","title":{"rendered":"Working with STM32 and sensors: MPU6050"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"357\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/rp-mpu-6050.png\" alt=\"\" class=\"wp-image-1800\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/rp-mpu-6050.png 500w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/rp-mpu-6050-300x214.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/rp-mpu-6050-400x286.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/rp-mpu-6050-250x179.png 250w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall see how to interface MPU6050 with STM32F4xx. <\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is MPU6050.<\/li><li>Connection.<\/li><li>Developing the driver.<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is MPU6050:<\/h2>\n\n\n\n<p>The MPU-6050&#x2122; parts are the world\u2019s first MotionTracking devices designed for the low power, low cost, and high-performance requirements of smartphones, tablets and wearable sensors.<\/p>\n\n\n\n<p>The MPU-6050 incorporates InvenSense\u2019s MotionFusion&#x2122; and run-time calibration firmware that enables manufacturers to eliminate the costly and complex selection, qualification, and system level integration of discrete devices in motion-enabled products, guaranteeing that sensor fusion algorithms and calibration procedures deliver optimal performance for consumers.<\/p>\n\n\n\n<p>The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die, together with an onboard Digital Motion Processor&#x2122; (DMP&#x2122;), which processes complex 6-axis MotionFusion algorithms. The device can access external magnetometers or other sensors through an auxiliary master I\u00b2C bus, allowing the devices to gather a full set of sensor data without intervention from the system processor. The devices are offered in a 4 mm x 4 mm x 0.9 mm QFN package.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/invensense.tdk.com\/wp-content\/uploads\/2014\/12\/mpu-6000-family-diagram.png\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>The InvenSense MotionApps&#x2122; Platform that comes with the MPU-6050 abstracts motion-based complexities, offloads sensor management from the operating system, and provides a structured set of APIs for application development.<\/p>\n\n\n\n<p>For precision tracking of both fast and slow motions, the parts feature a user-programmable gyro full-scale range of \u00b1250, \u00b1500, \u00b11000, and \u00b12000 \u00b0\/sec (dps), and a user-programmable accelerometer full-scale range of \u00b12g, \u00b14g, \u00b18g, and \u00b116g. Additional features include an embedded temperature sensor and an on-chip oscillator with \u00b11% variation over the operating temperature range.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Applications<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>BlurFree&#x2122; technology (for Video\/Still Image Stabilization)<\/li><li>AirSign&#x2122; technology (for Security\/Authentication)<\/li><li>TouchAnywhere&#x2122; technology (for \u201cno touch\u201d UI Application Control\/Navigation)<\/li><li>MotionCommand&#x2122; technology (for Gesture Short-cuts)<\/li><li>Motion-enabled game and application framework<\/li><li>InstantGesture&#x2122; iG&#x2122; gesture recognition<\/li><li>Location based services, points of interest, and dead reckoning<\/li><li>Handset and portable gaming<\/li><li>Motion-based game controllers<\/li><li>3D remote controls for Internet connected DTVs and set top boxes, 3D mice<\/li><li>Wearable sensors for health, fitness and sports<\/li><li>Toys<\/li><\/ul>\n\n\n\n<p><strong>Features<\/strong>:<\/p>\n\n\n\n<p>Gyroscope Features:<\/p>\n\n\n\n<p> The triple-axis MEMS gyroscope in the MPU-60X0 includes a wide range of features:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable full-scale range of \u00b1250, \u00b1500, \u00b11000, and \u00b12000\u00b0\/sec<\/li><li>External sync signal connected to the FSYNC pin supports image, video and GPS synchronization<\/li><li>Integrated 16-bit ADCs enable simultaneous sampling of gyros<\/li><li>Enhanced bias and sensitivity temperature stability reduces the need for user calibration<\/li><li>Improved low-frequency noise performance<\/li><li>Digitally-programmable low-pass filter<\/li><li>Gyroscope operating current: 3.6mA<\/li><li>Standby current: 5\u00b5A<\/li><li>Factory calibrated sensitivity scale factor<\/li><li>User self-test<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>Accelerometer Features:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The triple-axis MEMS accelerometer in MPU-60X0 includes a wide range of features:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Digital-output triple-axis accelerometer with a programmable full scale range of \u00b12g, \u00b14g, \u00b18g and \u00b116g<\/li><li>Integrated 16-bit ADCs enable simultaneous sampling of accelerometers while requiring no external multiplexer<\/li><li>Accelerometer normal operating current: 500\u00b5A<\/li><li>Low power accelerometer mode current: 10\u00b5A at 1.25Hz, 20\u00b5A at 5Hz, 60\u00b5A at 20Hz, 110\u00b5A at 40Hz<\/li><li>Orientation detection and signaling<\/li><li>Tap detection<\/li><li>User-programmable interrupts<\/li><li>High-G interrupt<\/li><li>User self-test<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Connection:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"887\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-887x1024.png\" alt=\"\" class=\"wp-image-1801\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-887x1024.png 887w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-260x300.png 260w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-768x886.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-1331x1536.png 1331w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-1150x1327.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-750x865.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-400x462.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM-250x288.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.10.08-AM.png 1560w\" sizes=\"(max-width: 887px) 100vw, 887px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><td>MPU6050<\/td><td>STM32F411<\/td><\/tr><tr><td>Vcc<\/td><td>5V<\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><tr><td>SDA<\/td><td>PB9<\/td><\/tr><tr><td>SCL<\/td><td>PB8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. Developing the driver:<\/h2>\n\n\n\n<p>Before we starting developing the driver, we need the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Writing single byte using i2c bus (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=524\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=524\" target=\"_blank\">here<\/a>).<\/li><li>Multibyte read using i2c bus (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=549\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=549\" target=\"_blank\">here<\/a>).<\/li><li>Time base (<a href=\"https:\/\/blog.embeddedexpert.io\/?p=1644\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1644\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>).<\/li><\/ul>\n\n\n\n<p>Also, we need uart to transmit data over uart (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=329\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=329\" target=\"_blank\">uart<\/a> , r<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=800\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=800\" target=\"_blank\">etargeting printf <\/a>).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>We start of by creating new source and header file with name of mpu6050.c and mpu6050.h respectively.<\/p>\n\n\n\n<p>Within the header:<\/p>\n\n\n\n<p>Include the following header files<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/Header Files\n#include &quot;i2c.h&quot;\n#include &lt;string.h&gt;\n#include &lt;stdbool.h&gt;\t\/\/Boolean\n#include &lt;math.h&gt;\t\t\t\/\/Pow()<\/pre><\/div>\n\n\n\n<p>Define the registers:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/Define Registers\n#define MPU_ADDR          0x68\n\n#define WHO_AM_I_REG\t\t\t0x75\n#define PWR_MAGT_1_REG\t\t0x6B\n#define CONFIG_REG\t\t\t\t0x1A\n#define GYRO_CONFIG_REG\t\t0x1B\n#define ACCEL_CONFIG_REG\t0x1C\n#define SMPLRT_DIV_REG\t\t0x19\n#define INT_STATUS_REG\t\t0x3A\n#define ACCEL_XOUT_H_REG\t0x3B\n#define TEMP_OUT_H_REG\t\t0x41\n#define GYRO_XOUT_H_REG\t\t0x43\n#define FIFO_EN_REG \t\t\t0x23\n#define INT_ENABLE_REG \t\t0x38\n#define I2CMACO_REG \t\t\t0x23\n#define USER_CNT_REG\t\t\t0x6A\n#define FIFO_COUNTH_REG \t0x72\n#define FIFO_R_W_REG \t\t\t0x74<\/pre><\/div>\n\n\n\n<p>Define the struct for MPU configuration:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/1- MPU Configuration \ntypedef struct\n{\n\tuint8_t ClockSource;\n\tuint8_t Gyro_Full_Scale;\n\tuint8_t Accel_Full_Scale;\n\tuint8_t CONFIG_DLPF;\n\tbool \t\tSleep_Mode_Bit; \n\t\n}MPU_ConfigTypeDef;<\/pre><\/div>\n\n\n\n<p>Enum for clock source:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/2- Clock Source ENUM\nenum PM_CLKSEL_ENUM\n{\n\tInternal_8MHz \t= 0x00,\n\tX_Axis_Ref\t\t\t= 0x01,\n\tY_Axis_Ref\t\t\t= 0x02,\n\tZ_Axis_Ref\t\t\t= 0x03,\n\tExt_32_768KHz\t\t= 0x04,\n\tExt_19_2MHz\t\t\t= 0x05,\n\tTIM_GENT_INREST\t= 0x07\n};<\/pre><\/div>\n\n\n\n<p>Gyro full scale:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/3- Gyro Full Scale Range ENUM (deg\/sec)\nenum gyro_FullScale_ENUM\n{\n\tFS_SEL_250 \t= 0x00,\n\tFS_SEL_500 \t= 0x01,\n\tFS_SEL_1000 = 0x02,\n\tFS_SEL_2000\t= 0x03\n};<\/pre><\/div>\n\n\n\n<p>Accelerometer scale:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/4- Accelerometer Full Scale Range ENUM (1g = 9.81m\/s2)\nenum accel_FullScale_ENUM\n{\n\tAFS_SEL_2g\t= 0x00,\n\tAFS_SEL_4g,\n\tAFS_SEL_8g,\n\tAFS_SEL_16g\n};<\/pre><\/div>\n\n\n\n<p>Digital low pass filter:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">enum DLPF_CFG_ENUM\n{\n\tDLPF_260A_256G_Hz = 0x00,\n\tDLPF_184A_188G_Hz = 0x01,\n\tDLPF_94A_98G_Hz \t= 0x02,\n\tDLPF_44A_42G_Hz \t= 0x03,\n\tDLPF_21A_20G_Hz \t= 0x04,\n\tDLPF_10_Hz \t\t\t\t= 0x05,\n\tDLPF_5_Hz \t\t\t\t= 0x06\n};<\/pre><\/div>\n\n\n\n<p>External frame sync:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/6- e external Frame Synchronization ENUM\nenum EXT_SYNC_SET_ENUM\n{\n\tinput_Disable = 0x00,\n\tTEMP_OUT_L\t\t= 0x01,\n\tGYRO_XOUT_L\t\t= 0x02,\n\tGYRO_YOUT_L\t\t= 0x03,\n\tGYRO_ZOUT_L\t\t= 0x04,\n\tACCEL_XOUT_L\t= 0x05,\n\tACCEL_YOUT_L\t= 0x06,\n\tACCEL_ZOUT_L\t= 0x07\n};<\/pre><\/div>\n\n\n\n<p>Raw data struct:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/7. Raw data typedef\ntypedef struct\n{\n\tint16_t x;\n\tint16_t y;\n\tint16_t z;\n}RawData_Def;\n<\/pre><\/div>\n\n\n\n<p>Scaled data struct:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/8. Scaled data typedef\ntypedef struct\n{\n\tfloat x;\n\tfloat y;\n\tfloat z;\n}ScaledData_Def;\n<\/pre><\/div>\n\n\n\n<p>Function prototypes:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/Function Prototype\n\n\/\/2- i2c Read\nvoid I2C_Read(uint8_t ADDR, uint8_t *i2cBuf, uint8_t NofData);\n\/\/3- i2c Write 8 Bit\nvoid I2C_Write8(uint8_t ADDR, uint8_t data);\n\/\/4- MPU6050 Initialaztion Configuration \nvoid MPU6050_Config(MPU_ConfigTypeDef *config);\n\/\/5- Get Sample Rate Divider\nuint8_t MPU6050_Get_SMPRT_DIV(void);\n\/\/6- Set Sample Rate Divider\nvoid MPU6050_Set_SMPRT_DIV(uint8_t SMPRTvalue);\n\/\/7- External Frame Sync.\nuint8_t MPU6050_Get_FSYNC(void);\n\/\/8- Set External Frame Sync.\nvoid MPU6050_Set_FSYNC(enum EXT_SYNC_SET_ENUM ext_Sync);\n\/\/9- Get Accel Raw Data\nvoid MPU6050_Get_Accel_RawData(RawData_Def *rawDef);\/\/************\n\/\/10- Get Accel scaled data\nvoid MPU6050_Get_Accel_Scale(ScaledData_Def *scaledDef);\/\/***********\n\/\/11- Get Accel calibrated data\nvoid MPU6050_Get_Accel_Cali(ScaledData_Def *CaliDef);\n\/\/12- Get Gyro Raw Data\nvoid MPU6050_Get_Gyro_RawData(RawData_Def *rawDef);\n\/\/13- Get Gyro scaled data\nvoid MPU6050_Get_Gyro_Scale(ScaledData_Def *scaledDef);\n\/\/14- Accel Calibration\nvoid _Accel_Cali(float x_min, float x_max, float y_min, float y_max, float z_min, float z_max);\n<\/pre><\/div>\n\n\n\n<p>Hence, the entire header file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/Header Files\n#include &quot;i2c.h&quot;\n#include &lt;string.h&gt;\n#include &lt;stdbool.h&gt;\t\/\/Boolean\n#include &lt;math.h&gt;\t\t\t\/\/Pow()\n\n\/\/Define Registers\n#define MPU_ADDR          0x68\n\n#define WHO_AM_I_REG\t\t\t0x75\n#define PWR_MAGT_1_REG\t\t0x6B\n#define CONFIG_REG\t\t\t\t0x1A\n#define GYRO_CONFIG_REG\t\t0x1B\n#define ACCEL_CONFIG_REG\t0x1C\n#define SMPLRT_DIV_REG\t\t0x19\n#define INT_STATUS_REG\t\t0x3A\n#define ACCEL_XOUT_H_REG\t0x3B\n#define TEMP_OUT_H_REG\t\t0x41\n#define GYRO_XOUT_H_REG\t\t0x43\n#define FIFO_EN_REG \t\t\t0x23\n#define INT_ENABLE_REG \t\t0x38\n#define I2CMACO_REG \t\t\t0x23\n#define USER_CNT_REG\t\t\t0x6A\n#define FIFO_COUNTH_REG \t0x72\n#define FIFO_R_W_REG \t\t\t0x74\n\n\/\/TypeDefs and Enums\n\/\/1- MPU Configuration \ntypedef struct\n{\n\tuint8_t ClockSource;\n\tuint8_t Gyro_Full_Scale;\n\tuint8_t Accel_Full_Scale;\n\tuint8_t CONFIG_DLPF;\n\tbool \t\tSleep_Mode_Bit; \n\t\n}MPU_ConfigTypeDef;\n\n\/\/2- Clock Source ENUM\nenum PM_CLKSEL_ENUM\n{\n\tInternal_8MHz \t= 0x00,\n\tX_Axis_Ref\t\t\t= 0x01,\n\tY_Axis_Ref\t\t\t= 0x02,\n\tZ_Axis_Ref\t\t\t= 0x03,\n\tExt_32_768KHz\t\t= 0x04,\n\tExt_19_2MHz\t\t\t= 0x05,\n\tTIM_GENT_INREST\t= 0x07\n};\n\n\/\/3- Gyro Full Scale Range ENUM (deg\/sec)\nenum gyro_FullScale_ENUM\n{\n\tFS_SEL_250 \t= 0x00,\n\tFS_SEL_500 \t= 0x01,\n\tFS_SEL_1000 = 0x02,\n\tFS_SEL_2000\t= 0x03\n};\n\n\n\/\/4- Accelerometer Full Scale Range ENUM (1g = 9.81m\/s2)\nenum accel_FullScale_ENUM\n{\n\tAFS_SEL_2g\t= 0x00,\n\tAFS_SEL_4g,\n\tAFS_SEL_8g,\n\tAFS_SEL_16g\n};\n\n\/\/5- Digital Low Pass Filter ENUM\nenum DLPF_CFG_ENUM\n{\n\tDLPF_260A_256G_Hz = 0x00,\n\tDLPF_184A_188G_Hz = 0x01,\n\tDLPF_94A_98G_Hz \t= 0x02,\n\tDLPF_44A_42G_Hz \t= 0x03,\n\tDLPF_21A_20G_Hz \t= 0x04,\n\tDLPF_10_Hz \t\t\t\t= 0x05,\n\tDLPF_5_Hz \t\t\t\t= 0x06\n};\n\/\/6- e external Frame Synchronization ENUM\nenum EXT_SYNC_SET_ENUM\n{\n\tinput_Disable = 0x00,\n\tTEMP_OUT_L\t\t= 0x01,\n\tGYRO_XOUT_L\t\t= 0x02,\n\tGYRO_YOUT_L\t\t= 0x03,\n\tGYRO_ZOUT_L\t\t= 0x04,\n\tACCEL_XOUT_L\t= 0x05,\n\tACCEL_YOUT_L\t= 0x06,\n\tACCEL_ZOUT_L\t= 0x07\n};\n\n\/\/7. Raw data typedef\ntypedef struct\n{\n\tint16_t x;\n\tint16_t y;\n\tint16_t z;\n}RawData_Def;\n\n\/\/8. Scaled data typedef\ntypedef struct\n{\n\tfloat x;\n\tfloat y;\n\tfloat z;\n}ScaledData_Def;\n\n\n\/\/Function Prototype\n\n\/\/2- i2c Read\nvoid I2C_Read(uint8_t ADDR, uint8_t *i2cBuf, uint8_t NofData);\n\/\/3- i2c Write 8 Bit\nvoid I2C_Write8(uint8_t ADDR, uint8_t data);\n\/\/4- MPU6050 Initialaztion Configuration \nvoid MPU6050_Config(MPU_ConfigTypeDef *config);\n\/\/5- Get Sample Rate Divider\nuint8_t MPU6050_Get_SMPRT_DIV(void);\n\/\/6- Set Sample Rate Divider\nvoid MPU6050_Set_SMPRT_DIV(uint8_t SMPRTvalue);\n\/\/7- External Frame Sync.\nuint8_t MPU6050_Get_FSYNC(void);\n\/\/8- Set External Frame Sync.\nvoid MPU6050_Set_FSYNC(enum EXT_SYNC_SET_ENUM ext_Sync);\n\/\/9- Get Accel Raw Data\nvoid MPU6050_Get_Accel_RawData(RawData_Def *rawDef);\/\/************\n\/\/10- Get Accel scaled data\nvoid MPU6050_Get_Accel_Scale(ScaledData_Def *scaledDef);\/\/***********\n\/\/11- Get Accel calibrated data\nvoid MPU6050_Get_Accel_Cali(ScaledData_Def *CaliDef);\n\/\/12- Get Gyro Raw Data\nvoid MPU6050_Get_Gyro_RawData(RawData_Def *rawDef);\n\/\/13- Get Gyro scaled data\nvoid MPU6050_Get_Gyro_Scale(ScaledData_Def *scaledDef);\n\/\/14- Accel Calibration\nvoid _Accel_Cali(float x_min, float x_max, float y_min, float y_max, float z_min, float z_max);\n<\/pre><\/div>\n\n\n\n<p>Thats all for header file.<\/p>\n\n\n\n<p>The source file:<\/p>\n\n\n\n<p>Include the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;MPU6050.h&quot;\n#include &quot;i2c.h&quot;\n#include &quot;time_base.h&quot;<\/pre><\/div>\n\n\n\n<p>Static variable for the library:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/2- Accel &amp; Gyro Scaling Factor\nstatic float accelScalingFactor, gyroScalingFactor;\n\/\/3- Bias variables\nstatic float A_X_Bias = 0.0f;\nstatic float A_Y_Bias = 0.0f;\nstatic float A_Z_Bias = 0.0f;\n\nstatic int16_t GyroRW[3];<\/pre><\/div>\n\n\n\n<p>MPU configuration:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void MPU6050_Config(MPU_ConfigTypeDef *config)\n{\n\tuint8_t Buffer = 0;\n\t\/\/Clock Source \n\t\/\/Reset Device\n\n\ti2c_writeByte(MPU_ADDR, PWR_MAGT_1_REG, 0x80);\n\n\tdelay(100);\n\n\tBuffer = config -&gt;ClockSource &amp; 0x07; \/\/change the 7th bits of register\n\n\tBuffer |= (config -&gt;Sleep_Mode_Bit &lt;&lt; 6) &amp;0x40; \/\/ change only the 7th bit in the register\n\t\n\ti2c_writeByte(MPU_ADDR,PWR_MAGT_1_REG, Buffer);\n\n\tdelay(100); \/\/ should wait 10ms after changeing the clock setting.\n\n\t\/\/Set the Digital Low Pass Filter\n\tBuffer = 0;\n\n\tBuffer = config-&gt;CONFIG_DLPF &amp; 0x07;\n\t\n\ti2c_writeByte(MPU_ADDR,CONFIG_REG, Buffer);\n\n\t\/\/Select the Gyroscope Full Scale Range\n\tBuffer = 0;\n\n\tBuffer = (config-&gt;Gyro_Full_Scale &lt;&lt; 3) &amp; 0x18;\n\t\n\ti2c_writeByte(MPU_ADDR,GYRO_CONFIG_REG, Buffer);\n\n\t\/\/Select the Accelerometer Full Scale Range \n\tBuffer = 0; \n\n\tBuffer = (config-&gt;Accel_Full_Scale &lt;&lt; 3) &amp; 0x18;\n\n\ti2c_writeByte(MPU_ADDR,ACCEL_CONFIG_REG, Buffer);\n\n\t\/\/Set SRD To Default\n\tMPU6050_Set_SMPRT_DIV(0x04);\n\t\n\t\n\t\/\/Accelerometer Scaling Factor, Set the Accelerometer and Gyroscope Scaling Factor\n\tswitch (config-&gt;Accel_Full_Scale)\n\t{\n\t\tcase AFS_SEL_2g:\n\t\t\taccelScalingFactor = (2000.0f\/32768.0f);\n\t\t\tbreak;\n\t\t\n\t\tcase AFS_SEL_4g:\n\t\t\taccelScalingFactor = (4000.0f\/32768.0f);\n\t\t\t\tbreak;\n\t\t\n\t\tcase AFS_SEL_8g:\n\t\t\taccelScalingFactor = (8000.0f\/32768.0f);\n\t\t\tbreak;\n\t\t\n\t\tcase AFS_SEL_16g:\n\t\t\taccelScalingFactor = (16000.0f\/32768.0f);\n\t\t\tbreak;\n\t\t\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\t\/\/Gyroscope Scaling Factor \n\tswitch (config-&gt;Gyro_Full_Scale)\n\t{\n\t\tcase FS_SEL_250:\n\t\t\tgyroScalingFactor = 250.0f\/32768.0f;\n\t\t\tbreak;\n\t\t\n\t\tcase FS_SEL_500:\n\t\t\t\tgyroScalingFactor = 500.0f\/32768.0f;\n\t\t\t\tbreak;\n\t\t\n\t\tcase FS_SEL_1000:\n\t\t\tgyroScalingFactor = 1000.0f\/32768.0f;\n\t\t\tbreak;\n\t\t\n\t\tcase FS_SEL_2000:\n\t\t\tgyroScalingFactor = 2000.0f\/32768.0f;\n\t\t\tbreak;\n\t\t\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\t\n}<\/pre><\/div>\n\n\n\n<p>Get the sample rate:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/5- Get Sample Rate Divider\nuint8_t MPU6050_Get_SMPRT_DIV(void)\n{\n\tuint8_t Buffer = 0;\n\t\n\ti2c_readByte(MPU_ADDR,SMPLRT_DIV_REG,&amp;Buffer);\n\n\treturn Buffer;\n}\n<\/pre><\/div>\n\n\n\n<p>Set the sample rate:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/6- Set Sample Rate Divider\nvoid MPU6050_Set_SMPRT_DIV(uint8_t SMPRTvalue)\n{\n\ti2c_writeByte(MPU_ADDR,SMPLRT_DIV_REG, SMPRTvalue);\n}\n<\/pre><\/div>\n\n\n\n<p>Get eh external FYSNC:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t MPU6050_Get_FSYNC(void)\n{\n\tuint8_t Buffer = 0;\n\t\n\ti2c_readByte(MPU_ADDR,CONFIG_REG, &amp;Buffer);\n\tBuffer &amp;= 0x38; \n\treturn (Buffer&gt;&gt;3);\n}<\/pre><\/div>\n\n\n\n<p>Set the FYSNC:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/8- Set External Frame Sync. \nvoid MPU6050_Set_FSYNC(enum EXT_SYNC_SET_ENUM ext_Sync)\n{\n\tuint8_t Buffer = 0;\n\ti2c_readByte(MPU_ADDR,CONFIG_REG, &amp;Buffer);\n\tBuffer &amp;= ~0x38;\n\t\n\tBuffer |= (ext_Sync &lt;&lt;3); \n\ti2c_writeByte(MPU_ADDR,CONFIG_REG, Buffer);\n\t\n}<\/pre><\/div>\n\n\n\n<p>Get the raw acceleration data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/9- Get Accel Raw Data\nvoid MPU6050_Get_Accel_RawData(RawData_Def *rawDef)\n{\n\tuint8_t state;\n\tuint8_t AcceArr[6], GyroArr[6];\n\t\n\ti2c_readByte(MPU_ADDR,INT_STATUS_REG, &amp;state);\n\n\n\tif((state&amp;&amp;0x01))\n\t{\n\t\ti2c_ReadMulti(MPU_ADDR,ACCEL_XOUT_H_REG, 6,AcceArr);\n\t\t\n\t\t\/\/Accel Raw Data\n\t\trawDef-&gt;x = ((AcceArr[0]&lt;&lt;8) + AcceArr[1]); \/\/ x-Axis\n\t\trawDef-&gt;y = ((AcceArr[2]&lt;&lt;8) + AcceArr[3]); \/\/ y-Axis\n\t\trawDef-&gt;z = ((AcceArr[4]&lt;&lt;8) + AcceArr[5]); \/\/ z-Axis\n\t\t\/\/Gyro Raw Data\n\t\ti2c_ReadMulti(MPU_ADDR,GYRO_XOUT_H_REG, 6,GyroArr);\n\t\tGyroRW[0] = ((GyroArr[0]&lt;&lt;8) + GyroArr[1]);\n\t\tGyroRW[1] = (GyroArr[2]&lt;&lt;8) + GyroArr[3];\n\t\tGyroRW[2] = ((GyroArr[4]&lt;&lt;8) + GyroArr[5]);\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p>Get the acceleration data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/10- Get Accel scaled data (g unit of gravity, 1g = 9.81m\/s2)\nvoid MPU6050_Get_Accel_Scale(ScaledData_Def *scaledDef)\n{\n\n\tRawData_Def AccelRData;\n\tMPU6050_Get_Accel_RawData(&amp;AccelRData);\n\t\n\t\/\/Accel Scale data \n\tscaledDef-&gt;x = ((AccelRData.x+0.0f)*accelScalingFactor)\/1000;\n\tscaledDef-&gt;y = ((AccelRData.y+0.0f)*accelScalingFactor)\/1000;\n\tscaledDef-&gt;z = ((AccelRData.z+0.0f)*accelScalingFactor)\/1000;\n}\n<\/pre><\/div>\n\n\n\n<p>Get the acceleration calibrated data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/11- Get Accel calibrated data\nvoid MPU6050_Get_Accel_Cali(ScaledData_Def *CaliDef)\n{\n\tScaledData_Def AccelScaled;\n\tMPU6050_Get_Accel_Scale(&amp;AccelScaled);\n\t\n\t\/\/Accel Scale data \n\tCaliDef-&gt;x = (AccelScaled.x) - A_X_Bias; \/\/ x-Axis\n\tCaliDef-&gt;y = (AccelScaled.y) - A_Y_Bias;\/\/ y-Axis\n\tCaliDef-&gt;z = (AccelScaled.z) - A_Z_Bias;\/\/ z-Axis\n}<\/pre><\/div>\n\n\n\n<p>Get the Gyro data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/12- Get Gyro Raw Data\nvoid MPU6050_Get_Gyro_RawData(RawData_Def *rawDef)\n{\n\t\n\t\/\/Accel Raw Data\n\trawDef-&gt;x = GyroRW[0];\n\trawDef-&gt;y = GyroRW[1];\n\trawDef-&gt;z = GyroRW[2];\n\t\n}\n\n\/\/13- Get Gyro scaled data\nvoid MPU6050_Get_Gyro_Scale(ScaledData_Def *scaledDef)\n{\n\tRawData_Def myGyroRaw;\n\tMPU6050_Get_Gyro_RawData(&amp;myGyroRaw);\n\t\n\t\/\/Gyro Scale data \n\tscaledDef-&gt;x = (myGyroRaw.x)*gyroScalingFactor; \/\/ x-Axis\n\tscaledDef-&gt;y = (myGyroRaw.y)*gyroScalingFactor; \/\/ y-Axis\n\tscaledDef-&gt;z = (myGyroRaw.z)*gyroScalingFactor; \/\/ z-Axis\n}\n<\/pre><\/div>\n\n\n\n<p>Calibrate the acceleration:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/\/14- Accel Calibration\nvoid _Accel_Cali(float x_min, float x_max, float y_min, float y_max, float z_min, float z_max)\n{\n\t\/\/1* X-Axis calibrate\n\tA_X_Bias\t\t= (x_max + x_min)\/2.0f;\n\t\n\t\/\/2* Y-Axis calibrate\n\tA_Y_Bias\t\t= (y_max + y_min)\/2.0f;\n\t\n\t\/\/3* Z-Axis calibrate\n\tA_Z_Bias\t\t= (z_max + z_min)\/2.0f;\n}<\/pre><\/div>\n\n\n\n<p>In main.c:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;i2c.h&quot;\n#include &quot;time_base.h&quot;\n#include &quot;uart.h&quot;\n#include &quot;stdio.h&quot;\n#include &quot;MPU6050.h&quot;\n\n#define rate 300\nuint32_t previous;\n\n\nint main(void)\n{\n\tTicks_Init(16000000);\n\n\tuart2_rxtx_init();\n\n\ti2c_init();\n\n\tMPU_ConfigTypeDef myConfig;\n\n\tmyConfig.Accel_Full_Scale = AFS_SEL_4g;\n\tmyConfig.ClockSource = Internal_8MHz;\n\tmyConfig.CONFIG_DLPF = DLPF_184A_188G_Hz;\n\tmyConfig.Sleep_Mode_Bit = 0;\n\tmyConfig.Gyro_Full_Scale = FS_SEL_500;\n\n\tMPU6050_Config(&amp;myConfig);\n\n\tScaledData_Def meAccel;\n\n\twhile(1)\n\t{\n\t\tMPU6050_Get_Accel_Scale(&amp;meAccel);\n\t\tif(get_Ticks()-previous &gt;rate)\n\t\t{\n\t\t    printf(&quot;Accel: X = %.2f Y = %.2f Z = %.2f\\r\\n&quot;, meAccel.x, meAccel.y, meAccel.z);\n\t\t    printf(&quot;==============================\\r\\n&quot;);\n\t\t\tprevious=get_Ticks();\n\t\t}\n\t}\n\n}\n<\/pre><\/div>\n\n\n\n<p>For the configuration:<\/p>\n\n\n\n<p>First, Set thee acceleration scale for 4G:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"917\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-1024x917.png\" alt=\"\" class=\"wp-image-1802\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-1024x917.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-300x269.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-768x687.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-1536x1375.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-1150x1029.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-750x671.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-400x358.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM-250x224.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.35.30-AM.png 2022w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">myConfig.Accel_Full_Scale = AFS_SEL_4g;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Set the clock to be internal 8MHz:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"917\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-1024x917.png\" alt=\"\" class=\"wp-image-1803\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-1024x917.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-300x269.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-768x687.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-1536x1375.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-1150x1029.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-750x671.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-400x358.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM-250x224.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.38.33-AM.png 2022w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">myConfig.ClockSource = Internal_8MHz;<\/pre><\/div>\n\n\n\n<p>Configure the filter:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"952\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-952x1024.png\" alt=\"\" class=\"wp-image-1804\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-952x1024.png 952w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-279x300.png 279w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-768x826.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-1427x1536.png 1427w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-1150x1238.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-750x807.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-400x430.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM-250x269.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.41.22-AM.png 1682w\" sizes=\"(max-width: 952px) 100vw, 952px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">myConfig.CONFIG_DLPF = DLPF_184A_188G_Hz;<\/pre><\/div>\n\n\n\n<p>Exit from sleep mode:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"224\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-1024x224.png\" alt=\"\" class=\"wp-image-1805\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-1024x224.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-300x66.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-768x168.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-1536x336.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-1150x252.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-750x164.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-400x88.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM-250x55.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.42.34-AM.png 1682w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">myConfig.Sleep_Mode_Bit = 0;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Set the gyro scale:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"885\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-1024x885.png\" alt=\"\" class=\"wp-image-1806\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-1024x885.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-300x259.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-768x664.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-1536x1328.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-1150x994.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-750x648.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-400x346.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM-250x216.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.43.55-AM.png 1682w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">myConfig.Gyro_Full_Scale = FS_SEL_500;<\/pre><\/div>\n\n\n\n<p>Pass the data structure to MPU configuration function as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">MPU6050_Config(&amp;myConfig);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>You may download the code from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/MPU6050.zip\">MPU6050<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/MPU6050.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Results:<\/h2>\n\n\n\n<p>Upload the code to your F411RE Nucleo and open serial monitor and set the buadrare to 115200:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"610\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-610x1024.png\" alt=\"\" class=\"wp-image-1808\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-610x1024.png 610w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-179x300.png 179w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-768x1289.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-750x1259.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-400x672.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM-250x420.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-04-at-9.54.43-AM.png 866w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall see how to interface MPU6050 with STM32F4xx. In this guide, we shall cover the following: What is MPU6050. Connection. Developing the driver. Code. Results. 1. What is MPU6050: The MPU-6050&#x2122; parts are the world\u2019s first MotionTracking devices designed for the low power, low cost, and high-performance requirements of smartphones, tablets [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2,11,12],"tags":[],"class_list":["post-1799","post","type-post","status-publish","format-standard","hentry","category-data-structures","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1799"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1799"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1799\/revisions"}],"predecessor-version":[{"id":1809,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1799\/revisions\/1809"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}