multi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

tinygo-multi-i2c

Go Reference go reportcard A reimplementation of the TinyGo drivers package for communicating with multiples of the same (supported) devices on one individual I2C bus.

Supported Devices

  • ADXL345 - I2C Accelerometor by iMEMS
  • AMG88XX series - I2C High Precision Infrared Array Sensor by Panasonic
  • BH1750 - I2C Light Sensor by SMAKN
  • BLINKM: I2C-controllable LEDs
  • BME280 - I2C Humidity and Pressure Sensor by Bosch Sensortec
  • BMP280 - I2C Barometric Pressure Sensor by Bosch Sensortec
  • DS3231 - I2C RTC (Real-Time-Clock) by Adafruit
  • LIS3DH - I2C Acclerometer by STMicroelectronics
  • MPU6050 - I2C (Gyro + Acclerometer) MEMS Motion Tracking Device by InvenSense/TDK

Pre-requisites

  • you must have Go installed (recommended v1.17+, for Windows 10, you MUST use Go v1.16 or greater)
  • you must have TinyGo installed (quick install guides found here) and configured for the IDE you are using (guides for both VSCode, IntelliJ IDEA, and other IDEs found here)

Why was tinygo-multi-i2c built?

tinygo-multi-2c was built for the purpose of simplifying the process of setting up multiples of one or more devices that communicate over the same I2C bus using the I2c protocol and pre-written drivers from TinyGo (found here).

What problem does tinygo-multi-i2c solve?

While using the pre-written drivers from TinyGo is extremely useful, it takes a handful of lines to set up one device. And that's only if you're using the default address that specifc device uses. Whereas using the tinygo-multi-i2c package, you can create a device, configure it, set the address specifically to the one you want, and test the connection for that device all in as little as two lines after initializing the your I2C bus, allowing for cleaner, more concise code. Initializing the I2C bus; which will be the same as doing so with the drivers package from TinyGo (an example of can be found on TinyGo's page for Divers here; there's also an example down below). The error returned, if nil isn't returned, will help point you in the direction of where your device set-up is failing to allow for smooth debugging.

How do I use tinygo-multi-i2c?

After installing the pre-requisites and configuring your IDE, simply import tinygo-multi-i2c using go get

$ go get github.com/syke99/tinygo-multi-i2c

Then you can import the package in any go file you'd like

import (
    "machine"

     multi "github.com/syke99/go-c2dmc"
)
Basic usage

Initialize your I2C bus by initializing and configuring an machine.I2C0 to be passed into the NewDevice() method. Ex:

    i2c := machine.I2C0
    err := i2c.Configure(machine.I2CConfig{
        SCL: machine.P0_30, // <-- These values will be dependent on what microcontroller you're using
        SDA: machine.P0_31, // <-- These values will be dependent on what microcontroller you're using
    })
    if err != nil {
        println("could not configure I2C:", err)
        return
    }

Declare a variable to hold the returned Devices struct that will be used to access the device you create, and then call multi.NewDevices(params) and pass in your parameters, the first being the i2c bus you initialized, followed by the name of the device you would like to create in all lowercase (minus the first letter). Ex:

// since this isn't a BMP280, we need to just pass in a slice of uint's that are all 0
// it can also be reused for any other I2C device that you're using that isn't a BMP280
// a BMP280 needs 5 uint's passed to it for its Standby, Filter, Temperature, Pressure, and Mode.
b := [5]uint{0,0,0,0,0}

// the default address for a BLINKM is 0x09, so to dynamically set it, we pass in the address, 
// i.e.: 0x00 in this example
// if you want to use the default address of 0x09, you can just pass in a 0 as the address
devices, error := multi.NewDevice(i2c, "blinkm", 0x00, b)

NOTE: if you are setting up a BMP280 device, you must provide 5 arguments (of type uint) to the NewDevice method to configure the BMP280's Standby, Filter, Temperature, Pressure, and Mode. If not, simply pass in all 0's. This example just uses all 0's with a BMP280 for brevity's sake.

After that, grab the device you created and save it in a variable by using dot notation with the Devices struct you got returned. Ex:

b := devices.Blinkm

Then you can simply just call the function that corresponds to how you want to interact with the device. Ex:

error := b.FadeToRGB()

This process can be repeated by simply repeating the line to create a new device, just with a new name of a variable to hold the Devices struct for each device you wish to create. Ex:

// These devices are using the default addresses, 
// so passing in 0, and using the []uint named b we initialized 
// above since none of them are a BMP280

// Device 1, a BLINKM RGB light
d1, error := multi.NewDevice(i2c, "blinkm", 0, b)
// Handle or ignore error (advised to not ignore)
bl := d1.Blinkm

