pyupm_mpu9150 module

class pyupm_mpu9150.AK8975(bus=0, address=12)[source]

Bases: object

API for the AK8975 magnetometer.

ID: ak8975

Name: 3-axis Magnetometer

Other Names: AK9875

Category: compass

Manufacturer: seeed

Connection: i2c

Link:http://www.akm.com/akm/en/file/datasheet/AK8975.pdf This is a 3-axis magnetometer, which can be used alone, or coupled with another device (such as the mcu9150 9-axis motion sensor).

C++ includes: ak8975.hpp

ASTC_SELF = 64
CNTL_FUSE_ACCESS = 15
CNTL_MEASURE = 1
CNTL_PWRDWN = 0
CNTL_SELFTEST = 8
REG_ASAX = 16
REG_ASAY = 17
REG_ASAZ = 18
REG_ASTC = 12
REG_CNTL = 10
REG_HXH = 4
REG_HXL = 3
REG_HYH = 6
REG_HYL = 5
REG_HZH = 8
REG_HZL = 7
REG_INFO = 1
REG_ST1 = 2
REG_ST2 = 9
REG_WIA = 0
ST1_DRDY = 1
ST2_DERR = 4
ST2_HOFL = 8
getMagnetometer(x, y, z)[source]

void getMagnetometer(float *x, float *y, float *z)

return the compensated values for the x, y, and z axes. The unit of measurement is in micro-teslas (uT).

x: pointer to returned X axis value

y: pointer to returned Y axis value

z: pointer to returned Z axis value

init()[source]

bool init()

set up initial values and start operation

dsr: the data sampling rate: one of the DSR_BITS_T values

true if successful

isReady()[source]

bool isReady()

check to see if the ST1_DRDY bit is set, indicating the device can accept commands

true if device is ready, false otherwise

selfTest()[source]

bool selfTest()

do a self test sequence. When self test is executed, the device activates internal calibrated magnets, and measures them, updating the measurement registers. Once complete, the data can be read as usual ( getMagnetometer()) and the returned values compared against the following limits to determine correctness:

-100 < X < +100; -100 < Y < +100; -1000 < Z < -300

true if successful, false otherwise

setMode(mode)[source]

bool setMode(CNTL_MODES_T mode)

put the chip into a specific mode

mode: one of the CNTL_MODES_T values

true if successful

update(selfTest=False)[source]

bool update(bool selfTest=false)

take a measurement

selfTest: true if we are running a self test, false (default) otherwise.

true if successful, false otherwise

waitforDeviceReady()[source]

bool waitforDeviceReady()

check to see if device is ready and sleep/retry if not. Returns once device indicates it’s ready.

true if device is ready, false if retries exhausted

class pyupm_mpu9150.MPU60X0(bus=0, address=104)[source]

Bases: object

API for the MPU60X0 3-axis Gyroscope and 3-axis Accelerometer.

ID: mpu60x0

Name: 3-axis Gyroscope and 3-axis Accelerometer

Category: accelerometer compass

Manufacturer: seeed

Connection: i2c gpio

Link:https://www.invensense.com/products/motion- tracking/6-axis/mpu-6050/ The MPU60X0 devices provide the world’s first integrated 6-axis motion processor solution that eliminates the package-level gyroscope and accelerometer cross-axis misalignment associated with discrete solutions. The devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die.

While not all of the functionality of this device is supported initially, methods and register definitions are provided that should allow an end user to implement whatever features are required.

C++ includes: mpu60x0.hpp

