mpu9250

package
v3.6.8+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mpu9250 MPU-9250 is a 9-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer and a Digital Motion Processor™ (DMP)

Datasheet

https://www.invensense.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf https://www.invensense.com/wp-content/uploads/2015/02/MPU-9250-Register-Map.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccelerometerData

type AccelerometerData struct {
	X, Y, Z int16
}

AccelerometerData the values for x/y/z axises.

type DebugF

type DebugF func(string, ...interface{})

DebugF the debug function type.

type Deviation

type Deviation struct {
	X, Y, Z float64
}

Deviation defines the standard deviation for major axises.

type GyroscopeData

type GyroscopeData struct {
	X, Y, Z int16
}

GyroscopeData the values for x/y/z axises.

type MPU9250

type MPU9250 struct {
	// contains filtered or unexported fields
}

MPU9250 defines the structure to keep reference to the transport.

func New

func New(transport Proto) (*MPU9250, error)

New creates the new instance of the driver.

transport the transport interface.

func (*MPU9250) AccelerometerXIsEnabled

func (m *MPU9250) AccelerometerXIsEnabled() (bool, error)

AccelerometerXIsEnabled gets the X accelerometer status.

func (*MPU9250) AccelerometerYIsEnabled

func (m *MPU9250) AccelerometerYIsEnabled() (bool, error)

AccelerometerYIsEnabled gets the X accelerometer status.

func (*MPU9250) AccelerometerZIsEnabled

func (m *MPU9250) AccelerometerZIsEnabled() (bool, error)

AccelerometerZIsEnabled gets the Z accelerometer status.

func (*MPU9250) Calibrate

func (m *MPU9250) Calibrate() error

Calibrate calibrates the device using maximum precision for both Gyroscope and Accelerometer.

func (*MPU9250) Debug

func (m *MPU9250) Debug(f DebugF)

Debug sets the debug logger implementation.

func (*MPU9250) DisableAccelerometerAxis

func (m *MPU9250) DisableAccelerometerAxis(axis byte) error

DisableAccelerometerAxis disables an accelerometer axis.

axis is one of MPU9250_DISABLE_XA_MASK, MPU9250_DISABLE_YA_MASK, MPU9250_DISABLE_ZA_MASK.

func (*MPU9250) DisableGyro

func (m *MPU9250) DisableGyro() error

DisableGyro disables the gyroscope.

func (*MPU9250) DisableTemperature

func (m *MPU9250) DisableTemperature() error

DisableTemperature disables the internal temperature sensor.

func (*MPU9250) EnableAccelerometer

func (m *MPU9250) EnableAccelerometer() error

EnableAccelerometer enables the accelerometer.

func (*MPU9250) EnableAccelerometerAxis

func (m *MPU9250) EnableAccelerometerAxis(axis byte) error

EnableAccelerometerAxis enables an accelerometer axis.

axis is one of MPU9250_DISABLE_XA_MASK, MPU9250_DISABLE_YA_MASK, MPU9250_DISABLE_ZA_MASK.

func (*MPU9250) EnableGyro

func (m *MPU9250) EnableGyro() error

EnableGyro enables the gyroscope.

func (*MPU9250) EnableTemperature

func (m *MPU9250) EnableTemperature() error

EnableTemperature enables internal temperature sensor.

func (*MPU9250) GetAccelFIFOEnabled

func (m *MPU9250) GetAccelFIFOEnabled() (bool, error)

GetAccelFIFOEnabled gets accelerometer FIFO enabled value.

func (*MPU9250) GetAccelRange

func (m *MPU9250) GetAccelRange() (byte, error)

GetAccelRange gets the full-scale accelerometer range.

func (*MPU9250) GetAcceleration

func (m *MPU9250) GetAcceleration() (*AccelerometerData, error)

GetAcceleration reads the 3-axis accelerometer.

These registers store the most recent accelerometer measurements. Accelerometer measurements are written to these registers at the Sample Rate as defined in Register 25.

The accelerometer measurement registers, along with the temperature measurement registers, gyroscope measurement registers, and external sensor data registers, are composed of two sets of registers: an internal register set and a user-facing read register set.

The data within the accelerometer sensors' internal register set is always updated at the Sample Rate. Meanwhile, the user-facing read register set duplicates the internal register set's data values whenever the serial interface is idle. This guarantees that a burst read of sensor registers will read measurements from the same sampling instant. Note that if burst reads are not used, the user is responsible for ensuring a set of single byte reads correspond to a single sampling instant by checking the Data Ready interrupt.

Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS (Register 28). For each full scale setting, the accelerometers' sensitivity per LSB in ACCEL_xOUT is shown in the table below:

AFS_SEL | Full Scale Range | LSB Sensitivity
--------+------------------+----------------
0       | +/- 2g           | 8192 LSB/mg
1       | +/- 4g           | 4096 LSB/mg
2       | +/- 8g           | 2048 LSB/mg
3       | +/- 16g          | 1024 LSB/mg

func (*MPU9250) GetAccelerationX

func (m *MPU9250) GetAccelerationX() (int16, error)

GetAccelerationX reads the X-axis accelerometer.

func (*MPU9250) GetAccelerationY

func (m *MPU9250) GetAccelerationY() (int16, error)

GetAccelerationY reads the Y-axis accelerometer.

func (*MPU9250) GetAccelerationZ

func (m *MPU9250) GetAccelerationZ() (int16, error)

GetAccelerationZ reads the Z-axis accelerometer.

func (*MPU9250) GetAccelerometerTestData

func (m *MPU9250) GetAccelerometerTestData() (*AccelerometerData, error)

GetAccelerometerTestData gets the self-test data values from the registers.

func (*MPU9250) GetClockSource

func (m *MPU9250) GetClockSource() (byte, error)

GetClockSource gets the clock source setting.

