Package: nxp-imu
NXP IMUPython drivers forAdafruit Precision NXP
9-DOF. This is basically a
python version of Adafruit'sFXOS8700and theirFXAS21002Cwritten in
C++ for the Arduino.NXP Precision 9DoFThe board consists of two separate ICs, described below:FXOS8700 3-Axis Accelerometer/Magnetometer2-3.6V Supply±2 g/±4 g/±8 g adjustable acceleration range±1200 µT magnetic sensor rangeOutput data rates (ODR) from 1.563 Hz to 800 Hz14-bit ADC resolution for acceleration measurements16-bit ADC resolution for magnetic measurementsFXAS21002 3-Axis Gyroscope2-3.6V Supply±250/500/1000/2000°/s configurable rangeOutput Data Rates (ODR) from 12.5 to 800 Hz16-bit digital output resolution192 bytes FIFO buffer (32 X/Y/Z samples)SetupAdafruit setup
tutorialUsageVerifying 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 theexamplesfolder, but to have the IMU run at 4G and 2000
degrees per second:#!/usr/bin/env python3fromnxp_imuimportIMU,Rateimporttime# verbose will print some start-up info on the IMU sensorsimu=IMU(gs=4,dps=2000,verbose=True)# setting a bias correction for the accel only, the mags/gyros# are not getting a bias correctionimu.setBias((0.1,-0.02,.25),None,None)# grab data at 10Hzrate=Rate(10)whileTrue:header=67print('-'*header)print("|{:17}|{:20}|{:20}|".format("Accels [g's]"," Magnet [uT]","Gyros [dps]"))print('-'*header)for_inrange(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()Examplespi@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 AngleRemeber, depending on where you are on the Earth, true North changes
because the Earth isnota perfect sphere. You can get the declination
angle for your location from:http://www.magnetic-declination.com/DocumentsThe/docsfolder has the datasheets for both the accel/magnetometer
and the gyros.MIT LicenseCopyright (c) 2017 Kevin J. WalchkoPermission 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.