i2c

package
v0.0.0-...-d18d6cd Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2015 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

README

I2C

This package provides drivers for i2cdevices . It is normally not used directly, but instead is registered by an adaptor such as firmata that supports the needed interfaces for i2c devices.

Getting Started

Installing

go get -d -u github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/i2c

Hardware Support

Gobot has a extensible system for connecting to hardware devices. The following i2c devices are currently supported:

  • BlinkM
  • HMC6352 Digital Compass
  • MPL115A2 Barometer/Temperature Sensor
  • MPU6050 Accelerometer/Gyroscope
  • Wii Nunchuck Controller

More drivers are coming soon...

Documentation

Overview

Package i2c provides Gobot drivers for i2c devices.

Installing:

go get github.com/hybridgroup/gobot/platforms/i2c

For further information refer to i2c README: https://github.com/hybridgroup/gobot/blob/master/platforms/i2c/README.md

Index

Constants

View Source
const (
	Error    = "error"
	Joystick = "joystick"
	C        = "c"
	Z        = "z"
)
View Source
const (
	REG_RED   = 0x04
	REG_GREEN = 0x03
	REG_BLUE  = 0x02

	LCD_CLEARDISPLAY        = 0x01
	LCD_RETURNHOME          = 0x02
	LCD_ENTRYMODESET        = 0x04
	LCD_DISPLAYCONTROL      = 0x08
	LCD_CURSORSHIFT         = 0x10
	LCD_FUNCTIONSET         = 0x20
	LCD_SETCGRAMADDR        = 0x40
	LCD_SETDDRAMADDR        = 0x80
	LCD_ENTRYRIGHT          = 0x00
	LCD_ENTRYLEFT           = 0x02
	LCD_ENTRYSHIFTINCREMENT = 0x01
	LCD_ENTRYSHIFTDECREMENT = 0x00
	LCD_DISPLAYON           = 0x04
	LCD_DISPLAYOFF          = 0x00
	LCD_CURSORON            = 0x02
	LCD_CURSOROFF           = 0x00
	LCD_BLINKON             = 0x01
	LCD_BLINKOFF            = 0x00
	LCD_DISPLAYMOVE         = 0x08
	LCD_CURSORMOVE          = 0x00
	LCD_MOVERIGHT           = 0x04
	LCD_MOVELEFT            = 0x00
	LCD_2LINE               = 0x08
)
View Source
const (
	MMA7660_X              = 0x00
	MMA7660_Y              = 0x01
	MMA7660_Z              = 0x02
	MMA7660_TILT           = 0x03
	MMA7660_SRST           = 0x04
	MMA7660_SPCNT          = 0x05
	MMA7660_INTSU          = 0x06
	MMA7660_MODE           = 0x07
	MMA7660_STAND_BY       = 0x00
	MMA7660_ACTIVE         = 0x01
	MMA7660_SR             = 0x08
	MMA7660_AUTO_SLEEP_120 = 0x00
	MMA7660_AUTO_SLEEP_64  = 0x01
	MMA7660_AUTO_SLEEP_32  = 0x02
	MMA7660_AUTO_SLEEP_16  = 0x03
	MMA7660_AUTO_SLEEP_8   = 0x04
	MMA7660_AUTO_SLEEP_4   = 0x05
	MMA7660_AUTO_SLEEP_2   = 0x06
	MMA7660_AUTO_SLEEP_1   = 0x07
	MMA7660_PDET           = 0x09
	MMA7660_PD             = 0x0A
)
View Source
const MPL115A2_REGISTER_A0_COEFF_LSB = 0x05
View Source
const MPL115A2_REGISTER_A0_COEFF_MSB = 0x04
View Source
const MPL115A2_REGISTER_B1_COEFF_LSB = 0x07
View Source
const MPL115A2_REGISTER_B1_COEFF_MSB = 0x06
View Source
const MPL115A2_REGISTER_B2_COEFF_LSB = 0x09
View Source
const MPL115A2_REGISTER_B2_COEFF_MSB = 0x08
View Source
const MPL115A2_REGISTER_C12_COEFF_LSB = 0x0B
View Source
const MPL115A2_REGISTER_C12_COEFF_MSB = 0x0A
View Source
const MPL115A2_REGISTER_PRESSURE_LSB = 0x01
View Source
const MPL115A2_REGISTER_PRESSURE_MSB = 0x00
View Source
const MPL115A2_REGISTER_STARTCONVERSION = 0x12
View Source
const MPL115A2_REGISTER_TEMP_LSB = 0x03
View Source
const MPL115A2_REGISTER_TEMP_MSB = 0x02
View Source
const MPU6050_ACCEL_FS_2 = 0x00
View Source
const MPU6050_ACONFIG_AFS_SEL_BIT = 4
View Source
const MPU6050_ACONFIG_AFS_SEL_LENGTH = 2
View Source
const MPU6050_CLOCK_PLL_XGYRO = 0x01
View Source
const MPU6050_GCONFIG_FS_SEL_BIT = 4
View Source
const MPU6050_GCONFIG_FS_SEL_LENGTH = 2
View Source
const MPU6050_GYRO_FS_250 = 0x00
View Source
const MPU6050_PWR1_CLKSEL_BIT = 2
View Source
const MPU6050_PWR1_CLKSEL_LENGTH = 3
View Source
const MPU6050_PWR1_SLEEP_BIT = 6
View Source
const MPU6050_RA_ACCEL_CONFIG = 0x1C
View Source
const MPU6050_RA_ACCEL_XOUT_H = 0x3B
View Source
const MPU6050_RA_GYRO_CONFIG = 0x1B
View Source
const MPU6050_RA_PWR_MGMT_1 = 0x6B