func (*MPU9250) GetDeviceID

func (m *MPU9250) GetDeviceID() (byte, error)

GetDeviceID returns the device ID.

func (*MPU9250) GetFIFOByte

func (m *MPU9250) GetFIFOByte() (byte, error)

GetFIFOByte Get byte from FIFO buffer.

This register is used to read and write data from the FIFO buffer. Data is written to the FIFO in order of register number (from lowest to highest). If all the FIFO enable flags (see below) are enabled and all External Sensor Data registers (Registers 73 to 96) are associated with a Slave device, the contents of registers 59 through 96 will be written in order at the Sample Rate.

The contents of the sensor data registers (Registers 59 to 96) are written into the FIFO buffer when their corresponding FIFO enable flags are set to 1 in FIFO_EN (Register 35). An additional flag for the sensor data registers associated with I2C Slave 3 can be found in I2C_MST_CTRL (Register 36).

If the FIFO buffer has overflowed, the status bit FIFO_OFLOW_INT is automatically set to 1. This bit is located in INT_STATUS (Register 58). When the FIFO buffer has overflowed, the oldest data will be lost and new data will be written to the FIFO.

If the FIFO buffer is empty, reading this register will return the last byte that was previously read from the FIFO until new data is available. The user should check FIFO_COUNT to ensure that the FIFO buffer is not read when empty.

func (*MPU9250) GetFIFOCount

func (m *MPU9250) GetFIFOCount() (uint16, error)

GetFIFOCount gets the current FIFO buffer size.

This value indicates the number of bytes stored in the FIFO buffer. This number is in turn the number of bytes that can be read from the FIFO buffer and it is directly proportional to the number of samples available given the set of sensor data bound to be stored in the FIFO (register 35 and 36).

func (*MPU9250) GetFIFOEnabled

func (m *MPU9250) GetFIFOEnabled() (bool, error)

GetFIFOEnabled gets the FIFO enabled status.

func (*MPU9250) GetFSyncInterruptEnabled

func (m *MPU9250) GetFSyncInterruptEnabled() (bool, error)

GetFSyncInterruptEnabled gets the FSYNC pin interrupt enabled setting.

func (*MPU9250) GetFSyncInterruptLevel

func (m *MPU9250) GetFSyncInterruptLevel() (bool, error)

GetFSyncInterruptLevel gets the FSYNC interrupt logic level mode.

func (*MPU9250) GetGyroRange

func (m *MPU9250) GetGyroRange() (byte, error)

GetGyroRange gets the gyroscope range.

func (*MPU9250) GetGyroTestData

func (m *MPU9250) GetGyroTestData() (*GyroscopeData, error)

GetGyroTestData gets the test data from self-test registers, factory settings.

func (*MPU9250) GetI2CBypassEnabled

func (m *MPU9250) GetI2CBypassEnabled() (bool, error)

GetI2CBypassEnabled gets the I2C bypass enabled status.

func (*MPU9250) GetI2CMasterModeEnabled

func (m *MPU9250) GetI2CMasterModeEnabled() (bool, error)

GetI2CMasterModeEnabled gets the I2C Master Mode enabled status.

func (*MPU9250) GetIntEnabled

func (m *MPU9250) GetIntEnabled() (byte, error)

GetIntEnabled gets the full interrupt enabled status.

func (*MPU9250) GetIntFIFOBufferOverflowEnabled

func (m *MPU9250) GetIntFIFOBufferOverflowEnabled() (bool, error)

GetIntFIFOBufferOverflowEnabled gets the FIFO Buffer Overflow interrupt enabled status.

func (*MPU9250) GetIntI2CMasterEnabled

func (m *MPU9250) GetIntI2CMasterEnabled() (bool, error)

GetIntI2CMasterEnabled gets the I2C Master interrupt enabled status.

func (*MPU9250) GetIntStatus

func (m *MPU9250) GetIntStatus() (byte, error)

GetIntStatus get the full set of interrupt status bits.

These bits clear to 0 after the register has been read. Very useful for getting multiple INT statuses, since each single bit read clears all of them because it has to read the whole byte.

func (*MPU9250) GetInterruptDrive

func (m *MPU9250) GetInterruptDrive() (bool, error)

GetInterruptDrive gets interrupt drive mode.

Will be set false for push-pull, true for open-drain.

func (*MPU9250) GetInterruptLatch

func (m *MPU9250) GetInterruptLatch() (bool, error)

GetInterruptLatch gets interrupt latch mode.

Is false for 50us-pulse, true for latch-until-int-cleared.

func (*MPU9250) GetInterruptLatchClear

func (m *MPU9250) GetInterruptLatchClear() (bool, error)

GetInterruptLatchClear gets the interrupt latch clear mode.

Is false for status-read-only, true for any-register-read.

func (*MPU9250) GetInterruptMode

func (m *MPU9250) GetInterruptMode() (bool, error)

GetInterruptMode gets interrupt logic level mode.

Is false for active-high, true for active-low.

func (*MPU9250) GetLostArbitration

func (m *MPU9250) GetLostArbitration() (bool, error)

GetLostArbitration gets master arbitration lost status.

This bit automatically sets to 1 when the I2C Master has lost arbitration of the auxiliary I2C bus (an error condition). This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.

func (*MPU9250) GetMasterClockSpeed

func (m *MPU9250) GetMasterClockSpeed() (byte, error)

GetMasterClockSpeed gets I2C master clock speed.

func (*MPU9250) GetMotion6

func (m *MPU9250) GetMotion6() (*AccelerometerData, *RotationData, error)

GetMotion6 gets the motion data - accelerometer and rotation(gyroscope).

func (*MPU9250) GetMultiMasterEnabled

func (m *MPU9250) GetMultiMasterEnabled() (bool, error)

GetMultiMasterEnabled gets multi-master enabled value.

