drivers

package
v0.0.0-...-9455d11 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INA219_ADDRESS01 = 0x40
	INA219_ADDRESS02 = 0x41

	INA219_CONFIG_RESET                     = 0x8000
	INA219_CONFIG_BVOLTAGERANGE_MASK        = 0x2000
	INA219_CONFIG_BVOLTAGERANGE_16V         = 0x0000
	INA219_CONFIG_BVOLTAGERANGE_32V         = 0x2000
	INA219_CONFIG_GAIN_MASK                 = 0x1800
	INA219_CONFIG_GAIN_1_40MV               = 0x0000
	INA219_CONFIG_GAIN_2_80MV               = 0x0800
	INA219_CONFIG_GAIN_4_160MV              = 0x1000
	INA219_CONFIG_GAIN_8_320MV              = 0x1800
	INA219_CONFIG_BADCRES_MASK              = 0x0780
	INA219_CONFIG_BADCRES_9BIT              = 0x0080
	INA219_CONFIG_BADCRES_10BIT             = 0x0100
	INA219_CONFIG_BADCRES_11BIT             = 0x0200
	INA219_CONFIG_BADCRES_12BIT             = 0x0400
	INA219_CONFIG_SADCRES_MASK              = 0x0078
	INA219_CONFIG_SADCRES_9BIT_1S_84US      = 0x0000
	INA219_CONFIG_SADCRES_10BIT_1S_148US    = 0x0008
	INA219_CONFIG_SADCRES_11BIT_1S_276US    = 0x0010
	INA219_CONFIG_SADCRES_12BIT_1S_532US    = 0x0018
	INA219_CONFIG_SADCRES_12BIT_2S_1060US   = 0x0048
	INA219_CONFIG_SADCRES_12BIT_4S_2130US   = 0x0050
	INA219_CONFIG_SADCRES_12BIT_8S_4260US   = 0x0058
	INA219_CONFIG_SADCRES_12BIT_16S_8510US  = 0x0060
	INA219_CONFIG_SADCRES_12BIT_32S_17MS    = 0x0068
	INA219_CONFIG_SADCRES_12BIT_64S_34MS    = 0x0070
	INA219_CONFIG_SADCRES_12BIT_128S_69MS   = 0x0078
	INA219_CONFIG_MODE_MASK                 = 0x0007
	INA219_CONFIG_MODE_POWERDOWN            = 0x0000
	INA219_CONFIG_MODE_SVOLT_TRIGGERED      = 0x0001
	INA219_CONFIG_MODE_BVOLT_TRIGGERED      = 0x0002
	INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED  = 0x0003
	INA219_CONFIG_MODE_ADCOFF               = 0x0004
	INA219_CONFIG_MODE_SVOLT_CONTINUOUS     = 0x0005
	INA219_CONFIG_MODE_BVOLT_CONTINUOUS     = 0x0006
	INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS = 0x0007

	INA219_SHUNTRESISTOR_VALUE float64 = 0.1

	INA219_REG_CONFIG       = 0x00
	INA219_REG_SHUNTVOLTAGE = 0x01
	INA219_REG_BUSVOLTAGE   = 0x02
	INA219_REG_POWER        = 0x03
	INA219_REG_CURRENT      = 0x04
	INA219_REG_CALIBRATION  = 0x05
)
View Source
const (
	MPU_ADDRESS               = 0x68
	MPUREG_XG_OFFS_TC         = 0x00
	MPUREG_YG_OFFS_TC         = 0x01
	MPUREG_ZG_OFFS_TC         = 0x02
	MPUREG_X_FINE_GAIN        = 0x03
	MPUREG_Y_FINE_GAIN        = 0x04
	MPUREG_Z_FINE_GAIN        = 0x05
	MPUREG_XA_OFFS_H          = 0x06
	MPUREG_XA_OFFS_L          = 0x07
	MPUREG_YA_OFFS_H          = 0x08
	MPUREG_YA_OFFS_L          = 0x09
	MPUREG_ZA_OFFS_H          = 0x0A
	MPUREG_ZA_OFFS_L          = 0x0B
	MPUREG_PRODUCT_ID         = 0x0C
	MPUREG_SELF_TEST_X        = 0x0D
	MPUREG_SELF_TEST_Y        = 0x0E
	MPUREG_SELF_TEST_Z        = 0x0F
	MPUREG_SELF_TEST_A        = 0x10
	MPUREG_XG_OFFS_USRH       = 0x13
	MPUREG_XG_OFFS_USRL       = 0x14
	MPUREG_YG_OFFS_USRH       = 0x15
	MPUREG_YG_OFFS_USRL       = 0x16
	MPUREG_ZG_OFFS_USRH       = 0x17
	MPUREG_ZG_OFFS_USRL       = 0x18
	MPUREG_SMPLRT_DIV         = 0x19
	MPUREG_CONFIG             = 0x1A
	MPUREG_GYRO_CONFIG        = 0x1B
	MPUREG_ACCEL_CONFIG       = 0x1C
	MPUREG_ACCEL_CONFIG_2     = 0x1D
	MPUREG_LP_ACCEL_ODR       = 0x1E
	MPUREG_MOT_THR            = 0x1F
	MPUREG_FIFO_EN            = 0x23
	MPUREG_I2C_MST_CTRL       = 0x24
	MPUREG_I2C_SLV0_ADDR      = 0x25
	MPUREG_I2C_SLV0_REG       = 0x26
	MPUREG_I2C_SLV0_CTRL      = 0x27
	MPUREG_I2C_SLV1_ADDR      = 0x28
	MPUREG_I2C_SLV1_REG       = 0x29
	MPUREG_I2C_SLV1_CTRL      = 0x2A
	MPUREG_I2C_SLV2_ADDR      = 0x2B
	MPUREG_I2C_SLV2_REG       = 0x2C
	MPUREG_I2C_SLV2_CTRL      = 0x2D
	MPUREG_I2C_SLV3_ADDR      = 0x2E
	MPUREG_I2C_SLV3_REG       = 0x2F
	MPUREG_I2C_SLV3_CTRL      = 0x30
	MPUREG_I2C_SLV4_ADDR      = 0x31
	MPUREG_I2C_SLV4_REG       = 0x32
	MPUREG_I2C_SLV4_DO        = 0x33
	MPUREG_I2C_SLV4_CTRL      = 0x34
	MPUREG_I2C_SLV4_DI        = 0x35
	MPUREG_I2C_MST_STATUS     = 0x36
	MPUREG_INT_PIN_CFG        = 0x37
	MPUREG_INT_ENABLE         = 0x38
	MPUREG_INT_STATUS         = 0x3A
	MPUREG_ACCEL_XOUT_H       = 0x3B
	MPUREG_ACCEL_XOUT_L       = 0x3C
	MPUREG_ACCEL_YOUT_H       = 0x3D
	MPUREG_ACCEL_YOUT_L       = 0x3E
	MPUREG_ACCEL_ZOUT_H       = 0x3F
	MPUREG_ACCEL_ZOUT_L       = 0x40
	MPUREG_TEMP_OUT_H         = 0x41
	MPUREG_TEMP_OUT_L         = 0x42
	MPUREG_GYRO_XOUT_H        = 0x43
	MPUREG_GYRO_XOUT_L        = 0x44
	MPUREG_GYRO_YOUT_H        = 0x45
	MPUREG_GYRO_YOUT_L        = 0x46
	MPUREG_GYRO_ZOUT_H        = 0x47
	MPUREG_GYRO_ZOUT_L        = 0x48
	MPUREG_EXT_SENS_DATA_00   = 0x49
	MPUREG_EXT_SENS_DATA_01   = 0x4A
	MPUREG_EXT_SENS_DATA_02   = 0x4B
	MPUREG_EXT_SENS_DATA_03   = 0x4C
	MPUREG_EXT_SENS_DATA_04   = 0x4D
	MPUREG_EXT_SENS_DATA_05   = 0x4E
	MPUREG_EXT_SENS_DATA_06   = 0x4F
	MPUREG_EXT_SENS_DATA_07   = 0x50
	MPUREG_EXT_SENS_DATA_08   = 0x51
	MPUREG_EXT_SENS_DATA_09   = 0x52
	MPUREG_EXT_SENS_DATA_10   = 0x53
	MPUREG_EXT_SENS_DATA_11   = 0x54
	MPUREG_EXT_SENS_DATA_12   = 0x55
	MPUREG_EXT_SENS_DATA_13   = 0x56
	MPUREG_EXT_SENS_DATA_14   = 0x57
	MPUREG_EXT_SENS_DATA_15   = 0x58
	MPUREG_EXT_SENS_DATA_16   = 0x59
	MPUREG_EXT_SENS_DATA_17   = 0x5A
	MPUREG_EXT_SENS_DATA_18   = 0x5B
	MPUREG_EXT_SENS_DATA_19   = 0x5C
	MPUREG_EXT_SENS_DATA_20   = 0x5D
	MPUREG_EXT_SENS_DATA_21   = 0x5E
	MPUREG_EXT_SENS_DATA_22   = 0x5F
	MPUREG_EXT_SENS_DATA_23   = 0x60
	MPUREG_I2C_SLV0_DO        = 0x63
	MPUREG_I2C_SLV1_DO        = 0x64
	MPUREG_I2C_SLV2_DO        = 0x65
	MPUREG_I2C_SLV3_DO        = 0x66
	MPUREG_I2C_MST_DELAY_CTRL = 0x67
	MPUREG_SIGNAL_PATH_RESET  = 0x68
	MPUREG_MOT_DETECT_CTRL    = 0x69
	MPUREG_USER_CTRL          = 0x6A
	MPUREG_PWR_MGMT_1         = 0x6B
	MPUREG_PWR_MGMT_2         = 0x6C
	MPUREG_BANK_SEL           = 0x6D
	MPUREG_MEM_START_ADDR     = 0x6E
	MPUREG_MEM_R_W            = 0x6F
	MPUREG_DMP_CFG_1          = 0x70
	MPUREG_DMP_CFG_2          = 0x71
	MPUREG_FIFO_COUNTH        = 0x72
	MPUREG_FIFO_COUNTL        = 0x73
	MPUREG_FIFO_R_W           = 0x74
	MPUREG_WHOAMI             = 0x75
	MPUREG_XA_OFFSET_H        = 0x77
	MPUREG_XA_OFFSET_L        = 0x78
	MPUREG_YA_OFFSET_H        = 0x7A
	MPUREG_YA_OFFSET_L        = 0x7B
	MPUREG_ZA_OFFSET_H        = 0x7D
	MPUREG_ZA_OFFSET_L        = 0x7E
	/* ---- AK8963 Reg In MPU9250 ----------------------------------------------- */
	AK8963_I2C_ADDR        = 0x0C //0x18
	AK8963_Device_ID       = 0x48
	AK8963_MAX_SAMPLE_RATE = 0x64 // 100 Hz
	// Read-only Reg
	AK8963_WIA  = 0x00
	AK8963_INFO = 0x01
	AK8963_ST1  = 0x02
	AK8963_HXL  = 0x03
	AK8963_HXH  = 0x04
	AK8963_HYL  = 0x05
	AK8963_HYH  = 0x06
	AK8963_HZL  = 0x07
	AK8963_HZH  = 0x08
	AK8963_ST2  = 0x09
	// Write/Read Reg
	AK8963_CNTL1  = 0x0A
	AK8963_CNTL2  = 0x0B
	AK8963_ASTC   = 0x0C
	AK8963_TS1    = 0x0D
	AK8963_TS2    = 0x0E
	AK8963_I2CDIS = 0x0F
	// Read-only Reg ( ROM )
	AK8963_ASAX = 0x10
	AK8963_ASAY = 0x11
	AK8963_ASAZ = 0x12
	// Configuration bits mpu9250
	BIT_SLEEP                  = 0x40
	BIT_H_RESET                = 0x80
	BITS_CLKSEL                = 0x07
	MPU_CLK_SEL_PLLGYROX       = 0x01
	MPU_CLK_SEL_PLLGYROZ       = 0x03
	MPU_EXT_SYNC_GYROX         = 0x02
	BITS_FS_250DPS             = 0x00
	BITS_FS_500DPS             = 0x08
	BITS_FS_1000DPS            = 0x10
	BITS_FS_2000DPS            = 0x18
	BITS_FS_2G                 = 0x00
	BITS_FS_4G                 = 0x08
	BITS_FS_8G                 = 0x10
	BITS_FS_16G                = 0x18
	BITS_FS_MASK               = 0x18
	BITS_DLPF_CFG_256HZ_NOLPF2 = 0x00
	BITS_DLPF_CFG_188HZ        = 0x01
	BITS_DLPF_CFG_98HZ         = 0x02
	BITS_DLPF_CFG_42HZ         = 0x03
	BITS_DLPF_CFG_20HZ         = 0x04
	BITS_DLPF_CFG_10HZ         = 0x05
	BITS_DLPF_CFG_5HZ          = 0x06
	BITS_DLPF_CFG_2100HZ_NOLPF = 0x07
	BITS_DLPF_CFG_MASK         = 0x07
	BIT_INT_ANYRD_2CLEAR       = 0x10
	BIT_RAW_RDY_EN             = 0x01
	BIT_I2C_IF_DIS             = 0x10

	// CNTL1 Mode select
	// Power down mode
	AK8963_MODE_DOWN = 0x00
	// One shot data output
	AK8963_MODE_ONE = 0x01
	// Continous data output 8Hz
	AK8963_MODE_C8HZ = 0x02
	// Continous data output 100Hz
	AK8963_MODE_C100HZ = 0x06
	// Magneto Scale Select
	// 14bit output
	AK8963_BIT_14 = 0x00
	// 16bit output
	AK8963_BIT_16 = 0x01

	// Misc
	READ_FLAG                    = 0x80
	MPU_BANK_SIZE                = 0xFF
	CFG_MOTION_BIAS              = 0x4B8 // Enable/disable gyro bias compensation
	BIT_FIFO_SIZE_1024           = 0x40  // FIFO buffer size
	BIT_AUX_IF_EN          uint8 = 0x20
	BIT_BYPASS_EN                = 0x02
	AKM_POWER_DOWN               = 0x00
	BIT_I2C_READ                 = 0x80
	BIT_SLAVE_EN                 = 0x80
	AKM_SINGLE_MEASUREMENT       = 0x01
	INV_CLK_PLL                  = 0x01
	AK89xx_FSR                   = 9830
	AKM_DATA_READY               = 0x01
	AKM_DATA_OVERRUN             = 0x02
	AKM_OVERFLOW                 = 0x80

	MPU9250M_4800uT = 0.6            // 0.6 uT/LSB
	MPU9250T_85degC = 0.002995177763 // 0.002995177763 degC/LSB

)