ACCEL_FIFO_EN = 8
ACCEL_ON_DELAY0 = 16
ACCEL_ON_DELAY1 = 32
ACCEL_RESET = 2
AFS_16 = 3
AFS_2 = 0
AFS_4 = 1
AFS_8 = 2
AFS_SEL0 = 8
AFS_SEL1 = 16
CLKOUT_EN = 1
CLKSEL0 = 1
CLKSEL1 = 2
CLKSEL2 = 4
CLK_STOP = 7
CONFIG_DLPF_CFG0 = 1
CONFIG_DLPF_CFG1 = 2
CONFIG_DLPF_CFG2 = 4
CONFIG_EXT_SYNC_SET0 = 8
CONFIG_EXT_SYNC_SET1 = 16
CONFIG_EXT_SYNC_SET2 = 32
COUNT_0 = 0
COUNT_1 = 1
COUNT_2 = 2
COUNT_4 = 3
DATA_RDY_EN = 1
DATA_RDY_INT = 1
DELAY_ES_SHADOW = 128
DEVICE_RESET = 128
DLPF_10_10 = 5
DLPF_184_188 = 1
DLPF_21_20 = 4
DLPF_260_256 = 0
DLPF_44_42 = 3
DLPF_5_5 = 6
DLPF_94_98 = 2
DLPF_RESERVED = 7
EXT_SYNC_ACCEL_XOUT = 5
EXT_SYNC_ACCEL_YOUT = 6
EXT_SYNC_ACCEL_ZOUT = 7
EXT_SYNC_DISABLED = 0
EXT_SYNC_GYRO_XOUT = 2
EXT_SYNC_GYRO_YOUT = 3
EXT_SYNC_GYRO_ZOUT = 4
EXT_SYNC_TEMP_OUT = 1
FF_COUNT0 = 4
FF_COUNT1 = 8
FF_EN = 128
FF_INT = 128
FIFO_EN = 64
FIFO_OFLOW_EN = 16
FIFO_OFLOW_INT = 16
FIFO_RESET = 4
FSYNC_INT_EN = 4
FSYNC_INT_LEVEL = 8
FS_1000 = 2
FS_2000 = 3
FS_250 = 0
FS_500 = 1
FS_SEL0 = 8
FS_SEL1 = 16
GYRO_RESET = 4
I2C_BYPASS_ENABLE = 2
I2C_IF_DIS = 16
I2C_LOST_ARB = 32
I2C_MST_CLK0 = 1
I2C_MST_CLK1 = 2
I2C_MST_CLK2 = 4
I2C_MST_CLK3 = 8
I2C_MST_DLY0 = 1
I2C_MST_DLY1 = 2
I2C_MST_DLY2 = 4
I2C_MST_DLY3 = 8
I2C_MST_DLY4 = 16
I2C_MST_EN = 32
I2C_MST_INT = 8
I2C_MST_INT_EN = 8
I2C_MST_P_NSR = 16
I2C_MST_RESET = 2
I2C_SLV0_DLY_EN = 1
I2C_SLV0_NACK = 1
I2C_SLV1_DLY_EN = 2
I2C_SLV1_NACK = 2
I2C_SLV2_DLY_EN = 4
I2C_SLV2_NACK = 4
I2C_SLV3_DLY_EN = 8
I2C_SLV3_NACK = 8
I2C_SLV4_DLY_EN = 16
I2C_SLV4_DONE = 64
I2C_SLV4_EN = 128
I2C_SLV4_INT_EN = 64
I2C_SLV4_NACK = 16
I2C_SLV4_REG_DIS = 32
I2C_SLV_ADDR0 = 1
I2C_SLV_ADDR1 = 2
I2C_SLV_ADDR2 = 4
I2C_SLV_ADDR3 = 8
I2C_SLV_ADDR4 = 16
I2C_SLV_ADDR5 = 32
I2C_SLV_ADDR6 = 64
I2C_SLV_BYTE_SW = 64
I2C_SLV_EN = 128
I2C_SLV_GRP = 16
I2C_SLV_LEN0 = 1
I2C_SLV_LEN1 = 2
I2C_SLV_LEN2 = 4
I2C_SLV_LEN3 = 8
I2C_SLV_REG_DIS = 32
I2C_SLV_RW = 128
INT_8MHZ = 0
INT_LEVEL = 128
INT_OPEN = 64
INT_RD_CLEAR = 16
LATCH_INT_EN = 32
LP_WAKE_1_25 = 0
LP_WAKE_20 = 2
LP_WAKE_40 = 3
LP_WAKE_5 = 1
LP_WAKE_CTRL0 = 64
LP_WAKE_CTRL1 = 128
MOT_COUNT0 = 1
MOT_COUNT1 = 2
MOT_EN = 64
MOT_INT = 64
MOT_XNEG = 128
MOT_XPOS = 64
MOT_YNEG = 32
MOT_YPOS = 16
MOT_ZNEG = 8
MOT_ZPOS = 4
MOT_ZRMOT = 1
MST_CLK_258 = 8
MST_CLK_267 = 7
MST_CLK_276 = 6
MST_CLK_286 = 5
MST_CLK_296 = 4
MST_CLK_308 = 3
MST_CLK_320 = 2
MST_CLK_333 = 1
MST_CLK_348 = 0
MST_CLK_364 = 15
MST_CLK_381 = 14
MST_CLK_400 = 13
MST_CLK_421 = 12
MST_CLK_444 = 11
MST_CLK_471 = 10
MST_CLK_500 = 9
MULT_MST_EN = 128
ON_DELAY_0 = 0
ON_DELAY_1 = 1
ON_DELAY_2 = 2
ON_DELAY_3 = 3
PASS_THROUGH = 128
PLL_EXT_19MHZ = 5
PLL_EXT_32KHZ = 4
PLL_XG = 1
PLL_YG = 2
PLL_ZG = 3
PWR_CYCLE = 32
PWR_SLEEP = 64
REG_ACCEL_CONFIG = 28
REG_ACCEL_XOUT_H = 59
REG_ACCEL_XOUT_L = 60
REG_ACCEL_YOUT_H = 61
REG_ACCEL_YOUT_L = 62
REG_ACCEL_ZOUT_H = 63
REG_ACCEL_ZOUT_L = 64
REG_CONFIG = 26
REG_EXT_SENS_DATA_00 = 73
REG_EXT_SENS_DATA_01 = 74
REG_EXT_SENS_DATA_02 = 75
REG_EXT_SENS_DATA_03 = 76
REG_EXT_SENS_DATA_04 = 77
REG_EXT_SENS_DATA_05 = 78
REG_EXT_SENS_DATA_06 = 79
REG_EXT_SENS_DATA_07 = 80
REG_EXT_SENS_DATA_08 = 81
REG_EXT_SENS_DATA_09 = 82
REG_EXT_SENS_DATA_10 = 83
REG_EXT_SENS_DATA_11 = 84
REG_EXT_SENS_DATA_12 = 85
REG_EXT_SENS_DATA_13 = 86
REG_EXT_SENS_DATA_14 = 87
REG_EXT_SENS_DATA_15 = 88
REG_EXT_SENS_DATA_16 = 89
REG_EXT_SENS_DATA_17 = 90
REG_EXT_SENS_DATA_18 = 91
REG_EXT_SENS_DATA_19 = 92
REG_EXT_SENS_DATA_20 = 93
REG_EXT_SENS_DATA_21 = 94
REG_EXT_SENS_DATA_22 = 95
REG_EXT_SENS_DATA_23 = 96
REG_FF_DUR = 30
REG_FF_THR = 29
REG_FIFO_COUNTH = 114
REG_FIFO_COUNTL = 115
REG_FIFO_EN = 35
REG_FIFO_R_W = 116
REG_GYRO_CONFIG = 27
REG_GYRO_XOUT_H = 67
REG_GYRO_XOUT_L = 68
REG_GYRO_YOUT_H = 69
REG_GYRO_YOUT_L = 70
REG_GYRO_ZOUT_H = 71
REG_GYRO_ZOUT_L = 72
REG_I2C_MST_CTRL = 36
REG_I2C_MST_DELAY_CTRL = 103
REG_I2C_MST_STATUS = 54
REG_I2C_SLV0_ADDR = 37
REG_I2C_SLV0_CTRL = 39
REG_I2C_SLV0_DO = 99
REG_I2C_SLV0_REG = 38
REG_I2C_SLV1_ADDR = 40
REG_I2C_SLV1_CTRL = 42
REG_I2C_SLV1_DO = 100
REG_I2C_SLV1_REG = 41
REG_I2C_SLV2_ADDR = 43
REG_I2C_SLV2_CTRL = 45
REG_I2C_SLV2_DO = 101
REG_I2C_SLV2_REG = 44
REG_I2C_SLV3_ADDR = 46
REG_I2C_SLV3_CTRL = 48
REG_I2C_SLV3_DO = 102
REG_I2C_SLV3_REG = 47
REG_I2C_SLV4_ADDR = 49
REG_I2C_SLV4_CTRL = 52
REG_I2C_SLV4_DI = 53
REG_I2C_SLV4_DO = 51
REG_I2C_SLV4_REG = 50
REG_INT_ENABLE = 56
REG_INT_PIN_CFG = 55
REG_INT_STATUS = 58
REG_MOT_DETECT_CTRL = 105
REG_MOT_DETECT_STATUS = 97
REG_MOT_DUR = 32
REG_MOT_THR = 31
REG_PWR_MGMT_1 = 107
REG_PWR_MGMT_2 = 108
REG_SELF_TEST_A = 16
REG_SELF_TEST_X = 13
REG_SELF_TEST_Y = 14
REG_SELF_TEST_Z = 15
REG_SIGNAL_PATH_RESET = 104
REG_SMPLRT_DIV = 25
REG_TEMP_OUT_H = 65
REG_TEMP_OUT_L = 66
REG_USER_CTRL = 106
REG_WHO_AM_I = 117
REG_ZRMOT_DUR = 34
REG_ZRMOT_THR = 33
SIG_COND_RESET = 1
SLV0_FIFO_EN = 1
SLV1_FIFO_EN = 2
SLV2_FIFO_EN = 4
SLV_3_FIFO_EN = 32
STBY_XA = 32
STBY_XG = 4
STBY_YA = 16
STBY_YG = 2
STBY_ZA = 8
STBY_ZG = 1
TEMP_DIS = 8
TEMP_FIFO_EN = 128
TEMP_RESET = 1
WAIT_FOR_ES = 64
XA_ST = 128
XG_FIFO_EN = 64
XG_ST = 128
YA_ST = 64
YG_FIFO_EN = 32
YG_ST = 64
ZA_ST = 32
ZG_FIFO_EN = 16
ZG_ST = 32
ZMOT_EN = 32
ZMOT_INT = 32
enableI2CBypass(enable)[source]