func (*MPU9250) GetPassthroughStatus

func (m *MPU9250) GetPassthroughStatus() (bool, error)

GetPassthroughStatus gets FSYNC interrupt status.

This bit reflects the status of the FSYNC interrupt from an external device into the MPU-60X0. This is used as a way to pass an external interrupt through the MPU-60X0 to the host application processor. When set to 1, this bit will cause an interrupt if FSYNC_INT_EN is asserted in INT_PIN_CFG (Register 55).

func (*MPU9250) GetRotation

func (m *MPU9250) GetRotation() (*RotationData, error)

GetRotation reads the 3-axis gyroscope.

These gyroscope measurement registers, along with the accelerometer measurement registers, temperature measurement registers, and external sensor data registers, are composed of two sets of registers: an internal register set and a user-facing read register set. The data within the gyroscope sensors' internal register set is always updated at the Sample Rate. Meanwhile, the user-facing read register set duplicates the internal register set's data values whenever the serial interface is idle. This guarantees that a burst read of sensor registers will read measurements from the same sampling instant. Note that if burst reads are not used, the user is responsible for ensuring a set of single byte reads correspond to a single sampling instant by checking the Data Ready interrupt.

Each 16-bit gyroscope measurement has a full scale defined in FS_SEL (Register 27). For each full scale setting, the gyroscopes' sensitivity per LSB in GYRO_xOUT is shown in the table below:

FS_SEL | Full Scale Range   | LSB Sensitivity
-------+--------------------+----------------
0      | +/- 250 degrees/s  | 131 LSB/deg/s
1      | +/- 500 degrees/s  | 65.5 LSB/deg/s
2      | +/- 1000 degrees/s | 32.8 LSB/deg/s
3      | +/- 2000 degrees/s | 16.4 LSB/deg/s

func (*MPU9250) GetRotationX

func (m *MPU9250) GetRotationX() (int16, error)

GetRotationX gets X-axis gyroscope reading.

func (*MPU9250) GetRotationY

func (m *MPU9250) GetRotationY() (int16, error)

GetRotationY gets Y-axis gyroscope reading.

func (*MPU9250) GetRotationZ

func (m *MPU9250) GetRotationZ() (int16, error)

GetRotationZ gets Z-axis gyroscope reading.

func (*MPU9250) GetSlave0FIFOEnabled

func (m *MPU9250) GetSlave0FIFOEnabled() (bool, error)

GetSlave0FIFOEnabled gets Slave 0 FIFO enabled value.

func (*MPU9250) GetSlave0Nack

func (m *MPU9250) GetSlave0Nack() (bool, error)

GetSlave0Nack gets Slave 0 NACK status.

This bit automatically sets to 1 when the I2C Master receives a NACK in a transaction with Slave 0. This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.

func (*MPU9250) GetSlave1FIFOEnabled

func (m *MPU9250) GetSlave1FIFOEnabled() (bool, error)

GetSlave1FIFOEnabled gets Slave 1 FIFO enabled value.

func (*MPU9250) GetSlave1Nack

func (m *MPU9250) GetSlave1Nack() (bool, error)

GetSlave1Nack gets Slave 1 NACK status.

This bit automatically sets to 1 when the I2C Master receives a NACK in a transaction with Slave 1. This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.

func (*MPU9250) GetSlave2FIFOEnabled

func (m *MPU9250) GetSlave2FIFOEnabled() (bool, error)

GetSlave2FIFOEnabled gets Slave 2 FIFO enabled value.

func (*MPU9250) GetSlave2Nack

func (m *MPU9250) GetSlave2Nack() (bool, error)

GetSlave2Nack gets Slave 2 NACK status.

This bit automatically sets to 1 when the I2C Master receives a NACK in a transaction with Slave 2. This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.

func (*MPU9250) GetSlave3FIFOEnabled

func (m *MPU9250) GetSlave3FIFOEnabled() (bool, error)

GetSlave3FIFOEnabled gets Slave 3 FIFO enabled value.

func (*MPU9250) GetSlave3Nack

func (m *MPU9250) GetSlave3Nack() (bool, error)

GetSlave3Nack gets Slave 3 NACK status.

This bit automatically sets to 1 when the I2C Master receives a NACK in a transaction with Slave 3. This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.

func (*MPU9250) GetSlave4Address

func (m *MPU9250) GetSlave4Address() (byte, error)

GetSlave4Address gets the I2C address of Slave 4.

func (*MPU9250) GetSlave4Enabled

func (m *MPU9250) GetSlave4Enabled() (bool, error)

GetSlave4Enabled gets the enabled value for the Slave 4.

func (*MPU9250) GetSlave4InputByte

func (m *MPU9250) GetSlave4InputByte() (byte, error)

GetSlave4InputByte gets last available byte read from Slave 4.

This register stores the data read from Slave 4. This field is populated after a read transaction.

func (*MPU9250) GetSlave4InterruptEnabled

func (m *MPU9250) GetSlave4InterruptEnabled() (bool, error)

GetSlave4InterruptEnabled gets the enabled value for Slave 4 transaction interrupts.

func (*MPU9250) GetSlave4IsDone

func (m *MPU9250) GetSlave4IsDone() (bool, error)

GetSlave4IsDone gets Slave 4 transaction done status.

Automatically sets to 1 when a Slave 4 transaction has completed. This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted and if the SLV_4_DONE_INT bit is asserted in the I2C_SLV4_CTRL register (Register 52).

func (*MPU9250) GetSlave4MasterDelay

func (m *MPU9250) GetSlave4MasterDelay() (byte, error)

GetSlave4MasterDelay gets Slave 4 master delay value.

func (*MPU9250) GetSlave4Nack

func (m *MPU9250) GetSlave4Nack() (bool, error)

GetSlave4Nack gets Slave 4 NACK status.

