mma8653

package
v0.0.0-...-7691dab Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package mma8653 provides a driver for the MMA8653 3-axis accelerometer by Freescale/NXP.

Datasheet: https://www.nxp.com/docs/en/data-sheet/MMA8653FC.pdf

Index

Constants

View Source
const (
	STATUS       = 0x00 // Real time status
	OUT_X_MSB    = 0x01 // top 8 bits of 10-bit sample
	OUT_X_LSB    = 0x02 // bottom 2 bits of 10-bit sample
	OUT_Y_MSB    = 0x03 // top 8 bits of 10-bit sample
	OUT_Y_LSB    = 0x04 // bottom 2 bits of 10-bit sample
	OUT_Z_MSB    = 0x05 // top 8 bits of 10-bit sample
	OUT_Z_LSB    = 0x06 // bottom 2 bits of 10-bit sample
	SYSMOD       = 0x0B // Current System Mode
	INT_SOURCE   = 0x0C // Interrupt status
	WHO_AM_I     = 0x0D // Device ID (0x5A)
	XYZ_DATA_CFG = 0x0E // Dynamic Range Settings
	PL_STATUS    = 0x10 // Landscape/Portrait orientation status
	PL_CFG       = 0x11 // Landscape/Portrait configuration
	PL_COUNT     = 0x12 // Landscape/Portrait debouncer counter
	PL_BF_ZCOMP  = 0x13 // Back/Front, Z-Lock Trip threshold
	PL_THS_REG   = 0x14 // Portrait to Landscape Trip angle
	FF_MT_CFG    = 0x15 // Freefall/Motion functional block configuration
	FF_MT_SRC    = 0x16 // Freefall/Motion event source register
	FF_MT_THS    = 0x17 // Freefall/Motion threshold register
	FF_MT_COUNT  = 0x18 // Freefall/Motion debounce counter
	ASLP_COUNT   = 0x29 // Counter setting for Auto-SLEEP/WAKE
	CTRL_REG1    = 0x2A // Data Rates, ACTIVE Mode
	CTRL_REG2    = 0x2B // Sleep Enable, OS Modes, RST, ST
	CTRL_REG3    = 0x2C // Wake from Sleep, IPOL, PP_OD
	CTRL_REG4    = 0x2D // Interrupt enable register
	CTRL_REG5    = 0x2E // Interrupt pin (INT1/INT2) map
	OFF_X        = 0x2F // X-axis offset adjust
	OFF_Y        = 0x30 // Y-axis offset adjust
	OFF_Z        = 0x31 // Z-axis offset adjust
)

Registers. Names, addresses and comments copied from the datasheet.

View Source
const Address = 0x1D

The I2C address which this device listens to.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataRate

type DataRate uint8
const (
	DataRate800Hz DataRate = iota // 800Hz,  1.25ms interval
	DataRate400Hz                 // 400Hz,  2.5ms  interval
	DataRate200Hz                 // 200Hz,  5ms    interval
	DataRate100Hz                 // 100Hz,  10ms   interval
	DataRate50Hz                  // 50Hz,   20ms   interval
	DataRate12Hz                  // 12.5Hz, 80ms   interval
	DataRate6Hz                   // 6.25Hz, 160ms  interval
	DataRate2Hz                   // 1.56Hz, 640ms  interval
)

Data rate constants.

type Device

type Device struct {
	Address uint16
	// contains filtered or unexported fields
}

Device wraps an I2C connection to a MMA8653 device.

func New

func New(bus drivers.I2C) Device

New creates a new MMA8653 connection. The I2C bus must already be configured.

This function only creates the Device object, it does not touch the device.

func (*Device) Configure

func (d *Device) Configure(speed DataRate, sensitivity Sensitivity) error

Configure sets up the device for communication.

func (Device) Connected

func (d Device) Connected() bool

Connected returns whether a MMA8653 has been found. It does a "who am I" request and checks the response.

func (Device) ReadAcceleration

func (d Device) ReadAcceleration() (x int32, y int32, z int32, err error)

ReadAcceleration reads the current acceleration from the device and returns it in µg (micro-gravity). When one of the axes is pointing straight to Earth and the sensor is not moving the returned value will be around 1000000 or -1000000.

type Sensitivity

type Sensitivity uint8
const (
	Sensitivity2G Sensitivity = iota
	Sensitivity4G
	Sensitivity8G
)

Sensitivity constants.

Jump to

Keyboard shortcuts

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