bool enableI2CBypass(bool enable)

enable I2C Bypass. Enabling this feature allows devices on the MPU60X0 auxiliary I2C bus to be visible on the MCU’s I2C bus.

enable: true to I2C bypass

true if successful, false otherwise

enableTemperatureSensor(enable)[source]

bool enableTemperatureSensor(bool enable)

enable onboard temperature measurement sensor

enable: true to enable temperature sensor, false to disable

true if successful, false otherwise

getAccelerometer(x, y, z)[source]

void getAccelerometer(float *x, float *y, float *z)

get the accelerometer values

x: the returned x value, if arg is non-NULL

y: the returned y value, if arg is non-NULL

z: the returned z value, if arg is non-NULL

true if successful, false otherwise

getGyroscope(x, y, z)[source]

void getGyroscope(float *x, float *y, float *z)

get the gyroscope values

x: the returned x value, if arg is non-NULL

y: the returned y value, if arg is non-NULL

z: the returned z value, if arg is non-NULL

true if successful, false otherwise

getInterruptEnables()[source]

uint8_t getInterruptEnables()

get the current interrupt enables register

bitmask of INT_ENABLE_BITS_T values

getInterruptPinConfig()[source]

uint8_t getInterruptPinConfig()

get the current interrupt pin configuration

bitmask of INT_PIN_CFG_BITS_T values