// Device 2, an MPU6050 motion tracking device
d2, error := multi.NewDevice(i2c, "mpu6050", 0, b)
// Handle or ignore error (advised to not ignore)
m := d2.Mpu6050

// Device 3, a BH1750 light sensor
d3, error := multi.NewDevice(i2c, "bh1750", 0, b)
// Handle or ignore error (advised to not ignore)
bh := d3.Bh1750

error := bl.FadeToRGB()
// handle error and/or using pressure reading value here

acceleration, error := m.ReadAcceleration()
// handle error and/or using acceleration reading value here

illuminance, error := bh.Illuminance()
// handle error and/or using illuminance reading value here

Note Due to these drivers requiring an I2C bus that is set up outside of this package (utilizing the machine package that TinyGo uses and you must have configured your IDE to be able to use), adding tests to this package is beyond its scope (due to not having direct access to the machine package coupled with the fact the machine package is dependent on the microcontroller your program(s) will be running on).

Documentation

Index

Constants

View Source
const (
	// Data rate
	ADX1345_RATE_3200HZ Adxl345Rate = 0x0F // 3200 Hz
	ADX1345_RATE_1600HZ Adxl345Rate = 0x0E // 1600 Hz
	ADX1345_RATE_800HZ  Adxl345Rate = 0x0D // 800 Hz
	ADX1345_RATE_400HZ  Adxl345Rate = 0x0C // 400 Hz
	ADX1345_RATE_200HZ  Adxl345Rate = 0x0B // 200 Hz
	ADX1345_RATE_100HZ  Adxl345Rate = 0x0A // 100 Hz
	ADX1345_RATE_50HZ   Adxl345Rate = 0x09 // 50 Hz
	ADX1345_RATE_25HZ   Adxl345Rate = 0x08 // 25 Hz
	ADX1345_RATE_12_5HZ Adxl345Rate = 0x07 // 12.5 Hz
	ADX1345_RATE_6_25HZ Adxl345Rate = 0x06 // 6.25 Hz
	ADX1345_RATE_3_13HZ Adxl345Rate = 0x05 // 3.13 Hz
	ADX1345_RATE_1_56HZ Adxl345Rate = 0x04 // 1.56 Hz
	ADX1345_RATE_0_78HZ Adxl345Rate = 0x03 // 0.78 Hz
	ADX1345_RATE_0_39HZ Adxl345Rate = 0x02 // 0.39 Hz
	ADX1345_RATE_0_20HZ Adxl345Rate = 0x01 // 0.20 Hz
	ADX1345_RATE_0_10HZ Adxl345Rate = 0x00 // 0.10 Hz

	// Data range
	ADX1345_RANGE_2G  Adxl345Range = 0x00 // +-2 g
	ADX1345_RANGE_4G  Adxl345Range = 0x01 // +-4 g
	ADX1345_RANGE_8G  Adxl345Range = 0x02 // +-8 g
	ADX1345_RANGE_16G Adxl345Range = 0x03 // +-16 g)

	ADX1345_REG_DEVID          = 0x00 // R,     11100101,   Device ID
	ADX1345_REG_THRESH_TAP     = 0x1D // R/W,   00000000,   Tap threshold
	ADX1345_REG_OFSX           = 0x1E // R/W,   00000000,   X-axis offset
	ADX1345_REG_OFSY           = 0x1F // R/W,   00000000,   Y-axis offset
	ADX1345_REG_OFSZ           = 0x20 // R/W,   00000000,   Z-axis offset
	ADX1345_REG_DUR            = 0x21 // R/W,   00000000,   Tap duration
	ADX1345_REG_LATENT         = 0x22 // R/W,   00000000,   Tap latency
	ADX1345_REG_WINDOW         = 0x23 // R/W,   00000000,   Tap window
	ADX1345_REG_THRESH_ACT     = 0x24 // R/W,   00000000,   Activity threshold
	ADX1345_REG_THRESH_INACT   = 0x25 // R/W,   00000000,   Inactivity threshold
	ADX1345_REG_TIME_INACT     = 0x26 // R/W,   00000000,   Inactivity time
	ADX1345_REG_ACT_INACT_CTL  = 0x27 // R/W,   00000000,   Axis enable control for activity and inactiv ity detection
	ADX1345_REG_THRESH_FF      = 0x28 // R/W,   00000000,   Free-fall threshold
	ADX1345_REG_TIME_FF        = 0x29 // R/W,   00000000,   Free-fall time
	ADX1345_REG_TAP_AXES       = 0x2A // R/W,   00000000,   Axis control for single tap/double tap
	ADX1345_REG_ACT_TAP_STATUS = 0x2B // R,     00000000,   Source of single tap/double tap
	ADX1345_REG_BW_RATE        = 0x2C // R/W,   00001010,   Data rate and power mode control
	ADX1345_REG_POWER_CTL      = 0x2D // R/W,   00000000,   Power-saving features control
	ADX1345_REG_INT_ENABLE     = 0x2E // R/W,   00000000,   Interrupt enable control
	ADX1345_REG_INT_MAP        = 0x2F // R/W,   00000000,   Interrupt mapping control
	ADX1345_REG_INT_SOUCE      = 0x30 // R,     00000010,   Source of interrupts
	ADX1345_REG_DATA_FORMAT    = 0x31 // R/W,   00000000,   Data format control
	ADX1345_REG_DATAX0         = 0x32 // R,     00000000,   X-Axis Data 0
	ADX1345_REG_DATAX1         = 0x33 // R,     00000000,   X-Axis Data 1
	ADX1345_REG_DATAY0         = 0x34 // R,     00000000,   Y-Axis Data 0
	ADX1345_REG_DATAY1         = 0x35 // R,     00000000,   Y-Axis Data 1
	ADX1345_REG_DATAZ0         = 0x36 // R,     00000000,   Z-Axis Data 0
	ADX1345_REG_DATAZ1         = 0x37 // R,     00000000,   Z-Axis Data 1
	ADX1345_REG_FIFO_CTL       = 0x38 // R/W,   00000000,   FIFO control
	ADX1345_REG_FIFO_STATUS    = 0x39 // R,     00000000,   FIFO status
)
View Source
const (
	AMG88XX_PCTL         = 0x00
	AMG88XX_RST          = 0x01
	AMG88XX_FPSC         = 0x02
	AMG88XX_INTC         = 0x03
	AMG88XX_STAT         = 0x04
	AMG88XX_SCLR         = 0x05
	AMG88XX_AVE          = 0x07
	AMG88XX_INTHL        = 0x08
	AMG88XX_INTHH        = 0x09
	AMG88XX_INTLL        = 0x0A
	AMG88XX_INTLH        = 0x0B
	AMG88XX_IHYSL        = 0x0C
	AMG88XX_IHYSH        = 0x0D
	AMG88XX_TTHL         = 0x0E
	AMG88XX_TTHH         = 0x0F
	AMG88XX_INT_OFFSET   = 0x010
	AMG88XX_PIXEL_OFFSET = 0x80

	// power modes
	AMG88XX_NORMAL_MODE = 0x00
	AMG88XX_SLEEP_MODE  = 0x01
	AMG88XX_STAND_BY_60 = 0x20
	AMG88XX_STAND_BY_10 = 0x21

	// resets
	AMG88XX_FLAG_RESET    = 0x30
	AMG88XX_INITIAL_RESET = 0x3F

	// frame rates
	AMG88XX_FPS_10 = 0x00
	AMG88XX_FPS_1  = 0x01

	// interrupt modes
	AMG88XX_DIFFERENCE     Amg88xxInterruptMode = 0x00
	AMG88XX_ABSOLUTE_VALUE Amg88xxInterruptMode = 0x01

	AMG88XX_PIXEL_TEMP_CONVERSION = 250
	AMG88XX_THERMISTOR_CONVERSION = 625
)
View Source
const (
	BH1750_POWER_DOWN                      = 0x00
	BH1750_POWER_ON                        = 0x01
	BH1750_RESET                           = 0x07
	BH1750_CONTINUOUS_HIGH_RES_MODE   byte = 0x10
	BH1750_CONTINUOUS_HIGH_RES_MODE_2 byte = 0x11
	BH1750_CONTINUOUS_LOW_RES_MODE    byte = 0x13
	BH1750_ONE_TIME_HIGH_RES_MODE     byte = 0x20
	BH1750_ONE_TIME_HIGH_RES_MODE_2   byte = 0x21
	BH1750_ONE_TIME_LOW_RES_MODE      byte = 0x23

	// resolution in 10*lx
	BH1750_HIGH_RES  = 10
	BH1750_HIGH_RES2 = 5
	BH1750_LOW_RES   = 40
)
View Source
const (
	BLINKM_TO_RGB            = 0x6e
	BLINKM_FADE_TO_RGB       = 0x63
	BLINKM_FADE_TO_HSB       = 0x68
	BLINKM_FADE_TO_RND_RGB   = 0x43
	BLINKM_FADE_TO_RND_HSB   = 0x48
	BLINKM_PLAY_LIGHT_SCRIPT = 0x70
	BLINKM_STOP_SCRIPT       = 0x6f
	BLINKM_SET_FADE          = 0x66
	BLINKM_SET_TIME          = 0x74
	BLINKM_GET_RGB           = 0x67
	BLINKM_GET_ADDRESS       = 0x61
	BLINKM_SET_ADDRESS       = 0x41
	BLINKM_GET_FIRMWARE      = 0x5a
)
View Source
const (
	BME280_CTRL_MEAS_ADDR        = 0xF4
	BME280_CTRL_HUMIDITY_ADDR    = 0xF2
	BME280_CTRL_CONFIG           = 0xF5
	BME280_REG_PRESSURE          = 0xF7
	BME280_REG_CALIBRATION       = 0x88
	BME280_REG_CALIBRATION_H1    = 0xA1
	BME280_REG_CALIBRATION_H2LSB = 0xE1
	BME280_CMD_RESET             = 0xE0

	BME280_WHO_AM_I = 0xD0
	BME280_CHIP_ID  = 0x60
)
View Source
const (
	BMP280_REG_ID        = 0xD0 // WHO_AM_I
	BMP280_REG_RESET     = 0xE0
	BMP280_REG_STATUS    = 0xF3
	BMP280_REG_CTRL_MEAS = 0xF4
	BMP280_REG_CONFIG    = 0xF5
	BMP280_REG_TEMP      = 0xFA
	BMP280_REG_PRES      = 0xF7
	BMP280_REG_CALI      = 0x88

	BMP280_CHIP_ID   = 0x58
	BMP280_CMD_RESET = 0xB6
)
View Source
const (
	BMP280_SAMPLING_SKIPPED uint = iota
	BMP280_SAMPLING_1X
	BMP280_SAMPLING_2X
	BMP280_SAMPLING_4X
	BMP280_SAMPLING_8X
	BMP280_SAMPLING_16X
)
View Source
const (
	BMP280_MODE_SLEEP  uint = 0x00
	BMP280_MODE_FORCED uint = 0x01
	BMP280_MODE_NORMAL uint = 0x03
)
View Source
const (
	BMP280_STANDBY_1MS uint = iota
	BMP280_STANDBY_63MS
	BMP280_STANDBY_125MS
	BMP280_STANDBY_250MS
	BMP280_STANDBY_500MS
	BMP280_STANDBY_1000MS
	BMP280_STANDBY_2000MS
	BMP280_STANDBY_4000MS
)
View Source
const (
	BMP280_FILTER_OFF uint = iota
	BMP280_FILTER_2X
	BMP280_FILTER_4X
	BMP280_FILTER_8X
	BMP280_FILTER_16X
)
View Source
const (
	DS3231_REG_TIMEDATE = 0x00
	DS3231_REG_ALARMONE = 0x07
	DS3231_REG_ALARMTWO = 0x0B

	DS3231_REG_CONTROL = 0x0E
	DS3231_REG_STATUS  = 0x0F
	DS3231_REG_AGING   = 0x10

	DS3231_REG_TEMP = 0x11

	DS3231_REG_ALARMONE_SIZE = 4
	DS3231_REG_ALARMTWO_SIZE = 3

	// DS3231 Control Register Bits
	DS3231_A1IE  = 0
	DS3231_A2IE  = 1
	DS3231_INTCN = 2
	DS3231_RS1   = 3
	DS3231_RS2   = 4
	DS3231_CONV  = 5
	DS3231_BBSQW = 6
	DS3231_EOSC  = 7

	// DS3231 Status Register Bits
	DS3231_A1F     = 0
	DS3231_A2F     = 1
	DS3231_BSY     = 2
	DS3231_EN32KHZ = 3
	DS3231_OSF     = 7

	DS3231_AlarmFlag_Alarm1    = 0x01
	DS3231_AlarmFlag_Alarm2    = 0x02
	DS3231_AlarmFlag_AlarmBoth = 0x03

	DS3231_None          Ds3231Mode = 0
	DS3231_BatteryBackup Ds3231Mode = 1
	DS3231_Clock         Ds3231Mode = 2
	DS3231_AlarmOne      Ds3231Mode = 3
	DS3231_AlarmTwo      Ds3231Mode = 4
	DS3231_ModeAlarmBoth Ds3231Mode = 5
)
View Source
const (
	INA250_REG_CONFIG     = 0x00
	INA250_REG_CURRENT    = 0x01
	INA250_REG_BUSVOLTAGE = 0x02
	INA250_REG_POWER      = 0x03
	INA250_REG_MASKENABLE = 0x06
	INA250_REG_ALERTLIMIT = 0x07
	INA250_REG_MANF_ID    = 0xFE
	INA250_REG_DIE_ID     = 0xFF
)
View Source
const (
	Lis3dhAddress0 = 0x18 // SA0 is low
	Lis3dhAddress1 = 0x19 // SA0 is high
)

