{"id":16146101,"url":"https://github.com/libdriver/mpu9250","last_synced_at":"2025-04-04T22:08:47.974Z","repository":{"id":57646578,"uuid":"526863912","full_name":"libdriver/mpu9250","owner":"libdriver","description":"MPU9250 full function driver library for general MCU and Linux.","archived":false,"fork":false,"pushed_at":"2024-08-31T12:51:53.000Z","size":7881,"stargazers_count":364,"open_issues_count":1,"forks_count":169,"subscribers_count":51,"default_branch":"main","last_synced_at":"2024-10-11T00:18:58.814Z","etag":null,"topics":["accelerometer","c","dmp","full-function-driver","gyroscope","iic","imu","linux","magnetometer","mcu","mpu9250","spi"],"latest_commit_sha":null,"homepage":"https://www.libdriver.com","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libdriver.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-20T08:03:27.000Z","updated_at":"2024-09-27T16:36:04.000Z","dependencies_parsed_at":"2024-05-30T12:02:21.738Z","dependency_job_id":"0e6b9505-38e8-4080-9898-2302e53e4bbb","html_url":"https://github.com/libdriver/mpu9250","commit_stats":null,"previous_names":["libdriver/mpu9250","hepingood/mpu9250"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fmpu9250","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fmpu9250/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fmpu9250/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fmpu9250/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libdriver","download_url":"https://codeload.github.com/libdriver/mpu9250/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256115,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accelerometer","c","dmp","full-function-driver","gyroscope","iic","imu","linux","magnetometer","mcu","mpu9250","spi"],"created_at":"2024-10-10T00:18:49.543Z","updated_at":"2025-04-04T22:08:47.953Z","avatar_url":"https://github.com/libdriver.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English](/README.md) | [ 简体中文](/README_zh-Hans.md) | [繁體中文](/README_zh-Hant.md) | [日本語](/README_ja.md) | [Deutsch](/README_de.md) | [한국어](/README_ko.md)\n\n\u003cdiv align=center\u003e\n\u003cimg src=\"/doc/image/logo.svg\" width=\"400\" height=\"150\"/\u003e\n\u003c/div\u003e\n\n## LibDriver MPU9250\n\n[![MISRA](https://img.shields.io/badge/misra-compliant-brightgreen.svg)](/misra/README.md) [![API](https://img.shields.io/badge/api-reference-blue.svg)](https://www.libdriver.com/docs/mpu9250/index.html) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](/LICENSE)\n\nMPU9250 is a multi-chip module (MCM) consisting of two dies integrated into a single QFN package. One die houses the 3-Axis gyroscope and the 3-Axis accelerometer. The other die houses the AK8963 3-Axis magnetometer from Asahi Kasei Microdevices Corporation. Hence, the MPU9250 is a 9-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer and a Digital Motion Processor™ (DMP) all in a small 3x3x1mm package available as a pin-compatible upgrade from the MPU6515.With its dedicated I2C sensor bus, the MPU9250 directly provides complete 9-axis MotionFusion™ output. The MPU9250 MotionTracking device, with its 9-axis integration, on-chip MotionFusion™, and runtime calibration firmware, enables manufacturers to eliminate the costly and complex selection, qualification, and system level integration of discrete devices, guaranteeing optimal motion performance for consumers.MPU9250 is also designed to interface with multiple non-inertial digital sensors, such as pressure sensors, on its auxiliary I2C port.MPU9250 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope outputs, three 16-bit ADCs for digitizing the accelerometer outputs, and three 16-bit ADCs for digitizing the magnetometer outputs. For precision tracking of both fast and slow motions, the parts feature a user-programmable gyroscope full-scale range of ±250, ±500, ±1000, and ±2000°/sec (dps), a user-programmable accelerometer full-scale range of ±2g, ±4g, ±8g, and ±16g, and a magnetometer full-scale range of ±4800μT.\n\nLibDriver MPU9250 is the full function driver of mpu9250 launched by LibDriver. It provides acceleration reading, angular velocity reading, magnetometer reading, attitude angle reading, dmp reading, tap detection and other functions. LibDriver is MISRA compliant.\n\n### Table of Contents\n\n  - [Instruction](#Instruction)\n  - [Install](#Install)\n  - [Usage](#Usage)\n    - [example basic](#example-basic)\n    - [example fifo](#example-fifo)\n    - [example dmp](#example-dmp)\n  - [Document](#Document)\n  - [Contributing](#Contributing)\n  - [License](#License)\n  - [Contact Us](#Contact-Us)\n\n### Instruction\n\n/src includes LibDriver MPU9250 source files.\n\n/interface includes LibDriver MPU9250 IIC, SPI platform independent template.\n\n/test includes LibDriver MPU9250 driver test code and this code can test the chip necessary function simply.\n\n/example includes LibDriver MPU9250 sample code.\n\n/doc includes LibDriver MPU9250 offline document.\n\n/datasheet includes MPU9250 datasheet.\n\n/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.\n\n/misra includes the LibDriver MISRA code scanning results.\n\n### Install\n\nReference /interface IIC, SPI platform independent template and finish your platform IIC, SPI driver.\n\nAdd the /src directory, the interface driver for your platform, and your own drivers to your project, if you want to use the default example drivers, add the /example directory to your project.\n\n### Usage\n\nYou can refer to the examples in the /example directory to complete your own driver. If you want to use the default programming examples, here's how to use them.\n\n#### example basic\n\n```C\n#include \"driver_mpu9250_basic.h\"\n\nuint8_t res;\nuint32_t i;\nuint32_t times;\nfloat g[3];\nfloat dps[3];\nfloat ut[3];\nfloat degrees;\nmpu9250_address_t addr;\n\n/* init */\naddr = MPU9250_ADDRESS_AD0_LOW;\nres = mpu9250_basic_init(MPU9250_INTERFACE_IIC, addr);\nif (res != 0)\n{\n    return 1;\n}\n\n...\n    \n/* read all */\ntimes = 3;\nfor (i = 0; i \u003c times; i++)\n{\n    /* read */\n    if (mpu9250_basic_read(g, dps, ut) != 0)\n    {\n        (void)mpu9250_basic_deinit();\n\n        return 1;\n    }\n\n    ...\n        \n    if (mpu9250_basic_read_temperature(\u0026degrees) != 0)\n    {\n        (void)mpu9250_basic_deinit();\n\n        return 1;\n    }\n\n    ...\n        \n    /* output */\n    mpu9250_interface_debug_print(\"mpu9250: %d/%d.\\n\", i + 1, times);\n    mpu9250_interface_debug_print(\"mpu9250: acc x is %0.2fg.\\n\", g[0]);\n    mpu9250_interface_debug_print(\"mpu9250: acc y is %0.2fg.\\n\", g[1]);\n    mpu9250_interface_debug_print(\"mpu9250: acc z is %0.2fg.\\n\", g[2]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro x is %0.2fdps.\\n\", dps[0]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro y is %0.2fdps.\\n\", dps[1]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro z is %0.2fdps.\\n\", dps[2]);\n    mpu9250_interface_debug_print(\"mpu9250: mag x is %0.2fuT.\\n\", ut[0]);\n    mpu9250_interface_debug_print(\"mpu9250: mag y is %0.2fuT.\\n\", ut[1]);\n    mpu9250_interface_debug_print(\"mpu9250: mag z is %0.2fuT.\\n\", ut[2]);\n    mpu9250_interface_debug_print(\"mpu9250: temperature %0.2fC.\\n\", degrees);\n\n    ...\n        \n    /* delay 1000 ms */\n    mpu9250_interface_delay_ms(1000);\n\n    ...\n}\n\n...\n    \n/* deinit */\n(void)mpu9250_basic_deinit();\n\nreturn 0;\n```\n\n#### example fifo\n\n```C\n#include \"driver_mpu9250_fifo.h\"\n\nuint32_t i;\nuint32_t times;\nuint16_t len;\nuint8_t (*g_gpio_irq)(void) = NULL;\nstatic int16_t gs_accel_raw[128][3];\nstatic float gs_accel_g[128][3];\nstatic int16_t gs_gyro_raw[128][3];\nstatic float gs_gyro_dps[128][3];\natic int16_t gs_mag_raw[128][3];\nstatic float gs_mag_ut[128][3];\nmpu9250_address_t addr;\n\n/* gpio init */\nif (gpio_interrupt_init() != 0)\n{\n    return 1;\n}\ng_gpio_irq = mpu9250_fifo_irq_handler;\n\n/* init */\naddr = MPU9250_ADDRESS_AD0_LOW;\nif (mpu9250_fifo_init(MPU9250_INTERFACE_IIC, addr) != 0)\n{\n    g_gpio_irq = NULL;\n    (void)gpio_interrupt_deinit();\n\n    return 1;\n}\n\n/* delay 100 ms */\nmpu9250_interface_delay_ms(100);\n\n...\n\ntimes = 3;\nfor (i = 0; i \u003c times; i++)\n{\n    len = 128;\n\n    /* read */\n    if (mpu9250_fifo_read(gs_accel_raw, gs_accel_g,\n                          gs_gyro_raw, gs_gyro_dps, gs_mag_raw, gs_mag_ut, \u0026len) != 0)\n    {\n        (void)mpu9250_fifo_deinit();\n        g_gpio_irq = NULL;\n        (void)gpio_interrupt_deinit();\n\n        return 1;\n    }\n    \n    ...\n        \n    /* output */\n    mpu9250_interface_debug_print(\"mpu9250: %d/%d.\\n\", i + 1, times);\n    mpu9250_interface_debug_print(\"mpu9250: fifo %d.\\n\", len);\n    mpu9250_interface_debug_print(\"mpu9250: acc x[0] is %0.2fg.\\n\", gs_accel_g[0][0]);\n    mpu9250_interface_debug_print(\"mpu9250: acc y[0] is %0.2fg.\\n\", gs_accel_g[0][1]);\n    mpu9250_interface_debug_print(\"mpu9250: acc z[0] is %0.2fg.\\n\", gs_accel_g[0][2]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro x[0] is %0.2fdps.\\n\", gs_gyro_dps[0][0]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro y[0] is %0.2fdps.\\n\", gs_gyro_dps[0][1]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro z[0] is %0.2fdps.\\n\", gs_gyro_dps[0][2]);\n    mpu9250_interface_debug_print(\"mpu9250: mag x[0] is %0.2fuT.\\n\", gs_mag_ut[0][0]);\n    mpu9250_interface_debug_print(\"mpu9250: mag y[0] is %0.2fuT.\\n\", gs_mag_ut[0][1]);\n    mpu9250_interface_debug_print(\"mpu9250: mag z[0] is %0.2fuT.\\n\", gs_mag_ut[0][2]);\n    \n    ...\n        \n    /* delay 100 ms */\n    mpu9250_interface_delay_ms(100);\n    \n    ...\n}\n\n...\n    \n/* deinit */\n(void)mpu9250_fifo_deinit();\ng_gpio_irq = NULL;\n(void)gpio_interrupt_deinit();\n\nreturn 0;\n```\n\n#### example dmp\n\n```C\n#include \"driver_mpu9250_dmp.h\"\n\nuint32_t i;\nuint32_t times;\nuint32_t cnt;\nuint16_t len;\nuint8_t (*g_gpio_irq)(void) = NULL;\nstatic int16_t gs_accel_raw[128][3];\nstatic float gs_accel_g[128][3];\nstatic int16_t gs_gyro_raw[128][3];      \nstatic float gs_gyro_dps[128][3];\nstatic int32_t gs_quat[128][4];          \nstatic float gs_pitch[128];              \nstatic float gs_roll[128];                \nstatic float gs_yaw[128];                      \nmpu9250_address_t addr;\n\nstatic void a_receive_callback(uint8_t type)\n{\n    switch (type)\n    {\n        case MPU9250_INTERRUPT_MOTION :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: irq motion.\\n\");\n            \n            break;\n        }\n        case MPU9250_INTERRUPT_FIFO_OVERFLOW :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: irq fifo overflow.\\n\");\n            \n            break;\n        }\n        case MPU9250_INTERRUPT_FSYNC_INT :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: irq fsync int.\\n\");\n            \n            break;\n        }\n        case MPU9250_INTERRUPT_DMP :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: irq dmp\\n\");\n            \n            break;\n        }\n        case MPU9250_INTERRUPT_DATA_READY :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: irq data ready\\n\");\n            \n            break;\n        }\n        default :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: irq unknown code.\\n\");\n            \n            break;\n        }\n    }\n}\n\nstatic void a_dmp_tap_callback(uint8_t count, uint8_t direction)\n{\n    switch (direction)\n    {\n        case MPU9250_DMP_TAP_X_UP :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq x up with %d.\\n\", count);\n            \n            break;\n        }\n        case MPU9250_DMP_TAP_X_DOWN :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq x down with %d.\\n\", count);\n            \n            break;\n        }\n        case MPU9250_DMP_TAP_Y_UP :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq y up with %d.\\n\", count);\n            \n            break;\n        }\n        case MPU9250_DMP_TAP_Y_DOWN :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq y down with %d.\\n\", count);\n            \n            break;\n        }\n        case MPU9250_DMP_TAP_Z_UP :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq z up with %d.\\n\", count);\n            \n            break;\n        }\n        case MPU9250_DMP_TAP_Z_DOWN :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq z down with %d.\\n\", count);\n            \n            break;\n        }\n        default :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: tap irq unknown code.\\n\");\n            \n            break;\n        }\n    }\n}\n\nstatic void a_dmp_orient_callback(uint8_t orientation)\n{\n    switch (orientation)\n    {\n        case MPU9250_DMP_ORIENT_PORTRAIT :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: orient irq portrait.\\n\");\n            \n            break;\n        }\n        case MPU9250_DMP_ORIENT_LANDSCAPE :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: orient irq landscape.\\n\");\n            \n            break;\n        }\n        case MPU9250_DMP_ORIENT_REVERSE_PORTRAIT :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: orient irq reverse portrait.\\n\");\n            \n            break;\n        }\n        case MPU9250_DMP_ORIENT_REVERSE_LANDSCAPE :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: orient irq reverse landscape.\\n\");\n            \n            break;\n        }\n        default :\n        {\n            mpu9250_interface_debug_print(\"mpu9250: orient irq unknown code.\\n\");\n            \n            break;\n        }\n    }\n}\n\n/* init */\nif (gpio_interrupt_init() != 0)\n{\n    return 1;\n}\ng_gpio_irq = mpu9250_dmp_irq_handler;\n\n/* init */\naddr = MPU9250_ADDRESS_AD0_LOW;\nif (mpu9250_dmp_init(MPU9250_INTERFACE_IIC, addr, a_receive_callback, \n                     a_dmp_tap_callback, a_dmp_orient_callback) != 0)\n{\n    g_gpio_irq = NULL;\n    (void)gpio_interrupt_deinit();\n\n    return 1;\n}\n\n/* delay 500 ms */\nmpu9250_interface_delay_ms(500);\n\n...\n    \ntimes = 3;\nfor (i = 0; i \u003c times; i++)\n{\n    len = 128;\n\n    /* read */\n    if (mpu9250_dmp_read_all(gs_accel_raw, gs_accel_g,\n                             gs_gyro_raw, gs_gyro_dps, \n                             gs_quat,\n                             gs_pitch, gs_roll, gs_yaw,\n                             \u0026len) != 0)\n    {\n        (void)mpu9250_dmp_deinit();\n        g_gpio_irq = NULL;\n        (void)gpio_interrupt_deinit();\n\n        return 1;\n    }\n\n    /* output */\n    mpu9250_interface_debug_print(\"mpu9250: %d/%d.\\n\", i + 1, times);\n    mpu9250_interface_debug_print(\"mpu9250: fifo %d.\\n\", len);\n    mpu9250_interface_debug_print(\"mpu9250: pitch[0] is %0.2fdeg.\\n\", gs_pitch[0]);\n    mpu9250_interface_debug_print(\"mpu9250: roll[0] is %0.2fdeg.\\n\", gs_roll[0]);\n    mpu9250_interface_debug_print(\"mpu9250: yaw[0] is %0.2fdeg.\\n\", gs_yaw[0]);\n    mpu9250_interface_debug_print(\"mpu9250: acc x[0] is %0.2fg.\\n\", gs_accel_g[0][0]);\n    mpu9250_interface_debug_print(\"mpu9250: acc y[0] is %0.2fg.\\n\", gs_accel_g[0][1]);\n    mpu9250_interface_debug_print(\"mpu9250: acc z[0] is %0.2fg.\\n\", gs_accel_g[0][2]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro x[0] is %0.2fdps.\\n\", gs_gyro_dps[0][0]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro y[0] is %0.2fdps.\\n\", gs_gyro_dps[0][1]);\n    mpu9250_interface_debug_print(\"mpu9250: gyro z[0] is %0.2fdps.\\n\", gs_gyro_dps[0][2]);\n\n    /* delay 500 ms */\n    mpu9250_interface_delay_ms(500);\n    \n    ....\n        \n    /* get the pedometer step count */\n    res = mpu9250_dmp_get_pedometer_counter(\u0026cnt);\n    if (res != 0)\n    {\n        (void)mpu9250_dmp_deinit();\n        g_gpio_irq = NULL;\n        (void)gpio_interrupt_deinit();\n\n        return 1;\n    }\n    \n    ...\n}\n\n...\n\n/* deinit */\n(void)mpu9250_dmp_deinit();\ng_gpio_irq = NULL;\n(void)gpio_interrupt_deinit();\n\nreturn 0;\n```\n\n### Document\n\nOnline documents: [https://www.libdriver.com/docs/mpu9250/index.html](https://www.libdriver.com/docs/mpu9250/index.html).\n\nOffline documents: /doc/html/index.html.\n\n### Contributing\n\nPlease refer to CONTRIBUTING.md.\n\n### License\n\nCopyright (c) 2015 - present LibDriver All rights reserved\n\n\n\nThe MIT License (MIT) \n\n\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\n\nof this software and associated documentation files (the \"Software\"), to deal\n\nin the Software without restriction, including without limitation the rights\n\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\ncopies of the Software, and to permit persons to whom the Software is\n\nfurnished to do so, subject to the following conditions: \n\n\n\nThe above copyright notice and this permission notice shall be included in all\n\ncopies or substantial portions of the Software. \n\n\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\nSOFTWARE. \n\n### Contact Us\n\nPlease send an e-mail to lishifenging@outlook.com.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibdriver%2Fmpu9250","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibdriver%2Fmpu9250","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibdriver%2Fmpu9250/lists"}