python library to use the Adafruit NXP 9-Dof IMU
Project description
NXP IMU
Python drivers for Adafruit Precision NXP 9-DOF. This is basically a python version of Adafruit's FXOS8700 and their FXAS21002C written in C++ for the Arduino.
NXP Precision 9DoF
The board consists of two separate ICs, described below:
FXOS8700 3-Axis Accelerometer/Magnetometer
- 2-3.6V Supply
- ±2 g/±4 g/±8 g adjustable acceleration range
- ±1200 µT magnetic sensor range
- Output data rates (ODR) from 1.563 Hz to 800 Hz
- 14-bit ADC resolution for acceleration measurements
- 16-bit ADC resolution for magnetic measurements
FXAS21002 3-Axis Gyroscope
- 2-3.6V Supply
- ±250/500/1000/2000°/s configurable range
- Output Data Rates (ODR) from 12.5 to 800 Hz
- 16-bit digital output resolution
- 192 bytes FIFO buffer (32 X/Y/Z samples)
Setup
Usage
Verifying it is there:
sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1f
20: -- 21 -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
See the examples
folder, but to have the IMU run at 4G and 2000
degrees per second:
#!/usr/bin/env python3
from nxp_imu import IMU, Rate
import time
# verbose will print some start-up info on the IMU sensors
imu = IMU(gs=4, dps=2000, verbose=True)
# setting a bias correction for the accel only, the mags/gyros
# are not getting a bias correction
imu.setBias((0.1,-0.02,.25), None, None)
# grab data at 10Hz
rate = Rate(10)
while True:
header = 67
print('-'*header)
print("| {:17} | {:20} | {:20} |".format("Accels [g's]", " Magnet [uT]", "Gyros [dps]"))
print('-'*header)
for _ in range(10):
a, m, g = imu.get()
print('| {:>5.2f} {:>5.2f} {:>5.2f} | {:>6.1f} {:>6.1f} {:>6.1f} | {:>6.1f} {:>6.1f} {:>6.1f} |'.format(
a[0], a[1], a[2],
m[0], m[1], m[2],
g[0], g[1], g[2])
)
time.sleep(0.50)
print('-'*header)
print(' uT: micro Tesla')
print(' g: gravity')
print('dps: degrees per second')
print('')
rate.sleep()
Examples
pi@nav examples $ ./test.py
========================================
FXOS8700
Accelerometer:
Addr: 0x1F
Range: +/- 2 G
Magnetometer:
Range: +/- 1200
Temperature: 0 C
========================================
FXAS21002C Gyro
Addr: 0x21
Range: +/- 250dps
Temperature: 10 C
-----------------------------------------------
| Accels [g's] | Orient(r,p,h) [deg] |
-----------------------------------------------
| 0.0 -0.0 1.0 | -0.0 -0.0 3.0 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
| 0.0 -0.0 1.0 | -0.0 -0.0 2.9 |
-----------------------------------------------
r: roll
p: pitch
h: heading
g: gravity
deg: degree
========================================
FXOS8700
Accelerometer:
Addr: 0x1F
Range: +/- 4 G
Magnetometer:
Range: +/- 1200
Temperature: 25 C
========================================
FXAS21002C Gyro
Addr: 0x21
Range: +/- 2000dps
Temperature: 10 C
-------------------------------------------------------------------
| Accels [g's] | Magnet [uT] | Gyros [dps] |
-------------------------------------------------------------------
| 0.04 -0.04 1.02 | -21.5 -4.7 8.3 | 0.8 -1.4 -0.2 |
| 0.04 -0.04 1.03 | -21.6 -5.3 8.3 | 1.2 -1.1 -0.4 |
| 0.04 -0.04 1.02 | -21.9 -4.4 10.5 | 0.4 -0.9 -0.1 |
| 0.04 -0.04 1.02 | -21.5 -4.8 9.9 | 1.3 -1.2 0.1 |
| 0.04 -0.04 1.02 | -22.4 -4.9 8.7 | 1.2 -0.8 -0.2 |
| 0.04 -0.04 1.02 | -21.7 -5.4 8.5 | 0.2 -1.6 0.0 |
| 0.04 -0.04 1.03 | -21.9 -4.7 8.1 | 1.2 -1.2 -0.4 |
| 0.04 -0.04 1.02 | -22.2 -4.4 10.0 | 1.5 -1.5 -0.1 |
| 0.04 -0.04 1.02 | -22.2 -5.7 9.1 | 0.5 -1.2 -0.4 |
| 0.04 -0.04 1.02 | -22.3 -5.0 8.0 | 0.7 -1.4 -0.6 |
-------------------------------------------------------------------
uT: micro Tesla
g: gravity
dps: degrees per second
Done ...
Decination Angle
Remeber, depending on where you are on the Earth, true North changes because the Earth is not a perfect sphere. You can get the declination angle for your location from: http://www.magnetic-declination.com/
Documents
The /docs
folder has the datasheets for both the accel/magnetometer
and the gyros.
MIT License
Copyright (c) 2017 Kevin J. Walchko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nxp_imu-0.6.2.tar.gz
.
File metadata
- Download URL: nxp_imu-0.6.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.2 CPython/3.7.5 Linux/5.3.0-29-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c71ed9f1242aefb649e01b67df6f09056e4e584dbbbe827ab84512fae82425df |
|
MD5 | bbe9ac3d384bf7e0fae138aaefa98f00 |
|
BLAKE2b-256 | c2d1a745edf6e1e8da9bbe42ea341b670c32a500e3b3af9b4eabe3949ca2cef9 |
File details
Details for the file nxp_imu-0.6.2-py3-none-any.whl
.
File metadata
- Download URL: nxp_imu-0.6.2-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.2 CPython/3.7.5 Linux/5.3.0-29-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0f389877578c2004557daf3bbfcf13396115f0b1911994f54e2834508f2e41a |
|
MD5 | c26008d0966e748d858b08d97a877681 |
|
BLAKE2b-256 | 1860715b17136edba098f724b90734104d1fded385e0d0258e286d3010ddc2eb |