Variables

View Source
var (
	ErrEncryptedBytes = errors.New("Encrypted bytes")
	ErrNotEnoughBytes = errors.New("Not enough bytes read")
	ErrNotReady       = errors.New("Device is not ready")
)

Functions

This section is empty.

Types

type BlinkMDriver

type BlinkMDriver struct {
	gobot.Commander
	// contains filtered or unexported fields
}

func NewBlinkMDriver

func NewBlinkMDriver(a I2c, name string) *BlinkMDriver

NewBlinkMDriver creates a new BlinkMDriver with specified name.

Adds the following API commands:

Rgb - sets RGB color
Fade - fades the RGB color
FirmwareVersion - returns the version of the current Frimware
Color - returns the color of the LED.

func (*BlinkMDriver) Color

func (b *BlinkMDriver) Color() (color []byte, err error)

Color returns an array with current rgb color

func (*BlinkMDriver) Connection

func (b *BlinkMDriver) Connection() gobot.Connection

func (*BlinkMDriver) Fade

func (b *BlinkMDriver) Fade(red byte, green byte, blue byte) (err error)

Fade removes color using r,g,b params

func (*BlinkMDriver) FirmwareVersion

func (b *BlinkMDriver) FirmwareVersion() (version string, err error)

FirmwareVersion returns version with MAYOR.minor format

func (*BlinkMDriver) Halt

func (b *BlinkMDriver) Halt() (errs []error)

Halt returns true if device is halted successfully

func (*BlinkMDriver) Name

func (b *BlinkMDriver) Name() string

func (*BlinkMDriver) Rgb

func (b *BlinkMDriver) Rgb(red byte, green byte, blue byte) (err error)

Rgb sets color using r,g,b params

func (*BlinkMDriver) Start

func (b *BlinkMDriver) Start() (errs []error)

Start writes start bytes

type GroveAccelerometerDriver

type GroveAccelerometerDriver struct {
	*MMA7660Driver
}

func NewGroveAccelerometerDriver

func NewGroveAccelerometerDriver(a I2c, name string) *GroveAccelerometerDriver

type GroveLcdDriver

type GroveLcdDriver struct {
	*JHD1313M1Driver
}

func NewGroveLcdDriver

func NewGroveLcdDriver(a I2c, name string) *GroveLcdDriver

type HMC6352Driver

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

func NewHMC6352Driver

func NewHMC6352Driver(a I2c, name string) *HMC6352Driver

NewHMC6352Driver creates a new driver with specified name and i2c interface

func (*HMC6352Driver) Connection

func (h *HMC6352Driver) Connection() gobot.Connection

func (*HMC6352Driver) Halt

func (h *HMC6352Driver) Halt() (errs []error)

Halt returns true if devices is halted successfully

func (*HMC6352Driver) Heading

func (h *HMC6352Driver) Heading() (heading uint16, err error)

Heading returns the current heading

func (*HMC6352Driver) Name

func (h *HMC6352Driver) Name() string

func (*HMC6352Driver) Start

func (h *HMC6352Driver) Start() (errs []error)

Start initialized the hmc6352

type I2c

type I2c interface {
	gobot.Adaptor
	I2cStarter
	I2cReader
	I2cWriter
}

type I2cReader

type I2cReader interface {
	I2cRead(address int, len int) (data []byte, err error)
}

type I2cStarter

type I2cStarter interface {
	I2cStart(address int) (err error)
}

type I2cWriter

type I2cWriter interface {
	I2cWrite(address int, buf []byte) (err error)
}

type JHD1313M1Driver

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

func NewJHD1313M1Driver

func NewJHD1313M1Driver(a I2c, name string) *JHD1313M1Driver

NewJHD1313M1Driver creates a new driver with specified name and i2c interface

func (*JHD1313M1Driver) Clear

func (h *JHD1313M1Driver) Clear() (err error)

func (*JHD1313M1Driver) Connection

func (h *JHD1313M1Driver) Connection() gobot.Connection

func (*JHD1313M1Driver) Halt

func (h *JHD1313M1Driver) Halt() (errs []error)

func (*JHD1313M1Driver) Home

func (h *JHD1313M1Driver) Home() (err error)

func (*JHD1313M1Driver) Name

func (h *JHD1313M1Driver) Name() string

func (*JHD1313M1Driver) SetRGB

func (h *JHD1313M1Driver) SetRGB(r, g, b int) (err error)

func (*JHD1313M1Driver) Start