getInterruptStatus()[source]

uint8_t getInterruptStatus()

return the interrupt status register.

the interrupt status word (see INT_STATUS_BITS_T)

getSampleRateDivider()[source]

uint8_t getSampleRateDivider()

get the current Sample Rate divider

the current sample rate divider

getTemperature()[source]

float getTemperature()

get the temperature value

the temperature value in degrees Celsius

get_gpioIRQ()[source]

mraa::Gpio * get_gpioIRQ()

init()[source]

bool init()

set up initial values and start operation

true if successful

installISR(gpio, level, isr, arg)[source]

void installISR(int gpio, mraa::Edge level, void(*isr)(void *), void *arg)

install an interrupt handler.

gpio: gpio pin to use as interrupt pin

level: the interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin ( setInterruptPinConfig()) properly for whatever level you choose.

isr: the interrupt handler, accepting a void * argument

arg: the argument to pass the the interrupt handler

readReg(reg)[source]

uint8_t readReg(uint8_t reg)

read a register

reg: the register to read

the value of the register

readRegs(reg, buffer, len)[source]

void readRegs(uint8_t reg, uint8_t *buffer, int len)

read contiguous refister into a buffer

reg: the register to start reading at

buffer: the buffer to store the results

len: the number of registers to read

the value of the register