Variables

This section is empty.

Functions

This section is empty.

Types

type INA219Driver

type INA219Driver struct {
	i2c.Config
	CalibrationValue uint16
	// contains filtered or unexported fields
}

INA219Driver is a driver for the INA219 current and bus voltage monitoring device.

func NewINA219Driver

func NewINA219Driver(c i2c.Connector, options ...func(i2c.Config)) *INA219Driver

NewINA219Driver creates a new driver with the specified i2c interface. Params:

conn Connector - the Adaptor to use with this Driver

Optional params:

i2c.WithBus(int):		bus to use with this driver
i2c.WithAddress(int):		address to use with this driver

func (*INA219Driver) Connection

func (i *INA219Driver) Connection() gobot.Connection

Connection returns the connection of the device.

func (*INA219Driver) GetBusVoltage

func (i *INA219Driver) GetBusVoltage() (float64, error)

GetBusVoltage gets the bus voltage in Volts

func (*INA219Driver) GetCurrent

func (i *INA219Driver) GetCurrent() (float64, error)

GetCurrent gets the current value in mA, taking into account the config settings and current LSB

func (*INA219Driver) GetLoadVoltage

func (i *INA219Driver) GetLoadVoltage() (float64, error)

GetLoadVoltage gets the load voltage in mV

