upm
0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
|
API for the MPU60X0 3-axis Gyroscope and 3-axis Accelerometer. More...
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.
Public Member Functions | |
synchronized void | delete () |
MPU60X0 (int bus, short address) | |
MPU60X0 (int bus) | |
boolean | init () |
void | update () |
short | readReg (short reg) |
void | readRegs (short reg, byte[] buffer) |
boolean | writeReg (short reg, short val) |
boolean | setSleep (boolean enable) |
boolean | setClockSource (MPU60X0.CLKSEL_T clk) |
boolean | setGyroscopeScale (MPU60X0.FS_SEL_T scale) |
boolean | setAccelerometerScale (MPU60X0.AFS_SEL_T scale) |
boolean | setDigitalLowPassFilter (MPU60X0.DLPF_CFG_T dlp) |
boolean | setSampleRateDivider (short div) |
short | getSampleRateDivider () |
float[] | getAccelerometer () |
float[] | getGyroscope () |
float | getTemperature () |
boolean | enableTemperatureSensor (boolean enable) |
boolean | setExternalSync (MPU60X0.EXT_SYNC_SET_T val) |
boolean | enableI2CBypass (boolean enable) |
boolean | setMotionDetectionThreshold (short thr) |
short | getInterruptStatus () |
boolean | setInterruptEnables (short enables) |
short | getInterruptEnables () |
boolean | setInterruptPinConfig (short cfg) |
short | getInterruptPinConfig () |
void | installISR (int gpio, int level, IsrCallback cb) |
void | uninstallISR () |
MPU60X0 | ( | int | bus, |
short | address | ||
) |
mpu60x0 constructor
bus | i2c bus to use |
address | the address for this device |
boolean enableI2CBypass | ( | boolean | enable | ) |
enable I2C Bypass. Enabling this feature allows devices on the MPU60X0 auxillary I2C bus to be visible on the MCU's I2C bus.
enable | true to I2C bypass |
boolean enableTemperatureSensor | ( | boolean | enable | ) |
enable onboard temperature measurement sensor
enable | true to enable temperature sensor, false to disable |
float [] getAccelerometer | ( | ) |
get the accelerometer values
float [] getGyroscope | ( | ) |
get the gyroscope values
short getInterruptEnables | ( | ) |
get the current interrupt enables register
short getInterruptPinConfig | ( | ) |
get the current interrupt pin configuration
short getInterruptStatus | ( | ) |
return the interrupt status register.
short getSampleRateDivider | ( | ) |
get the current Sample Rate divider
float getTemperature | ( | ) |
get the temperature value
boolean init | ( | ) |
set up initial values and start operation
void installISR | ( | int | gpio, |
int | level, | ||
IsrCallback | cb | ||
) |
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 |
short readReg | ( | short | reg | ) |
read a register
reg | the register to read |
boolean setAccelerometerScale | ( | MPU60X0.AFS_SEL_T | scale | ) |
set the scaling mode of the accelerometer
scale | one of the AFS_SEL_T values |
boolean setClockSource | ( | MPU60X0.CLKSEL_T | clk | ) |
specify the clock source for the device to use
clk | one of the CLKSEL_T values |
boolean setDigitalLowPassFilter | ( | MPU60X0.DLPF_CFG_T | dlp | ) |
set the Low Pass Digital filter. This enables filtering (if non-0) of the accelerometer and gyro outputs.
scale | one of the DLPF_CFG_T values |
boolean setExternalSync | ( | MPU60X0.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 |
boolean setGyroscopeScale | ( | MPU60X0.FS_SEL_T | scale | ) |
set the scaling mode of the gyroscope
scale | one of the FS_SEL_T values |
boolean setInterruptEnables | ( | short | enables | ) |
set the interrupt enables
enables | bitmask of INT_ENABLE_BITS_T values to enable |
boolean setInterruptPinConfig | ( | short | cfg | ) |
set the interrupt pin configuration
cfg | bitmask of INT_PIN_CFG_BITS_T values |
boolean setMotionDetectionThreshold | ( | short | 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 |
boolean setSampleRateDivider | ( | short | 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.
scale | one of the DLPF_CFG_T values |
boolean setSleep | ( | boolean | enable | ) |
enable or disable device sleep
enable | true to put device to sleep, false to wake up |
void uninstallISR | ( | ) |
uninstall a previously installed interrupt handler
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().
boolean writeReg | ( | short | reg, |
short | val | ||
) |
write to a register
reg | the register to write to |
val | the value to write |