setAccelerometerScale(scale)[source]

bool setAccelerometerScale(AFS_SEL_T scale)

set the scaling mode of the accelerometer

scale: one of the AFS_SEL_T values

true if successful, false otherwise

setClockSource(clk)[source]

bool setClockSource(CLKSEL_T clk)

specify the clock source for the device to use

clk: one of the CLKSEL_T values

true if successful, false otherwise

setDigitalLowPassFilter(dlp)[source]

bool setDigitalLowPassFilter(DLPF_CFG_T dlp)

set the Low Pass Digital filter. This enables filtering (if non-0) of the accelerometer and gyro outputs.

dlp: one of the DLPF_CFG_T values

true if successful, false otherwise

setExternalSync(val)[source]

bool setExternalSync(EXT_SYNC_SET_T val)

configure external sync. An external signal connected to the FSYNC pin can be sampled by configuring EXT_SYNC_SET. Signal changes to the FSYNC pin are latched so that short strobes may be captured. The latched FSYNC signal will be sampled at the Sampling Rate, as defined in register 25. After sampling, the latch will reset to the current FSYNC signal state.

The sampled value will be reported in place of the least significant bit in a sensor data register determined by the value of EXT_SYNC_SET

val: one of the EXT_SYNC_SET_T values

true if successful, false otherwise

setGyroscopeScale(scale)[source]

bool setGyroscopeScale(FS_SEL_T scale)

set the scaling mode of the gyroscope

scale: one of the FS_SEL_T values

true if successful, false otherwise

setInterruptEnables(enables)[source]

bool setInterruptEnables(uint8_t enables)

set the interrupt enables

enables: bitmask of INT_ENABLE_BITS_T values to enable

true if successful, false otherwise

setInterruptPinConfig(cfg)[source]

bool setInterruptPinConfig(uint8_t cfg)

set the interrupt pin configuration

cfg: bitmask of INT_PIN_CFG_BITS_T values

true if successful, false otherwise

setMotionDetectionThreshold(thr)[source]

bool setMotionDetectionThreshold(uint8_t thr)

set the motion detection threshold for interrupt generation. Motion is detected when the absolute value of any of the accelerometer measurements exceeds this Motion detection threshold.

thr: threshold