func (*INA219Driver) GetShuntVoltage

func (i *INA219Driver) GetShuntVoltage() (float64, error)

GetShuntVoltage Gets the shunt voltage in mV

func (*INA219Driver) Halt

func (i *INA219Driver) Halt() error

Halt halts the device.

func (*INA219Driver) Name

func (i *INA219Driver) Name() string

Name returns the name of the device.

func (*INA219Driver) SetName

func (i *INA219Driver) SetName(name string)

SetName sets the name of the device.

func (*INA219Driver) Start

func (i *INA219Driver) Start() error

Start initializes the INA219

type MPU9250Driver

type MPU9250Driver struct {
	i2c.Config

	Data *MPUData
	// contains filtered or unexported fields
}

func NewMPU9250Driver

func NewMPU9250Driver(a i2c.Connector, options ...func(i2c.Config)) *MPU9250Driver

NewMPU9250Driver creates a new Gobot Driver for an MPU9250 I2C Accelerometer/Gyroscope.

Params:

conn Connector - the Adaptor to use with this Driver

Optional params:

i2c.WithBus(int):	bus to use with this driver
i2c.WithAddress(int):	address to use with this driver

func (*MPU9250Driver) Connection

func (mpu *MPU9250Driver) Connection() gobot.Connection

Connection returns the connection for the device.

func (*MPU9250Driver) GetData

func (mpu *MPU9250Driver) GetData() (err error)

readSensors polls the gyro, accelerometer and magnetometer sensors as well as the die temperature.

func (*MPU9250Driver) Halt

func (mpu *MPU9250Driver) Halt() (err error)

Halt returns true if devices is halted successfully

func (*MPU9250Driver) Name

func (mpu *MPU9250Driver) Name() string

Name returns the name of the device.

func (*MPU9250Driver) SetName

func (mpu *MPU9250Driver) SetName(n string)

SetName sets the name of the device.

func (*MPU9250Driver) Start

func (mpu *MPU9250Driver) Start() (err error)

Start writes initialization bytes to sensor

type MPUData

type MPUData struct {
	G1, G2, G3 float64
	A1, A2, A3 float64
	M1, M2, M3 float64
	Temp       float64
}

MPUData contains all the values measured by an MPU9250.

Jump to

Keyboard shortcuts

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