This bit automatically sets to 1 when the I2C Master receives a NACK in a transaction with Slave 4. This triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.

func (*MPU9250) GetSlave4Register

func (m *MPU9250) GetSlave4Register() (byte, error)

GetSlave4Register gets the active internal register for the Slave 4.

func (*MPU9250) GetSlave4WriteMode

func (m *MPU9250) GetSlave4WriteMode() (bool, error)

GetSlave4WriteMode gets write mode for Slave 4.

func (*MPU9250) GetSlaveAddress

func (m *MPU9250) GetSlaveAddress(num byte) (byte, error)

GetSlaveAddress gets the I2C address of the specified slave (0-3).

func (*MPU9250) GetSlaveDataLength

func (m *MPU9250) GetSlaveDataLength(num byte) (byte, error)

GetSlaveDataLength gets number of bytes to read for the specified slave (0-3).

func (*MPU9250) GetSlaveEnabled

func (m *MPU9250) GetSlaveEnabled(num byte) (bool, error)

GetSlaveEnabled gets the enabled value for the specified slave (0-3).

func (*MPU9250) GetSlaveReadWriteTransitionEnabled

func (m *MPU9250) GetSlaveReadWriteTransitionEnabled() (bool, error)

GetSlaveReadWriteTransitionEnabled gets slave read/write transition enabled value.

func (*MPU9250) GetSlaveRegister

func (m *MPU9250) GetSlaveRegister(num byte) (byte, error)

GetSlaveRegister gets the active internal register for the specified slave (0-3).

func (*MPU9250) GetSlaveWordByteSwap

func (m *MPU9250) GetSlaveWordByteSwap(num byte) (bool, error)

GetSlaveWordByteSwap gets the word pair byte-swapping enabled for the specified slave (0-3).

func (*MPU9250) GetSlaveWordGroupOffset

func (m *MPU9250) GetSlaveWordGroupOffset(num byte) (bool, error)

GetSlaveWordGroupOffset gets word pair grouping order offset for the specified slave (0-3).

func (*MPU9250) GetSlaveWriteMode

func (m *MPU9250) GetSlaveWriteMode(num byte) (bool, error)

GetSlaveWriteMode gets write mode for the specified slave (0-3).

func (*MPU9250) GetSleepEnabled

func (m *MPU9250) GetSleepEnabled() (bool, error)

GetSleepEnabled gets the sleep mode status.

func (*MPU9250) GetTempFIFOEnabled

func (m *MPU9250) GetTempFIFOEnabled() (bool, error)

GetTempFIFOEnabled gets the temperature FIFO enabled value.

func (*MPU9250) GetTemperature

func (m *MPU9250) GetTemperature() (uint16, error)

GetTemperature gets the current temperature.

func (*MPU9250) GetWaitForExternalSensorEnabled

func (m *MPU9250) GetWaitForExternalSensorEnabled() (bool, error)

GetWaitForExternalSensorEnabled gets wait-for-external-sensor-data enabled value.

func (*MPU9250) GetWakeCycleEnabled

func (m *MPU9250) GetWakeCycleEnabled() (bool, error)

GetWakeCycleEnabled gets the wake cycle enabled status.

func (*MPU9250) GetXGyroFIFOEnabled

func (m *MPU9250) GetXGyroFIFOEnabled() (bool, error)

GetXGyroFIFOEnabled gets the gyroscope X-axis FIFO enabled value.

func (*MPU9250) GetXGyroOffset

func (m *MPU9250) GetXGyroOffset() (uint16, error)

GetXGyroOffset returns the offset of X gyroscope.

func (*MPU9250) GetYGyroFIFOEnabled

func (m *MPU9250) GetYGyroFIFOEnabled() (bool, error)

GetYGyroFIFOEnabled gets the gyroscope Y-axis FIFO enabled value.

func (*MPU9250) GetYGyroOffset

func (m *MPU9250) GetYGyroOffset() (uint16, error)

GetYGyroOffset returns the offset of y gyroscope.

func (*MPU9250) GetZGyroFIFOEnabled

func (m *MPU9250) GetZGyroFIFOEnabled() (bool, error)

GetZGyroFIFOEnabled gets the gyroscope Z-axis FIFO enabled value.

func (*MPU9250) GetZGyroOffset

func (m *MPU9250) GetZGyroOffset() (uint16, error)

GetZGyroOffset returns the offset of Z gyroscope.

func (*MPU9250) GyroXIsEnabled

func (m *MPU9250) GyroXIsEnabled() (bool, error)

GyroXIsEnabled gets the X axis enabled flag.

func (*MPU9250) GyroYIsEnabled

func (m *MPU9250) GyroYIsEnabled() (bool, error)

GyroYIsEnabled gets the Y axis enabled flag.

func (*MPU9250) GyroZIsEnabled

func (m *MPU9250) GyroZIsEnabled() (bool, error)

GyroZIsEnabled gets the Z axis enabled flag.

func (*MPU9250) Init

func (m *MPU9250) Init() error

Init initializes the device.

func (*MPU9250) ReadSignedWord

func (m *MPU9250) ReadSignedWord(hi, lo byte) (int16, error)

ReadSignedWord reads signed word from the provided high/low registers addresses.

func (*MPU9250) ReadWord

func (m *MPU9250) ReadWord(hi, lo byte) (uint16, error)

ReadWord reads unsigned int from the provided addresses.

hi high 8 bit address
lo low 8 bit address

func (*MPU9250) Reset

func (m *MPU9250) Reset() error

Reset triggers a full device reset.

A small delay of ~50ms may be desirable after triggering a reset.

func (*MPU9250) ResetAccelerometerPath

func (m *MPU9250) ResetAccelerometerPath() error

ResetAccelerometerPath resets the accelerometer signal path.

The reset will revert the signal path analog to digital converters and filters to their power up configurations.