true if successful, false otherwise

setSampleRateDivider(div)[source]

bool setSampleRateDivider(uint8_t div)

set the sample rate divider. This register specifies the divider from the gyro output rate used to generate the Sample Rate. The sensor registor output, FIFO output, DMP sampling and motion detection are all based on the Sample Rate.

The Sample Rate is generated by dividing the gyro output rate by this register:

Sample Rate = Gyro output rate / (1 + sample rate divider).

The Gyro output rate is 8Khz when the Digital Low Pass Filter (DLPF) is 0 or 7 (DLPF_260_256 or DLPF_RESERVED), and 1Khz otherwise.

div: one of the DLPF_CFG_T values

true if successful, false otherwise

setSleep(enable)[source]

bool setSleep(bool enable)

enable or disable device sleep

enable: true to put device to sleep, false to wake up

true if successful, false otherwise

uninstallISR()[source]

void uninstallISR()

uninstall a previously installed interrupt handler

update()[source]

void update()

take a measurement and store the current sensor values internally. Note, these user facing registers are only updated from the internal device sensor values when the i2c serial traffic is ‘idle’. So, if you are reading the values too fast, the bus may never be idle, and you will just end up reading the same values over and over.

Unfortunately, it is is not clear how long ‘idle’ actually means, so if you see this behavior, reduce the rate at which you are calling update().

writeReg(reg, val)[source]

bool writeReg(uint8_t reg, uint8_t val)

write to a register

reg: the register to write to

val: the value to write

true if successful, false otherwise

class pyupm_mpu9150.MPU9150(bus=0, address=104, magAddress=12, enableAk8975=True)[source]

Bases: pyupm_mpu9150.MPU60X0

API for MPU9150 chip (Accelerometer, Gyro and Magnetometer Sensor)

ID: mpu9150

Name: Inertial Measurement Unit

Other Names: Grove IMU 9DOF

Category: accelerometer compass

Manufacturer: seeed

Link:http://www.seeedstudio.com/wiki/Grove_-_IMU_9DOF_v1.0

Connection: i2c gpio This module defines the MPU9150 interface for libmpu9150

C++ includes: mpu9150.hpp

getMagnetometer(*args)[source]

std::vector< float > getMagnetometer()

Return the compensated values for the x, y, and z axes. The unit of measurement is in micro-teslas (uT).

std::vector containing X, Y, Z magnetometer values

init()[source]

bool init()

Set up initial values and start operation

true if successful

update()[source]

void update()

Take a measurement and store the current sensor values internally. Note, these user facing registers are only updated from the internal device sensor values when the i2c serial traffic is ‘idle’. So, if you are reading the values too fast, the bus may never be idle, and you will just end up reading the same values over and over.

Unfortunately, it is is not clear how long ‘idle’ actually means, so if you see this behavior, reduce the rate at which you are calling update().

class pyupm_mpu9150.MPU9250(bus=0, address=104, magAddress=12, enableAk8975=True)[source]

Bases: pyupm_mpu9150.MPU9150

API for MPU9250 chip (Accelerometer, Gyro and Magnetometer Sensor)

ID: mpu9250

Name: Inertial Measurement Unit

Other Names: Grove IMU 9DOF V2

Category: accelerometer compass

Manufacturer: seeed

Link:http://www.seeedstudio.com/wiki/Grove_-_IMU_9DOF_v2.0

Connection: i2c gpio This module defines the MPU9250 interface for libmpu9150

C++ includes: mpu9250.hpp

getTemperature()[source]

float getTemperature()

get the temperature value

the temperature value in degrees Celsius

class pyupm_mpu9150.SwigPyIterator(*args, **kwargs)[source]

Bases: object

advance(n)[source]
copy()[source]
decr(n=1)[source]
distance(x)[source]
equal(x)[source]
incr(n=1)[source]
next()[source]
previous()[source]
value()[source]