{ "info": { "author": "Mika Tuupola", "author_email": "tuupola@appelsiini.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: Implementation :: MicroPython" ], "description": "# MicroPython 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\n## Usage\n\nSimple test with never ending loop.\n\n```python\nimport utime\nfrom machine import I2C, Pin\nfrom mpu9250 import MPU9250\n\ni2c = I2C(scl=Pin(22), sda=Pin(21))\nsensor = MPU9250(i2c)\n\nprint(\"MPU9250 id: \" + hex(sensor.whoami))\n\nwhile True:\n print(sensor.acceleration)\n print(sensor.gyro)\n print(sensor.magnetic)\n\n utime.sleep_ms(1000)\n```\n\nBy default the library returns 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. Note that both the MPU6500 and the AK8963 drivers are available as separate classes. MPU9250 is actually a composite of those two.\n\n```python\nimport utime\nfrom machine import I2C, Pin\nfrom mpu9250 import MPU9250\nfrom mpu6500 import MPU6500, SF_G, SF_DEG_S\n\ni2c = I2C(scl=Pin(22), sda=Pin(21))\nmpu6500 = MPU6500(i2c, accel_sf=SF_G, gyro_sf=SF_DEG_S)\nsensor = MPU9250(i2c, mpu6500=mpu6500)\n\nprint(\"MPU9250 id: \" + hex(sensor.whoami))\n\nwhile True:\n print(sensor.acceleration)\n print(sensor.gyro)\n print(sensor.magnetic)\n\n utime.sleep_ms(1000)\n```\n\nMore realistic example usage with timer. If you get `OSError: 26` or `i2c driver install error` after soft reboot do a hard reboot.\n\n```python\nimport micropython\nfrom machine import I2C, Pin, Timer\nfrom mpu9250 import MPU9250\n\nmicropython.alloc_emergency_exception_buf(100)\n\ni2c = I2C(scl=Pin(22), sda=Pin(21))\nsensor = MPU9250(i2c)\n\ndef read_sensor(timer):\n print(sensor.acceleration)\n print(sensor.gyro)\n print(sensor.magnetic)\n\nprint(\"MPU9250 id: \" + hex(sensor.whoami))\n\ntimer_0 = Timer(0)\ntimer_0.init(period=1000, mode=Timer.PERIODIC, callback=read_sensor)\n```\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 millisecods between the samples.\n\nWith the default values of `256` and `200` calibration takes aproximately one minute. While calibration function is running the sensor should be rotated multiple times around each axis.\n\n```python\nfrom machine import I2C, Pin\nfrom mpu9250 import MPU9250\nfrom ak8963 import AK8963\n\ni2c = I2C(scl=Pin(22), sda=Pin(21))\n\nak8963 = AK8963(i2c)\noffset, scale = ak8963.calibrate(count=256, delay=200)\n\nsensor = MPU9250(i2c, 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 strore 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 machine import I2C, Pin\nfrom mpu9250 import MPU9250\nfrom ak8963 import AK8963\n\ni2c = I2C(scl=Pin(22), sda=Pin(21))\nak8963 = AK8963(\n i2c,\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.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tuupola/micropython-mpu9250", "keywords": "accelerometer,gyro,magnetometer,micropython,i2c", "license": "MIT", "maintainer": "Mika Tuupola", "maintainer_email": "tuupola@appelsiini.net", "name": "micropython-mpu9250", "package_url": "https://pypi.org/project/micropython-mpu9250/", "platform": "", "project_url": "https://pypi.org/project/micropython-mpu9250/", "project_urls": { "Homepage": "https://github.com/tuupola/micropython-mpu9250" }, "release_url": "https://pypi.org/project/micropython-mpu9250/0.2.1/", "requires_dist": null, "requires_python": "", "summary": "MicroPython I2C driver for MPU9250 9-axis motion tracking device", "version": "0.2.1" }, "last_serial": 4789885, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "2b910c2bdebad0fd65ca9a74d3af497a", "sha256": "c125cf385a71692fa1fce24362b9336c170e4a33c4af2ccb89f5ec3e22af8db1" }, "downloads": -1, "filename": "micropython-mpu9250-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2b910c2bdebad0fd65ca9a74d3af497a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3474, "upload_time": "2018-02-17T07:53:17", "url": "https://files.pythonhosted.org/packages/23/05/ed832ef5a0ca63bf460e993cb3f24c1666decd964203e3cd7cecb5a8f5aa/micropython-mpu9250-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "53926c6c09ec0206963e50c0ff10d9c6", "sha256": "6606a2ae2838de4a6408acc81b071721f9d3c6e19dd887571a73e5cd4998335f" }, "downloads": -1, "filename": "micropython-mpu9250-0.2.0.tar.gz", "has_sig": false, "md5_digest": "53926c6c09ec0206963e50c0ff10d9c6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5791, "upload_time": "2018-04-08T07:20:14", "url": "https://files.pythonhosted.org/packages/57/7e/cbdf245a6898933eae1b67b080c08e214459f87d0fe52ada4731236c2f0e/micropython-mpu9250-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "0f0b831897bee19174bfc1f0b27dc564", "sha256": "a6382bdc55bb3a3aac2cb2d05631db297c662291f4f6fb82deb26a57015553c3" }, "downloads": -1, "filename": "micropython-mpu9250-0.2.1.tar.gz", "has_sig": false, "md5_digest": "0f0b831897bee19174bfc1f0b27dc564", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6368, "upload_time": "2019-02-07T07:20:27", "url": "https://files.pythonhosted.org/packages/67/9e/087148b6c4cdb84e0ab3f71938e74f1e021d87381a4e320c1c2f95641481/micropython-mpu9250-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0f0b831897bee19174bfc1f0b27dc564", "sha256": "a6382bdc55bb3a3aac2cb2d05631db297c662291f4f6fb82deb26a57015553c3" }, "downloads": -1, "filename": "micropython-mpu9250-0.2.1.tar.gz", "has_sig": false, "md5_digest": "0f0b831897bee19174bfc1f0b27dc564", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6368, "upload_time": "2019-02-07T07:20:27", "url": "https://files.pythonhosted.org/packages/67/9e/087148b6c4cdb84e0ab3f71938e74f1e021d87381a4e320c1c2f95641481/micropython-mpu9250-0.2.1.tar.gz" } ] }