LIS3DH registers

View Source
const (
	LIS3DH_WHO_AM_I      = 0x0F
	LIS3DH_REG_STATUS1   = 0x07
	LIS3DH_REG_OUTADC1_L = 0x08
	LIS3DH_REG_OUTADC1_H = 0x09
	LIS3DH_REG_OUTADC2_L = 0x0A
	LIS3DH_REG_OUTADC2_H = 0x0B
	LIS3DH_REG_OUTADC3_L = 0x0C
	LIS3DH_REG_OUTADC3_H = 0x0D
	LIS3DH_REG_INTCOUNT  = 0x0E
	LIS3DH_REG_WHOAMI    = 0x0F
	LIS3DH_REG_TEMPCFG   = 0x1F
	LIS3DH_REG_CTRL1     = 0x20
	LIS3DH_REG_CTRL2     = 0x21
	LIS3DH_REG_CTRL3     = 0x22
	LIS3DH_REG_CTRL4     = 0x23
	LIS3DH_REG_CTRL5     = 0x24
	LIS3DH_REG_CTRL6     = 0x25
	LIS3DH_REG_REFERENCE = 0x26
	LIS3DH_REG_STATUS2   = 0x27
	LIS3DH_REG_OUT_X_L   = 0x28
	LIS3DH_REG_OUT_X_H   = 0x29
	LIS3DH_REG_OUT_Y_L   = 0x2A
	LIS3DH_REG_OUT_Y_H   = 0x2B
	LIS3DH_REG_OUT_Z_L   = 0x2C
	LIS3DH_REG_OUT_Z_H   = 0x2D
	LIS3DH_REG_FIFOCTRL  = 0x2E
	LIS3DH_REG_FIFOSRC   = 0x2F
	LIS3DH_REG_INT1CFG   = 0x30
	LIS3DH_REG_INT1SRC   = 0x31
	LIS3DH_REG_INT1THS   = 0x32
	LIS3DH_REG_INT1DUR   = 0x33
	LIS3DH_REG_CLICKCFG  = 0x38
	LIS3DH_REG_CLICKSRC  = 0x39
	LIS3DH_REG_CLICKTHS  = 0x3A
	LIS3DH_REG_TIMELIMIT = 0x3B
	LIS3DH_REG_TIMELATEN = 0x3C
	LIS3DH_REG_TIMEWINDO = 0x3D
	LIS3DH_REG_ACTTHS    = 0x3E
	LIS3DH_REG_ACTDUR    = 0x3F
)
View Source
const (
	LIS3DH_RANGE_16_G Lis3dhRange = 3 // +/- 16g
	LIS3DH_RANGE_8_G              = 2 // +/- 8g
	LIS3DH_RANGE_4_G              = 1 // +/- 4g
	LIS3DH_RANGE_2_G              = 0 // +/- 2g (default value)
)
View Source
const (
	LIS3DH_DATARATE_400_HZ         Lis3dhDataRate = 7 //  400Hz
	LIS3DH_DATARATE_200_HZ                        = 6 //  200Hz
	LIS3DH_DATARATE_100_HZ                        = 5 //  100Hz
	LIS3DH_DATARATE_50_HZ                         = 4 //   50Hz
	LIS3DH_DATARATE_25_HZ                         = 3 //   25Hz
	LIS3DH_DATARATE_10_HZ                         = 2 // 10 Hz
	LIS3DH_DATARATE_1_HZ                          = 1 // 1 Hz
	LIS3DH_DATARATE_POWERDOWN                     = 0
	LIS3DH_DATARATE_LOWPOWER_1K6HZ                = 8
	LIS3DH_DATARATE_LOWPOWER_5KHZ                 = 9
)