func (h *JHD1313M1Driver) Start() (errs []error)

func (*JHD1313M1Driver) Write

func (h *JHD1313M1Driver) Write(message string) (err error)

type LIDARLiteDriver

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

func NewLIDARLiteDriver

func NewLIDARLiteDriver(a I2c, name string) *LIDARLiteDriver

NewLIDARLiteDriver creates a new driver with specified name and i2c interface

func (*LIDARLiteDriver) Connection

func (h *LIDARLiteDriver) Connection() gobot.Connection

func (*LIDARLiteDriver) Distance

func (h *LIDARLiteDriver) Distance() (distance int, err error)

Distance returns the current distance

func (*LIDARLiteDriver) Halt

func (h *LIDARLiteDriver) Halt() (errs []error)

Halt returns true if devices is halted successfully

func (*LIDARLiteDriver) Name

func (h *LIDARLiteDriver) Name() string

func (*LIDARLiteDriver) Start

func (h *LIDARLiteDriver) Start() (errs []error)

Start initialized the LIDAR

type MMA7660Driver

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

func NewMMA7660Driver

func NewMMA7660Driver(a I2c, name string) *MMA7660Driver

NewMMA7660Driver creates a new driver with specified name and i2c interface

func (*MMA7660Driver) Acceleration

func (h *MMA7660Driver) Acceleration(x, y, z float64) (ax, ay, az float64)

Acceleration returns the acceleration of the provided x, y, z

func (*MMA7660Driver) Connection

func (h *MMA7660Driver) Connection() gobot.Connection

func (*MMA7660Driver) Halt

func (h *MMA7660Driver) Halt() (errs []error)

Halt returns true if devices is halted successfully

func (*MMA7660Driver) Name

func (h *MMA7660Driver) Name() string

func (*MMA7660Driver) Start

func (h *MMA7660Driver) Start() (errs []error)

Start initialized the mma7660

func (*MMA7660Driver) XYZ

func (h *MMA7660Driver) XYZ() (x float64, y float64, z float64, err error)

XYZ returns the raw x,y and z axis from the mma7660

type MPL115A2Driver

type MPL115A2Driver struct {
	gobot.Eventer
	A0          float32
	B1          float32
	B2          float32
	C12         float32
	Pressure    float32
	Temperature float32
	// contains filtered or unexported fields
}

func NewMPL115A2Driver

func NewMPL115A2Driver(a I2c, name string, v ...time.Duration) *MPL115A2Driver

NewMPL115A2Driver creates a new driver with specified name and i2c interface

func (*MPL115A2Driver) Connection

func (h *MPL115A2Driver) Connection() gobot.Connection

func (*MPL115A2Driver) Halt

func (h *MPL115A2Driver) Halt() (err []error)

Halt returns true if devices is halted successfully

func (*MPL115A2Driver) Name

func (h *MPL115A2Driver) Name() string

func (*MPL115A2Driver) Start

func (h *MPL115A2Driver) Start() (errs []error)

Start writes initialization bytes and reads from adaptor using specified interval to accelerometer andtemperature data

type MPU6050Driver

type MPU6050Driver struct {
	Accelerometer ThreeDData
	Gyroscope     ThreeDData
	Temperature   int16
	gobot.Eventer
	// contains filtered or unexported fields
}

func NewMPU6050Driver

func NewMPU6050Driver(a I2c, name string, v ...time.Duration) *MPU6050Driver

NewMPU6050Driver creates a new driver with specified name and i2c interface

func (*MPU6050Driver) Connection

func (h *MPU6050Driver) Connection() gobot.Connection

func (*MPU6050Driver) Halt

func (h *MPU6050Driver) Halt() (errs []error)

Halt returns true if devices is halted successfully

func (*MPU6050Driver) Name

func (h *MPU6050Driver) Name() string

func (*MPU6050Driver) Start

func (h *MPU6050Driver) Start() (errs []error)

Start writes initialization bytes and reads from adaptor using specified interval to accelerometer andtemperature data

type ThreeDData

type ThreeDData struct {
	X int16
	Y int16
	Z int16
}

type WiichuckDriver

type WiichuckDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

func NewWiichuckDriver

func NewWiichuckDriver(a I2c, name string, v ...time.Duration) *WiichuckDriver

NewWiichuckDriver creates a WiichuckDriver with specified i2c interface and name.

It adds the following events:

"z"- Get's triggered every interval amount of time if the z button is pressed
"c" - Get's triggered every interval amount of time if the c button is pressed
"joystick" - Get's triggered every "interval" amount of time if a joystick event occured, you can access values x, y

func (*WiichuckDriver) Connection

func (w *WiichuckDriver) Connection() gobot.Connection

func (*WiichuckDriver) Halt

func (w *WiichuckDriver) Halt() (errs []error)

Halt returns true if driver is halted successfully

func (*WiichuckDriver) Name

func (w *WiichuckDriver) Name() string

func (*WiichuckDriver) Start

func (w *WiichuckDriver) Start() (errs []error)

Start initilizes i2c and reads from adaptor using specified interval to update with new value

Jump to

Keyboard shortcuts

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