func (*MPU9250) ResetFIFO

func (m *MPU9250) ResetFIFO() error

ResetFIFO resets the FIFO.

This bit resets the FIFO buffer when set to 1 while FIFO_EN equals 0. This bit automatically clears to 0 after the reset has been triggered.

func (*MPU9250) ResetGyroscopePath

func (m *MPU9250) ResetGyroscopePath() error

ResetGyroscopePath resets the gyroscope signal path.

The reset will revert the signal path analog to digital converters and filters to their power up configurations.

func (*MPU9250) ResetI2CMaster

func (m *MPU9250) ResetI2CMaster() error

ResetI2CMaster resets the I2C Master.

This bit resets the I2C Master when set to 1 while I2C_MST_EN equals 0. This bit automatically clears to 0 after the reset has been triggered.

func (*MPU9250) ResetSensors

func (m *MPU9250) ResetSensors() error

ResetSensors resets all sensor registers and signal paths.

When set to 1, this bit resets the signal paths for all sensors (gyroscopes, accelerometers, and temperature sensor). This operation will also clear the sensor registers. This bit automatically clears to 0 after the reset has been triggered.

When resetting only the signal path (and not the sensor registers), please use Register 104, SIGNAL_PATH_RESET.

func (*MPU9250) ResetTemperaturePath

func (m *MPU9250) ResetTemperaturePath() error

ResetTemperaturePath resets the temperature sensor signal path.

The reset will revert the signal path analog to digital converters and filters to their power up configurations.

func (*MPU9250) SelfTest

func (m *MPU9250) SelfTest() (*SelfTestResult, error)

SelfTest runs the self test on the device.

Returns the accelerator and gyroscope deviations from the factory defaults.

func (*MPU9250) SetAccelFIFOEnabled

func (m *MPU9250) SetAccelFIFOEnabled(enabled bool) error

SetAccelFIFOEnabled sets accelerometer FIFO enabled value.

When set, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H, ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L (Registers 59 to 64) to be written into the FIFO buffer.

func (*MPU9250) SetAccelRange

func (m *MPU9250) SetAccelRange(rangeVal byte) error

SetAccelRange sets the full-scale accelerometer range.

The FS_SEL parameter allows setting the full-scale range of the accelerometer sensors, as described in the table below.

0 = +/- 2g
1 = +/- 4g
2 = +/- 8g
3 = +/- 16g

func (*MPU9250) SetAccelerationOffsetX

func (m *MPU9250) SetAccelerationOffsetX(offset uint16) error

SetAccelerationOffsetX sets the acceleration trim offset for X axis.

func (*MPU9250) SetAccelerationOffsetY

func (m *MPU9250) SetAccelerationOffsetY(offset uint16) error

SetAccelerationOffsetY sets the acceleration trim offset for Y axis.

func (*MPU9250) SetAccelerationOffsetZ

func (m *MPU9250) SetAccelerationOffsetZ(offset uint16) error

SetAccelerationOffsetZ sets the acceleration trim offset for Z axis.

func (*MPU9250) SetClockSource

func (m *MPU9250) SetClockSource(src byte) error

SetClockSource sets clock source setting.

An internal 8MHz oscillator, gyroscope based clock, or external sources can be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator or an external source is chosen as the clock source, the MPU-60X0 can operate in low power modes with the gyroscopes disabled.

Upon power up, the MPU-60X0 clock source defaults to the internal oscillator. However, it is highly recommended that the device be configured to use one of the gyroscopes (or an external clock source) as the clock reference for improved stability. The clock source can be selected according to the following table:

CLK_SEL | Clock Source
--------+--------------------------------------
0       | Internal oscillator
1       | PLL with X Gyro reference
2       | PLL with Y Gyro reference
3       | PLL with Z Gyro reference
4       | PLL with external 32.768kHz reference
5       | PLL with external 19.2MHz reference
6       | Reserved
7       | Stops the clock and keeps the timing generator in reset

func (*MPU9250) SetFIFOByte

func (m *MPU9250) SetFIFOByte(data byte) error

SetFIFOByte writes byte to FIFO buffer.

func (*MPU9250) SetFIFOEnabled

func (m *MPU9250) SetFIFOEnabled(enabled bool) error

SetFIFOEnabled sets the FIFO enabled status.

When this bit is set to 0, the FIFO buffer is disabled. The FIFO buffer cannot be written to or read from while disabled. The FIFO buffer's state does not change unless the MPU-60X0 is power cycled.

func (*MPU9250) SetFSyncInterruptEnabled

func (m *MPU9250) SetFSyncInterruptEnabled(enabled bool) error

SetFSyncInterruptEnabled sets the FSYNC pin interrupt enabled setting.

func (*MPU9250) SetFSyncInterruptLevel

func (m *MPU9250) SetFSyncInterruptLevel(level bool) error

SetFSyncInterruptLevel sets the FSYNC interrupt logic level mode.

New FSYNC interrupt mode (false is active-high, true is active-low).

func (*MPU9250) SetGyroRange

func (m *MPU9250) SetGyroRange(rangeVal byte) error

SetGyroRange sets the gyroscope range.

The FS_SEL parameter allows setting the full-scale range of the gyro sensors, as described in the table below.

0 = +/- 250 degrees/sec
1 = +/- 500 degrees/sec
2 = +/- 1000 degrees/sec
3 = +/- 2000 degrees/sec

func (*MPU9250) SetI2CBypassEnabled

func (m *MPU9250) SetI2CBypassEnabled(enabled bool) error

SetI2CBypassEnabled sets the I2C bypass enabled status.

When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to 0, the host application processor will be able to directly access the auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host application processor will not be able to directly access the auxiliary I2C bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106 bit[5]).

func (*MPU9250) SetI2CMasterModeEnabled