Data rate constants.

View Source
const (
	LPS22HB_WHO_AM_I_REG  = 0x0F
	LPS22HB_CTRL1_REG     = 0x10
	LPS22HB_CTRL2_REG     = 0x11
	LPS22HB_STATUS_REG    = 0x27
	LPS22HB_PRESS_OUT_REG = 0x28
	LPS22HB_TEMP_OUT_REG  = 0x2B
)
View Source
const (
	// Self test registers
	MPU6050_SELF_TEST_X = 0x0D
	MPU6050_SELF_TEST_Y = 0x0E
	MPU6050_SELF_TEST_Z = 0x0F
	MPU6050_SELF_TEST_A = 0x10

	MPU6050_SMPLRT_DIV   = 0x19 // Sample rate divider
	MPU6050_CONFIG       = 0x1A // Configuration
	MPU6050_GYRO_CONFIG  = 0x1B // Gyroscope configuration
	MPU6050_ACCEL_CONFIG = 0x1C // Accelerometer configuration
	MPU6050_FIFO_EN      = 0x23 // FIFO enable

	// I2C pass-through configuration
	MPU6050_I2C_MST_CTRL   = 0x24
	MPU6050_I2C_SLV0_ADDR  = 0x25
	MPU6050_I2C_SLV0_REG   = 0x26
	MPU6050_I2C_SLV0_CTRL  = 0x27
	MPU6050_I2C_SLV1_ADDR  = 0x28
	MPU6050_I2C_SLV1_REG   = 0x29
	MPU6050_I2C_SLV1_CTRL  = 0x2A
	MPU6050_I2C_SLV2_ADDR  = 0x2B
	MPU6050_I2C_SLV2_REG   = 0x2C
	MPU6050_I2C_SLV2_CTRL  = 0x2D
	MPU6050_I2C_SLV3_ADDR  = 0x2E
	MPU6050_I2C_SLV3_REG   = 0x2F
	MPU6050_I2C_SLV3_CTRL  = 0x30
	MPU6050_I2C_SLV4_ADDR  = 0x31
	MPU6050_I2C_SLV4_REG   = 0x32
	MPU6050_I2C_SLV4_DO    = 0x33
	MPU6050_I2C_SLV4_CTRL  = 0x34
	MPU6050_I2C_SLV4_DI    = 0x35
	MPU6050_I2C_MST_STATUS = 0x36

	// Interrupt configuration
	MPU6050_INT_PIN_CFG = 0x37 // Interrupt pin/bypass enable configuration
	MPU6050_INT_ENABLE  = 0x38 // Interrupt enable
	MPU6050_INT_STATUS  = 0x3A // Interrupt status

	// Accelerometer measurements
	MPU6050_ACCEL_XOUT_H = 0x3B
	MPU6050_ACCEL_XOUT_L = 0x3C
	MPU6050_ACCEL_YOUT_H = 0x3D
	MPU6050_ACCEL_YOUT_L = 0x3E
	MPU6050_ACCEL_ZOUT_H = 0x3F
	MPU6050_ACCEL_ZOUT_L = 0x40

	// Temperature measurement
	MPU6050_TEMP_OUT_H = 0x41
	MPU6050_TEMP_OUT_L = 0x42

	// Gyroscope measurements
	MPU6050_GYRO_XOUT_H = 0x43
	MPU6050_GYRO_XOUT_L = 0x44
	MPU6050_GYRO_YOUT_H = 0x45
	MPU6050_GYRO_YOUT_L = 0x46
	MPU6050_GYRO_ZOUT_H = 0x47
	MPU6050_GYRO_ZOUT_L = 0x48

	// External sensor data
	MPU6050_EXT_SENS_DATA_00 = 0x49
	MPU6050_EXT_SENS_DATA_01 = 0x4A
	MPU6050_EXT_SENS_DATA_02 = 0x4B
	MPU6050_EXT_SENS_DATA_03 = 0x4C
	MPU6050_EXT_SENS_DATA_04 = 0x4D
	MPU6050_EXT_SENS_DATA_05 = 0x4E
	MPU6050_EXT_SENS_DATA_06 = 0x4F
	MPU6050_EXT_SENS_DATA_07 = 0x50
	MPU6050_EXT_SENS_DATA_08 = 0x51
	MPU6050_EXT_SENS_DATA_09 = 0x52
	MPU6050_EXT_SENS_DATA_10 = 0x53
	MPU6050_EXT_SENS_DATA_11 = 0x54
	MPU6050_EXT_SENS_DATA_12 = 0x55
	MPU6050_EXT_SENS_DATA_13 = 0x56
	MPU6050_EXT_SENS_DATA_14 = 0x57
	MPU6050_EXT_SENS_DATA_15 = 0x58
	MPU6050_EXT_SENS_DATA_16 = 0x59
	MPU6050_EXT_SENS_DATA_17 = 0x5A
	MPU6050_EXT_SENS_DATA_18 = 0x5B
	MPU6050_EXT_SENS_DATA_19 = 0x5C
	MPU6050_EXT_SENS_DATA_20 = 0x5D
	MPU6050_EXT_SENS_DATA_21 = 0x5E
	MPU6050_EXT_SENS_DATA_22 = 0x5F
	MPU6050_EXT_SENS_DATA_23 = 0x60

	// I2C peripheral data out
	MPU6050_I2C_PER0_DO      = 0x63
	MPU6050_I2C_PER1_DO      = 0x64
	MPU6050_I2C_PER2_DO      = 0x65
	MPU6050_I2C_PER3_DO      = 0x66
	MPU6050_I2C_MST_DELAY_CT = 0x67

	MPU6050_SIGNAL_PATH_RES = 0x68 // Signal path reset
	MPU6050_USER_CTRL       = 0x6A // User control
	MPU6050_PWR_MGMT_1      = 0x6B // Power Management 1
	MPU6050_PWR_MGMT_2      = 0x6C // Power Management 2
	MPU6050_FIFO_COUNTH     = 0x72 // FIFO count registers (high bits)
	MPU6050_FIFO_COUNTL     = 0x73 // FIFO count registers (low bits)
	MPU6050_FIFO_R_W        = 0x74 // FIFO read/write
	MPU6050_WHO_AM_I        = 0x75 // Who am I
)
View Source
const Adx1345AddressHigh = 0x1D
View Source
const Adx1345AddressLow = 0x53

