{"id":15142176,"url":"https://github.com/wallarug/circuitpython_mpu9250","last_synced_at":"2025-09-23T15:31:06.455Z","repository":{"id":72814111,"uuid":"192475373","full_name":"wallarug/CircuitPython_MPU9250","owner":"wallarug","description":"CircuitPython I2C driver for MPU9250 9-axis motion tracking device","archived":false,"fork":false,"pushed_at":"2024-03-03T10:06:39.000Z","size":111,"stargazers_count":20,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T13:04:41.325Z","etag":null,"topics":["acceleration","circuitpython","gyroscope","magnetometer","mpu6500","mpu9250"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"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/wallarug.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-06-18T06:00:53.000Z","updated_at":"2024-10-23T23:48:48.000Z","dependencies_parsed_at":"2023-02-23T12:31:10.790Z","dependency_job_id":null,"html_url":"https://github.com/wallarug/CircuitPython_MPU9250","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallarug%2FCircuitPython_MPU9250","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallarug%2FCircuitPython_MPU9250/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallarug%2FCircuitPython_MPU9250/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallarug%2FCircuitPython_MPU9250/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wallarug","download_url":"https://codeload.github.com/wallarug/CircuitPython_MPU9250/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233983415,"owners_count":18761117,"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":["acceleration","circuitpython","gyroscope","magnetometer","mpu6500","mpu9250"],"created_at":"2024-09-26T09:24:15.931Z","updated_at":"2025-09-23T15:31:01.073Z","avatar_url":"https://github.com/wallarug.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python MPU-9250 (MPU-6500 + AK8963) I2C driver\n\nMPU-9250 is a System in Package (SiP) which combines two chips: MPU-6500 which contains 3-axis gyroscope and 3-axis accelerometer and an AK8963 which is a 3-axis digital compass.\n\nThis library communicates with these sensors over I2C. It is written for \nCircuitPython.\n\n## Usage\n\nSimple test with never ending loop.\n\n```python\nimport time\nfrom mpu9250 import MPU9250\n\nsensor = MPU9250()\n\nprint(\"MPU9250 id: \" + hex(sensor.whoami))\n\nwhile True:\n    print(sensor.read_acceleration())\n    print(sensor.read_gyro())\n    print(sensor.read_magnetic())\n\n    time.sleep(1000)\n```\n\nThe library returns a 3-tuple of X, Y, Z axis values for either acceleration, gyroscope and magnetometer ie compass. Default units are `m/s^2`, `rad/s` and `uT`. It is possible to also get acceleration values in `g` and gyro values `deg/s`. See the example below. \n\nNote that both the MPU6500 and the AK8963 drivers are available as separate classes. MPU9250 is actually a composite of those two.\n\n## Magnetometer Calibration\n\nFor real life applications you should almost always [calibrate the magnetometer](https://appelsiini.net/2018/calibrate-magnetometer/). The AK8963 driver supports both hard and soft iron correction. Calibration function takes two parameters: `count` is the number of samples to collect and `delay` is the delay in milliseconds between the samples.\n\nWith the default values of `256` and `200` calibration takes approximately one minute. While calibration function is running the sensor should be rotated multiple times around each axis.\n\n```python\nfrom mpu9250 import MPU9250\nfrom ak8963 import AK8963\n\nak8963 = AK8963()\noffset, scale = ak8963.calibrate(count=256, delay=200)\n\nsensor = MPU9250(ak8963=ak8963)\n```\n\nAfter finishing calibration the `calibrate()` method also returns tuples for both hard iron `offset` and soft iron `scale`. To avoid calibrating after each startup it would make sense to store these values in NVRAM or config file and pass them to the AK8963 constructor. Below example only illustrates how to use the constructor.\n\n```python\nfrom mpu9250 import MPU9250\nfrom ak8963 import AK8963\n\nak8963 = AK8963(\n    offset=(-136.8931640625, -160.482421875, 59.02880859375),\n    scale=(1.18437220840483, 0.923895823933424, 0.931707933618979)\n)\nsensor = MPU9250(i2c, ak8963=ak8963)\n```\n\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.txt) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallarug%2Fcircuitpython_mpu9250","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwallarug%2Fcircuitpython_mpu9250","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallarug%2Fcircuitpython_mpu9250/lists"}