func (m *MPU9250) SetI2CMasterModeEnabled(enabled bool) error

SetI2CMasterModeEnabled sets the I2C Master Mode enabled status.

When this mode is enabled, the MPU-60X0 acts as the I2C Master to the external sensor slave devices on the auxiliary I2C bus. When this bit is cleared to 0, the auxiliary I2C bus lines (AUX_DA and AUX_CL) are logically driven by the primary I2C bus (SDA and SCL). This is a precondition to enabling Bypass Mode. For further information regarding Bypass Mode, please refer to Register 55.

func (*MPU9250) SetIntEnabled

func (m *MPU9250) SetIntEnabled(enabled byte) error

SetIntEnabled sets the full interrupt enabled status.

Full register byte for all interrupts, for quick reading. Each bit will be set 0 for disabled, 1 for enabled.

func (*MPU9250) SetIntFIFOBufferOverflowEnabled

func (m *MPU9250) SetIntFIFOBufferOverflowEnabled(enabled bool) error

SetIntFIFOBufferOverflowEnabled sets the FIFO Buffer Overflow interrupt enabled status.

func (*MPU9250) SetIntI2CMasterEnabled

func (m *MPU9250) SetIntI2CMasterEnabled(enabled bool) error

SetIntI2CMasterEnabled sets the I2C Master interrupt enabled status.

This enables any of the I2C Master interrupt sources to generate an interrupt.

func (*MPU9250) SetInterruptDrive

func (m *MPU9250) SetInterruptDrive(drive bool) error

SetInterruptDrive sets interrupt drive mode.

New interrupt drive mode (false for push-pull, true for open-drain).

func (*MPU9250) SetInterruptLatch

func (m *MPU9250) SetInterruptLatch(latch bool) error

SetInterruptLatch sets interrupt latch mode.

New latch mode (false is 50us-pulse, true is latch-until-int-cleared).

func (*MPU9250) SetInterruptLatchClear

func (m *MPU9250) SetInterruptLatchClear(clear bool) error

SetInterruptLatchClear sets the interrupt latch clear mode.

New latch clear mode (false is status-read-only, true is any-register-read).

func (*MPU9250) SetInterruptMode

func (m *MPU9250) SetInterruptMode(mode bool) error

SetInterruptMode sets interrupt logic level mode.

Is false for active-high, true for active-low.

func (*MPU9250) SetMasterClockSpeed

func (m *MPU9250) SetMasterClockSpeed(speed byte) error

SetMasterClockSpeed sets I2C master clock speed.

I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the MPU-60X0 internal 8MHz clock. It sets the I2C master clock speed according to the following table:

I2C_MST_CLK | I2C Master Clock Speed | 8MHz Clock Divider
------------+------------------------+-------------------
0           | 348kHz                 | 23
1           | 333kHz                 | 24
2           | 320kHz                 | 25
3           | 308kHz                 | 26
4           | 296kHz                 | 27
5           | 286kHz                 | 28
6           | 276kHz                 | 29
7           | 267kHz                 | 30
8           | 258kHz                 | 31
9           | 500kHz                 | 16
10          | 471kHz                 | 17
11          | 444kHz                 | 18
12          | 421kHz                 | 19
13          | 400kHz                 | 20
14          | 381kHz                 | 21
15          | 364kHz                 | 22

func (*MPU9250) SetMultiMasterEnabled

func (m *MPU9250) SetMultiMasterEnabled(enabled bool) error

SetMultiMasterEnabled sets multi-master enabled value.

Multi-master capability allows multiple I2C masters to operate on the same bus. In circuits where multi-master capability is required, set MULT_MST_EN to 1. This will increase current drawn by approximately 30uA.

In circuits where multi-master capability is required, the state of the I2C bus must always be monitored by each separate I2C Master. Before an I2C Master can assume arbitration of the bus, it must first confirm that no other I2C Master has arbitration of the bus. When MULT_MST_EN is set to 1, the MPU-60X0's bus arbitration detection logic is turned on, enabling it to detect when the bus is available.

func (*MPU9250) SetSlave0FIFOEnabled

func (m *MPU9250) SetSlave0FIFOEnabled(enabled bool) error

SetSlave0FIFOEnabled sets Slave 0 FIFO enabled value.

When set, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 0 to be written into the FIFO buffer.

func (*MPU9250) SetSlave1FIFOEnabled

func (m *MPU9250) SetSlave1FIFOEnabled(enabled bool) error

SetSlave1FIFOEnabled sets Slave 1 FIFO enabled value.

When set, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 1 to be written into the FIFO buffer.

func (*MPU9250) SetSlave2FIFOEnabled

func (m *MPU9250) SetSlave2FIFOEnabled(enabled bool) error

SetSlave2FIFOEnabled sets Slave 2 FIFO enabled value.

When set, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 2 to be written into the FIFO buffer.

func (*MPU9250) SetSlave3FIFOEnabled

func (m *MPU9250) SetSlave3FIFOEnabled(enabled bool) error

SetSlave3FIFOEnabled sets Slave 3 FIFO enabled value.

When set, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 3 to be written into the FIFO buffer.

func (*MPU9250) SetSlave4Address

func (m *MPU9250) SetSlave4Address(address byte) error

SetSlave4Address sets the I2C address of Slave 4.

Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read operation, and if it is cleared, then it's a write operation. The remaining bits (6-0) are the 7-bit device address of the slave device.

func (*MPU9250) SetSlave4Enabled

func (m *MPU9250) SetSlave4Enabled(enabled bool) error

SetSlave4Enabled sets the enabled value for Slave 4.

When set, this bit enables Slave 4 for data transfer operations. When cleared to 0, this bit disables Slave 4 from data transfer operations.

func (*MPU9250) SetSlave4InterruptEnabled

func (m *MPU9250) SetSlave4InterruptEnabled(enabled bool) error