ADX1345 registers

View Source
const Amg88xxAddressHigh = 0x69

AMG88XX registers

View Source
const Amg88xxAddressLow = 0x68
View Source
const At24cxAddress = 0x57

AT24CX registers

View Source
const (
	BME280_SEALEVEL_PRESSURE float32 = 1013.25 // in hPa
)
View Source
const Bh1750Address = 0x23

BH1750 registers

View Source
const BlinkmAddress = 0x09

BLINKM registers

View Source
const Bme280Address = 0x76

BME280 registers

View Source
const Bmp280Address = 0x77

BMP280 registers

View Source
const Ds3231Address = 0x68

DS3231 registers

View Source
const Ina250Address = 0x40

INA250 registers

View Source
const Lps22hbAddress = 0x5C

LPS22HB registers

View Source
const Mpu6050Address = 0x68

MPU6050 registers

Variables

This section is empty.

Functions

This section is empty.

Types

type Adxl345

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

func (Adxl345) Halt

func (d Adxl345) Halt()

Halt stops the sensor, values will not updated

func (Adxl345) ReadAcceleration

func (d Adxl345) 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.

func (Adxl345) ReadRawAcceleration

func (d Adxl345) ReadRawAcceleration() (x int32, y int32, z int32)

ReadRawAcceleration reads the sensor values and returns the raw x, y and z axis from the adxl345.