SetSlave4InterruptEnabled sets the enabled value for Slave 4 transaction interrupts.

When set, this bit enables the generation of an interrupt signal upon completion of a Slave 4 transaction. When cleared to 0, this bit disables the generation of an interrupt signal upon completion of a Slave 4 transaction. The interrupt status can be observed in Register 54.

func (*MPU9250) SetSlave4MasterDelay

func (m *MPU9250) SetSlave4MasterDelay(delay byte) error

SetSlave4MasterDelay sets Slave 4 master delay value.

This configures the reduced access rate of I2C slaves relative to the Sample Rate. When a slave's access rate is decreased relative to the Sample Rate, the slave is accessed every:

1 / (1 + I2C_MST_DLY) samples

This base Sample Rate in turn is determined by SMPLRT_DIV (register 25) and DLPF_CFG (register 26). Whether a slave's access rate is reduced relative to the Sample Rate is determined by I2C_MST_DELAY_CTRL (register 103). For further information regarding the Sample Rate, please refer to register 25.

func (*MPU9250) SetSlave4OutputByte

func (m *MPU9250) SetSlave4OutputByte(data byte) error

SetSlave4OutputByte sets new byte to write to Slave 4.

This register stores the data to be written into the Slave 4. If I2C_SLV4_RW is set 1 (set to read), this register has no effect.

func (*MPU9250) SetSlave4Register

func (m *MPU9250) SetSlave4Register(r byte) error

SetSlave4Register sets the active internal register for Slave 4.

Read/write operations for this slave will be done to whatever internal register address is stored in this MPU register.

func (*MPU9250) SetSlave4WriteMode

func (m *MPU9250) SetSlave4WriteMode(mode bool) error

SetSlave4WriteMode sets write mode for the Slave 4.

When set, the transaction will read or write data only. When cleared to 0, the transaction will write a register address prior to reading or writing data. This should equal 0 when specifying the register address within the Slave device to/from which the ensuing data transaction will take place.

func (*MPU9250) SetSlaveAddress

func (m *MPU9250) SetSlaveAddress(num, address byte) error

SetSlaveAddress sets the I2C address of the specified slave (0-3).

Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read operation, and if it is cleared, then it's a write operation. The remaining bits (6-0) are the 7-bit device address of the slave device.

In read mode, the result of the read is placed in the lowest available EXT_SENS_DATA register. For further information regarding the allocation of read results, please refer to the EXT_SENS_DATA register description (Registers 73 - 96).

The MPU-6050 supports a total of five slaves, but Slave 4 has unique characteristics, and so it has its own functions (getSlave4* and setSlave4*).

I2C data transactions are performed at the Sample Rate, as defined in Register 25. The user is responsible for ensuring that I2C data transactions to and from each enabled Slave can be completed within a single period of the Sample Rate.

The I2C slave access rate can be reduced relative to the Sample Rate. This reduced access rate is determined by I2C_MST_DLY (Register 52). Whether a slave's access rate is reduced relative to the Sample Rate is determined by I2C_MST_DELAY_CTRL (Register 103).

The processing order for the slaves is fixed. The sequence followed for processing the slaves is Slave 0, Slave 1, Slave 2, Slave 3 and Slave 4. If a particular Slave is disabled it will be skipped.

Each slave can either be accessed at the sample rate or at a reduced sample rate. In a case where some slaves are accessed at the Sample Rate and some slaves are accessed at the reduced rate, the sequence of accessing the slaves (Slave 0 to Slave 4) is still followed. However, the reduced rate slaves will be skipped if their access rate dictates that they should not be accessed during that particular cycle. For further information regarding the reduced access rate, please refer to Register 52. Whether a slave is accessed at the Sample Rate or at the reduced rate is determined by the Delay Enable bits in Register 103.

func (*MPU9250) SetSlaveDataLength

func (m *MPU9250) SetSlaveDataLength(num byte, length byte) error

SetSlaveDataLength sets number of bytes to read for the specified slave (0-3).

Specifies the number of bytes transferred to and from Slave 0. Clearing this bit to 0 is equivalent to disabling the register by writing 0 to I2C_SLV0_EN.

func (*MPU9250) SetSlaveEnabled

func (m *MPU9250) SetSlaveEnabled(num byte, enabled bool) error

SetSlaveEnabled sets the enabled value for the specified slave (0-3).

When set, this bit enables Slave 0 for data transfer operations. When cleared to 0, this bit disables Slave 0 from data transfer operations.

func (*MPU9250) SetSlaveReadWriteTransitionEnabled

func (m *MPU9250) SetSlaveReadWriteTransitionEnabled(enabled bool) error

SetSlaveReadWriteTransitionEnabled enables slave read/write transition.

The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave read to the next slave read. If the bit equals 0, there will be a restart between reads. If the bit equals 1, there will be a stop followed by a start of the following read. When a write transaction follows a read transaction, the stop followed by a start of the successive write will be always used.

func (*MPU9250) SetSlaveRegister

func (m *MPU9250) SetSlaveRegister(num, r byte) error

SetSlaveRegister sets the active internal register for the specified slave (0-3).

Read/write operations for this slave will be done to whatever internal register address is stored in this MPU register.

The MPU-6050 supports a total of five slaves, but Slave 4 has unique characteristics, and so it has its own functions.

func (*MPU9250) SetSlaveWordByteSwap

func (m *MPU9250) SetSlaveWordByteSwap(num byte, enabled bool) error

SetSlaveWordByteSwap sets the word pair byte-swapping enabled for the specified slave (0-3).

When set, this bit enables byte swapping. When byte swapping is enabled, the high and low bytes of a word pair are swapped. Please refer to I2C_SLV0_GRP for the pairing convention of the word pairs. When cleared to 0, bytes transferred to and from Slave 0 will be written to EXT_SENS_DATA registers in the order they were transferred.