func (Adxl345) Restart

func (d Adxl345) Restart()

Restart makes reading the sensor working again after a halt

func (Adxl345) SetRange

func (d Adxl345) SetRange(sensorRange Adxl345Range) bool

SetRange change the current range of the sensor

func (Adxl345) SetRate

func (d Adxl345) SetRate(rate Adxl345Rate) bool

SetRate change the current rate of the sensor

func (Adxl345) UseLowPower

func (d Adxl345) UseLowPower(power bool)

UseLowPower sets the ADXL345 to use the low power mode.

type Adxl345Range

type Adxl345Range uint8

type Adxl345Rate

type Adxl345Rate uint8

type Amg88xx

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

func (Amg88xx) ClearInterrupt

func (d Amg88xx) ClearInterrupt()

func (Amg88xx) DisableInterrupt

func (d Amg88xx) DisableInterrupt()

func (Amg88xx) EnableInterrupt

func (d Amg88xx) EnableInterrupt()

func (Amg88xx) GetInterrupt

func (d Amg88xx) GetInterrupt() []uint8

func (Amg88xx) ReadPixels

func (d Amg88xx) ReadPixels(buffer *[64]int16)

ReadPixels returns the 64 values (8x8 grid) of the sensor converted to millicelsius

func (Amg88xx) ReadThermistor

func (d Amg88xx) ReadThermistor() int16

func (Amg88xx) SetFrameRate

func (d Amg88xx) SetFrameRate(framerate uint8)

func (Amg88xx) SetInterruptLevels

func (d Amg88xx) SetInterruptLevels(high int16, low int16)

func (Amg88xx) SetInterruptLevelsHysteresis

func (d Amg88xx) SetInterruptLevelsHysteresis(high int16, low int16, hysteresis int16)

func (Amg88xx) SetInterruptMode

func (d Amg88xx) SetInterruptMode(mode Amg88xxInterruptMode)

func (Amg88xx) SetMovingAverageMode

func (d Amg88xx) SetMovingAverageMode(mode bool)

func (Amg88xx) SetPCTL

func (d Amg88xx) SetPCTL(pctl uint8)

func (Amg88xx) SetReset

func (d Amg88xx) SetReset(rst uint8)

type Amg88xxInterruptMode

type Amg88xxInterruptMode uint8

type Bh1750

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

func (Bh1750) Illuminance

func (d Bh1750) Illuminance() int32

func (Bh1750) RawSensorData

func (d Bh1750) RawSensorData() uint16

func (Bh1750) SetMode

func (d Bh1750) SetMode(mode byte)

type Blinkm

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

func (Blinkm) FadeToRGB

func (d Blinkm) FadeToRGB(r, g, b byte) error

func (Blinkm) GetRGB

func (d Blinkm) GetRGB() (r, g, b byte, err error)

func (Blinkm) SetRGB

func (d Blinkm) SetRGB(r, g, b byte) error

func (Blinkm) StopScript

func (d Blinkm) StopScript() error

func (Blinkm) Version

func (d Blinkm) Version() (major, minor byte, err error)

type Bme280

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

func (Bme280) ReadAltitude

func (d Bme280) ReadAltitude() (alt int32, err error)

func (Bme280) ReadHumidity

func (d Bme280) ReadHumidity() (int32, error)

func (Bme280) ReadPressure

func (d Bme280) ReadPressure() (int32, error)

func (Bme280) ReadTemperature

func (d Bme280) ReadTemperature() (int32, error)

func (Bme280) Reset

func (d Bme280) Reset()

type Bmp280

type Bmp280 struct {
	Address uint16

	Temperature uint
	Pressure    uint
	Mode        uint
	Standby     uint
	Filter      uint
	// contains filtered or unexported fields
}

func (Bmp280) ReadPressure

func (d Bmp280) ReadPressure() (pressure int32, err error)

func (Bmp280) ReadTemperature

func (d Bmp280) ReadTemperature() (temperature int32, err error)

func (Bmp280) Reset

func (d Bmp280) Reset()

type Devices

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

func NewDevice

func NewDevice(bus I2C, deviceName string, addr uint16, bmp280Settings [5]uint) (Devices, error)

The BMP280 Temperature, Humidity, and Berometric Pressure sensor by Bosch Sensortech requires some settings to be passed in as an array with a length of 5, of uint values to set Standby, Filter, Temperature, Pressure, and Mode

type Ds3231

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

func (Ds3231) IsRunning

func (d Ds3231) IsRunning() bool

IsRunning returns if the oscillator is running

func (Ds3231) IsTimeValid

func (d Ds3231) IsTimeValid() bool

IsTimeValid return true/false is the time in the device is valid

func (Ds3231) ReadTemperature

func (d Ds3231) ReadTemperature() (int32, error)

ReadTemperature returns the temperature in millicelsius (mC)

func (Ds3231) ReadTime

func (d Ds3231) ReadTime() (dt time.Time, err error)

ReadTime returns the date and time

func (Ds3231) SetRunning

func (d Ds3231) SetRunning(isRunning bool) error

SetRunning starts the internal oscillator

func (Ds3231) SetTime

func (d Ds3231) SetTime(dt time.Time) error

SetTime sets the date and time in the DS3231

type Ds3231Mode

type Ds3231Mode uint8

type I2C

type I2C interface {
	ReadRegister(addr uint8, r uint8, buf []byte) error
	WriteRegister(addr uint8, r uint8, buf []byte) error
	Tx(addr uint16, w, r []byte) error
}

I2C represents an I2C bus. It is notably implemented by the machine.I2C type.

type Lis3dh

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

func (Lis3dh) ReadAcceleration

func (d Lis3dh) ReadAcceleration() (int32, int32, int32, 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.

func (*Lis3dh) ReadRange

func (d *Lis3dh) ReadRange() (r Lis3dhRange)

func (Lis3dh) ReadRawAcceleration

func (d Lis3dh) ReadRawAcceleration() (x int16, y int16, z int16)

ReadRawAcceleration returns the raw x, y and z axis from the LIS3DH

func (Lis3dh) SetDataRate

func (d Lis3dh) SetDataRate(rate Lis3dhDataRate)

func (*Lis3dh) SetRange

func (d *Lis3dh) SetRange(r Lis3dhRange)

SetRange sets the G range for LIS3DH.

type Lis3dhDataRate

type Lis3dhDataRate uint8

type Lis3dhRange

type Lis3dhRange uint8

type Lis3dhRate

type Lis3dhRate uint8

type Lps22hb

type Lps22hb struct {
	Address uint8
	// contains filtered or unexported fields
}

func (Lps22hb) ReadPressure

func (d Lps22hb) ReadPressure() (pressure int32, err error)

ReadPressure returns the pressure in milli pascals (mPa).

func (Lps22hb) ReadTemperature

func (d Lps22hb) ReadTemperature() (temperature int32, err error)

ReadTemperature returns the temperature in celsius milli degrees (°C/1000).

type Mpu6050

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

func (Mpu6050) ReadAcceleration

func (d Mpu6050) ReadAcceleration() (x int32, y int32, z int32)

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.

func (Mpu6050) ReadRotation

func (d Mpu6050) ReadRotation() (x int32, y int32, z int32)

ReadRotation reads the current rotation from the device and returns it in µ°/s (micro-degrees/sec). This means that if you were to do a complete rotation along one axis and while doing so integrate all values over time, you would get a value close to 360000000.

Jump to

Keyboard shortcuts

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