func (*MPU9250) SetSlaveWordGroupOffset

func (m *MPU9250) SetSlaveWordGroupOffset(num byte, enabled bool) error

SetSlaveWordGroupOffset enables word pair grouping order offset for the specified slave (0-3).

This sets specifies the grouping order of word pairs received from registers. When cleared to 0, bytes from register addresses 0 and 1, 2 and 3, etc (even, then odd register addresses) are paired to form a word. When set to 1, bytes from register addresses are paired 1 and 2, 3 and 4, etc. (odd, then even register addresses) are paired to form a word.

func (*MPU9250) SetSlaveWriteMode

func (m *MPU9250) SetSlaveWriteMode(num byte, mode bool) error

SetSlaveWriteMode sets write mode for the specified slave (0-3).

When set, the transaction will read or write data only. When cleared to 0, the transaction will write a register address prior to reading or writing data. This should equal 0 when specifying the register address within the Slave device to/from which the ensuing data transaction will take place.

func (*MPU9250) SetSleepEnabled

func (m *MPU9250) SetSleepEnabled(enabled bool) error

SetSleepEnabled set sleep mode status.

Setting the SLEEP bit in the register puts the device into very low power sleep mode. In this mode, only the serial interface and internal registers remain active, allowing for a very low standby current. Clearing this bit puts the device back into normal mode. To save power, the individual standby selections for each of the gyros should be used if any gyro axis is not used by the application.

func (*MPU9250) SetTempFIFOEnabled

func (m *MPU9250) SetTempFIFOEnabled(enabled bool) error

SetTempFIFOEnabled sets the temperature FIFO enabled value.

When set, this bit enables TEMP_OUT_H and TEMP_OUT_L (Registers 65 and 66) to be written into the FIFO buffer.

func (*MPU9250) SetWaitForExternalSensorEnabled

func (m *MPU9250) SetWaitForExternalSensorEnabled(enabled bool) error

SetWaitForExternalSensorEnabled enables wait-for-external-sensor-data.

When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be delayed until External Sensor data from the Slave Devices are loaded into the EXT_SENS_DATA registers. This is used to ensure that both the internal sensor data (i.e. from gyro and accel) and external sensor data have been loaded to their respective data registers (i.e. the data is synced) when the Data Ready interrupt is triggered.

func (*MPU9250) SetWakeCycleEnabled

func (m *MPU9250) SetWakeCycleEnabled(enabled bool) error

SetWakeCycleEnabled sets the wake cycle enabled status.

When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle between sleep mode and waking up to take a single sample of data from active sensors at a rate determined by LP_WAKE_CTRL (register 108).

func (*MPU9250) SetXGyroFIFOEnabled

func (m *MPU9250) SetXGyroFIFOEnabled(enabled bool) error

SetXGyroFIFOEnabled sets the gyroscope X-axis FIFO enabled value.

When set, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and 68) to be written into the FIFO buffer.

func (*MPU9250) SetXGyroOffset

func (m *MPU9250) SetXGyroOffset(offset uint16) error

SetXGyroOffset sets the X gyroscope offset.

func (*MPU9250) SetYGyroFIFOEnabled

func (m *MPU9250) SetYGyroFIFOEnabled(enabled bool) error

SetYGyroFIFOEnabled sets the gyroscope Y-axis FIFO enabled value.

When set, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and 70) to be written into the FIFO buffer.

func (*MPU9250) SetYGyroOffset

func (m *MPU9250) SetYGyroOffset(offset uint16) error

SetYGyroOffset sets the Y gyroscope offset.

func (*MPU9250) SetZGyroFIFOEnabled

func (m *MPU9250) SetZGyroFIFOEnabled(enabled bool) error

SetZGyroFIFOEnabled sets the gyroscope Z-axis FIFO enabled value.

When set, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and 72) to be written into the FIFO buffer.

func (*MPU9250) SetZGyroOffset

func (m *MPU9250) SetZGyroOffset(offset uint16) error

SetZGyroOffset sets the Z gyroscope offset.

func (*MPU9250) SwitchSPIEnabled

func (m *MPU9250) SwitchSPIEnabled(enabled bool) error

SwitchSPIEnabled switches from I2C to SPI mode (MPU-6000 only)

If this is set, the primary SPI interface will be enabled in place of the disabled primary I2C interface.

func (*MPU9250) TemperatureIsEnabled

func (m *MPU9250) TemperatureIsEnabled() (bool, error)

TemperatureIsEnabled returns if the temperature sensor enabled.

func (*MPU9250) WriteByteAddress

func (m *MPU9250) WriteByteAddress(address, value byte) error

WriteByteAddress writes to the byte address.

type Proto

type Proto interface {
	// contains filtered or unexported methods
}

Proto defines the low-level methods used by different transports.

type RotationData

type RotationData struct {
	X, Y, Z int16
}

RotationData the rotation around X/Y/Z axises.

type SelfTestResult

type SelfTestResult struct {
	AccelDeviation Deviation
	GyroDeviation  Deviation
}

SelfTestResult defines the results for self-test for accelerometer, gyroscope.

type SpiTransport

type SpiTransport struct {
	// contains filtered or unexported fields
}

SpiTransport Encapsulates the SPI transport parameters.

func NewSpiTransport

func NewSpiTransport(path string, cs gpio.PinOut) (*SpiTransport, error)

NewSpiTransport Creates the SPI transport using the provided device path and chip select pin reference.

func (*SpiTransport) EnableDebug

func (s *SpiTransport) EnableDebug(f DebugF)

EnableDebug Sets the debugging output using the local print function.

Directories

Path Synopsis
Package accelerometer contains constants for the MPU9250.
Package accelerometer contains constants for the MPU9250.
Package reg defines constants for the MPU9250.
Package reg defines constants for the MPU9250.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL