Documentation ¶
Overview ¶
Package spi provides Gobot drivers for spi devices. Uses periph.io for spi Installing:
go get -d -u gobot.io/x/gobot/v2
For further information refer to spi README: https://github.com/hybridgroup/gobot/blob/master/drivers/spi/README.md
Index ¶
- Constants
- func NewConnection(spiSystem gobot.SpiSystemDevicer) *spiConnection
- func WithBitCount(bitCount int) func(Config)
- func WithBusNumber(busNum int) func(Config)
- func WithChipNumber(chipNum int) func(Config)
- func WithDCPin(val string) func(Config)
- func WithDisplayHeight(val int) func(Config)
- func WithDisplayWidth(val int) func(Config)
- func WithExternalVCC(val bool) func(Config)
- func WithMode(mode int) func(Config)
- func WithRstPin(val string) func(Config)
- func WithSpeed(speed int64) func(Config)
- type APA102Driver
- type Config
- type Connection
- type Connector
- type DisplayBuffer
- type Driver
- type MCP3002Driver
- type MCP3004Driver
- type MCP3008Driver
- type MCP3202Driver
- type MCP3204Driver
- type MCP3208Driver
- type MCP3304Driver
- type MFRC522Driver
- type SSD1306Driver
- func (s *SSD1306Driver) Clear() error
- func (s *SSD1306Driver) Display() error
- func (s *SSD1306Driver) Off() error
- func (s *SSD1306Driver) On() error
- func (s *SSD1306Driver) Reset() error
- func (s *SSD1306Driver) Set(x, y, c int)
- func (s *SSD1306Driver) SetBufferAndDisplay(buf []byte) error
- func (s *SSD1306Driver) SetContrast(contrast byte) error
- func (s *SSD1306Driver) ShowImage(img image.Image) error
Constants ¶
const MCP3002DriverMaxChannel = 2
MCP3002DriverMaxChannel is the number of channels of this A/D converter.
const MCP3004DriverMaxChannel = 4
MCP3004DriverMaxChannel is the number of channels of this A/D converter.
const MCP3008DriverMaxChannel = 8
MCP3008DriverMaxChannel is the number of channels of this A/D converter.
const MCP3202DriverMaxChannel = 2
MCP3202DriverMaxChannel is the number of channels of this A/D converter.
const MCP3204DriverMaxChannel = 4
MCP3204DriverMaxChannel is the number of channels of this A/D converter.
const MCP3208DriverMaxChannel = 8
MCP3208DriverMaxChannel is the number of channels of this A/D converter.
const MCP3304DriverMaxChannel = 8
MCP3304DriverMaxChannel is the number of channels of this A/D converter.
const (
// NotInitialized is the initial value for a bus/chip
NotInitialized = -1
)
Variables ¶
This section is empty.
Functions ¶
func NewConnection ¶
func NewConnection(spiSystem gobot.SpiSystemDevicer) *spiConnection
NewConnection uses the given SPI system device and provides it as gobot.SpiOperations and Implements gobot.BusOperations.
func WithBitCount ¶
WithBitCount sets how many bits to use as a optional param.
func WithBusNumber ¶
WithBusNumber sets which bus to use as a optional param.
func WithChipNumber ¶
WithChipNumber sets which chip to use as a optional param.
func WithDisplayHeight ¶ added in v1.12.0
WithDisplayHeight option sets the SSD1306Driver DisplayHeight option.
func WithDisplayWidth ¶ added in v1.12.0
WithDisplayWidth option sets the SSD1306Driver DisplayWidth option.
func WithExternalVCC ¶ added in v1.12.0
WithExternalVCC option sets the SSD1306Driver external vcc option.
func WithRstPin ¶ added in v1.12.0
WithRstPin option sets the SSD1306Driver RST pin option.
Types ¶
type APA102Driver ¶ added in v1.8.0
type APA102Driver struct { *Driver // contains filtered or unexported fields }
APA102Driver is a driver for the APA102 programmable RGB LEDs.
func NewAPA102Driver ¶ added in v1.8.0
func NewAPA102Driver(a Connector, count int, bright uint8, options ...func(Config)) *APA102Driver
NewAPA102Driver creates a new Gobot Driver for APA102 RGB LEDs.
Params:
a *Adaptor - the Adaptor to use with this Driver. count int - how many LEDs are in the array controlled by this driver. bright - the default brightness to apply for all LEDs (must be between 0 and 31).
Optional params:
spi.WithBusNumber(int): bus to use with this driver. spi.WithChipNumber(int): chip to use with this driver. spi.WithMode(int): mode to use with this driver. spi.WithBitCount(int): number of bits to use with this driver. spi.WithSpeed(int64): speed in Hz to use with this driver.
func (*APA102Driver) Brightness ¶ added in v1.14.0
func (d *APA102Driver) Brightness() uint8
Brightness return driver brightness value.
func (*APA102Driver) Draw ¶ added in v1.8.0
func (d *APA102Driver) Draw() error
Draw displays the RGBA values set on the actual LED strip.
func (*APA102Driver) SetBrightness ¶ added in v1.14.0
func (d *APA102Driver) SetBrightness(i uint8)
SetBrightness sets the ith LED's brightness to the given value. Must be between 0 and 31.
type Config ¶
type Config interface { // SetBusNumber sets which bus to use SetBusNumber(int) // GetBusNumberOrDefault gets which bus to use GetBusNumberOrDefault(def int) int // SetChipNumber sets which chip to use SetChipNumber(int) // GetChipNumberOrDefault gets which chip to use GetChipNumberOrDefault(def int) int // SetMode sets which mode to use SetMode(int) // GetModeOrDefault gets which mode to use GetModeOrDefault(def int) int // SetUsedBits sets how many bits to use SetBitCount(int) // GetBitCountOrDefault gets how many bits to use GetBitCountOrDefault(def int) int // SetSpeed sets which speed to use (in Hz) SetSpeed(int64) // GetSpeedOrDefault gets which speed to use (in Hz) GetSpeedOrDefault(def int64) int64 }
Config is the interface which describes how a Driver can specify optional SPI params such as which SPI bus it wants to use.
type Connection ¶
type Connection gobot.SpiOperations
Connection is a connection to a SPI device with a specific bus/chip. Provided by an Adaptor, usually just by calling the spi package's GetSpiConnection() function.
type Connector ¶
type Connector interface { // GetSpiConnection returns a connection to a SPI device at the specified bus and chip. // Bus numbering starts at index 0, the range of valid buses is // platform specific. Same with chip numbering. GetSpiConnection(busNum, chip, mode, bits int, maxSpeed int64) (device Connection, err error) // SpiDefaultBusNumber returns the default SPI bus index SpiDefaultBusNumber() int // SpiDefaultChipNumber returns the default SPI chip index SpiDefaultChipNumber() int // DefaultMode returns the default SPI mode (0/1/2/3) SpiDefaultMode() int // SpiDefaultBitCount returns the default SPI number of bits (8) SpiDefaultBitCount() int // SpiDefaultMaxSpeed returns the max SPI speed SpiDefaultMaxSpeed() int64 }
Connector lets Adaptors provide the interface for Drivers to get access to the SPI buses on platforms that support SPI.
type DisplayBuffer ¶ added in v1.12.0
type DisplayBuffer struct {
// contains filtered or unexported fields
}
DisplayBuffer represents the display buffer intermediate memory
func NewDisplayBuffer ¶ added in v1.12.0
func NewDisplayBuffer(width, height, pageSize int) *DisplayBuffer
NewDisplayBuffer creates a new DisplayBuffer
func (*DisplayBuffer) Clear ¶ added in v1.12.0
func (d *DisplayBuffer) Clear()
Clear the contents of the display buffer
func (*DisplayBuffer) Set ¶ added in v1.12.0
func (d *DisplayBuffer) Set(buf []byte)
Set sets the display buffer with the given buffer
func (*DisplayBuffer) SetPixel ¶ added in v1.12.0
func (d *DisplayBuffer) SetPixel(x, y, c int)
SetPixel sets the x, y pixel with c color
func (*DisplayBuffer) Size ¶ added in v1.12.0
func (d *DisplayBuffer) Size() int
Size returns the memory size of the display buffer
type Driver ¶
type Driver struct { Config gobot.Commander // contains filtered or unexported fields }
Driver implements the interface gobot.Driver for SPI devices.
func (*Driver) Connection ¶
func (d *Driver) Connection() gobot.Connection
Connection returns the Connection of the device.
type MCP3002Driver ¶ added in v1.8.0
type MCP3002Driver struct {
*Driver
}
MCP3002Driver is a driver for the MCP3002 A/D converter.
func NewMCP3002Driver ¶ added in v1.8.0
func NewMCP3002Driver(a Connector, options ...func(Config)) *MCP3002Driver
NewMCP3002Driver creates a new Gobot Driver for MCP3002 A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3002Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3002Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin
type MCP3004Driver ¶ added in v1.8.0
type MCP3004Driver struct {
*Driver
}
MCP3004Driver is a driver for the MCP3008 A/D converter.
func NewMCP3004Driver ¶ added in v1.8.0
func NewMCP3004Driver(a Connector, options ...func(Config)) *MCP3004Driver
NewMCP3004Driver creates a new Gobot Driver for MCP3004 A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3004Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3004Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin
type MCP3008Driver ¶ added in v1.8.0
type MCP3008Driver struct {
*Driver
}
MCP3008Driver is a driver for the MCP3008 A/D converter.
func NewMCP3008Driver ¶ added in v1.8.0
func NewMCP3008Driver(a Connector, options ...func(Config)) *MCP3008Driver
NewMCP3008Driver creates a new Gobot Driver for MCP3008Driver A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3008Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3008Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin
type MCP3202Driver ¶ added in v1.8.0
type MCP3202Driver struct {
*Driver
}
MCP3202Driver is a driver for the MCP3202 A/D converter.
func NewMCP3202Driver ¶ added in v1.8.0
func NewMCP3202Driver(a Connector, options ...func(Config)) *MCP3202Driver
NewMCP3202Driver creates a new Gobot Driver for MCP3202Driver A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3202Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3202Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.
type MCP3204Driver ¶ added in v1.8.0
type MCP3204Driver struct {
*Driver
}
MCP3204Driver is a driver for the MCP3204 A/D converter.
func NewMCP3204Driver ¶ added in v1.8.0
func NewMCP3204Driver(a Connector, options ...func(Config)) *MCP3204Driver
NewMCP3204Driver creates a new Gobot Driver for MCP3204Driver A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3204Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3204Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.
type MCP3208Driver ¶ added in v1.8.0
type MCP3208Driver struct {
*Driver
}
MCP3208Driver is a driver for the MCP3208 A/D converter.
func NewMCP3208Driver ¶ added in v1.8.0
func NewMCP3208Driver(a Connector, options ...func(Config)) *MCP3208Driver
NewMCP3208Driver creates a new Gobot Driver for MCP3208Driver A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3208Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3208Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.
type MCP3304Driver ¶ added in v1.8.0
type MCP3304Driver struct {
*Driver
}
MCP3304Driver is a driver for the MCP3304 A/D converter.
func NewMCP3304Driver ¶ added in v1.8.0
func NewMCP3304Driver(a Connector, options ...func(Config)) *MCP3304Driver
NewMCP3304Driver creates a new Gobot Driver for MCP3304Driver A/D converter
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
func (*MCP3304Driver) AnalogRead ¶ added in v1.8.0
func (d *MCP3304Driver) AnalogRead(pin string) (value int, err error)
AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.
type MFRC522Driver ¶
type MFRC522Driver struct { *Driver *mfrc522.MFRC522Common }
MFRC522Driver is a wrapper for SPI bus usage. Please refer to the mfrc522.MFRC522Common package for implementation details.
func NewMFRC522Driver ¶
func NewMFRC522Driver(a Connector, options ...func(Config)) *MFRC522Driver
NewMFRC522Driver creates a new Gobot Driver for MFRC522 RFID with SPI connection
Params:
a *Adaptor - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver
type SSD1306Driver ¶ added in v1.12.0
type SSD1306Driver struct { *Driver DisplayWidth int DisplayHeight int DCPin string RSTPin string ExternalVcc bool // contains filtered or unexported fields }
SSD1306Driver is a Gobot Driver for a SSD1306 Display
func NewSSD1306Driver ¶ added in v1.12.0
func NewSSD1306Driver(a gobot.Adaptor, options ...func(Config)) *SSD1306Driver
NewSSD1306Driver creates a new SSD1306Driver.
Params:
conn Connector - the Adaptor to use with this Driver
Optional params:
spi.WithBusNumber(int): bus to use with this driver spi.WithChipNumber(int): chip to use with this driver spi.WithMode(int): mode to use with this driver spi.WithBitCount(int): number of bits to use with this driver spi.WithSpeed(int64): speed in Hz to use with this driver spi.WithDisplayWidth(int): width of display (defaults to 128) spi.WithDisplayHeight(int): height of display (defaults to 64) spi.WithDCPin(string): gpio pin number connected to dc pin on display (defaults to "16") spi.WithRstPin(string): gpio pin number connected to rst pin on display (defaults to "18") spi.WithExternalVCC(bool): set to true if using external vcc (defaults to false)
func (*SSD1306Driver) Clear ¶ added in v1.12.0
func (s *SSD1306Driver) Clear() error
Clear clears the display buffer.
func (*SSD1306Driver) Display ¶ added in v1.12.0
func (s *SSD1306Driver) Display() error
Display sends the memory buffer to the display.
func (*SSD1306Driver) Off ¶ added in v1.12.0
func (s *SSD1306Driver) Off() error
Off turns off the display.
func (*SSD1306Driver) On ¶ added in v1.12.0
func (s *SSD1306Driver) On() error
On turns on the display.
func (*SSD1306Driver) Reset ¶ added in v1.12.0
func (s *SSD1306Driver) Reset() error
Reset re-initializes the device to a clean state.
func (*SSD1306Driver) Set ¶ added in v1.12.0
func (s *SSD1306Driver) Set(x, y, c int)
Set sets a pixel in the display buffer.
func (*SSD1306Driver) SetBufferAndDisplay ¶ added in v1.12.0
func (s *SSD1306Driver) SetBufferAndDisplay(buf []byte) error
SetBufferAndDisplay sets the display buffer with the given buffer and displays the image.
func (*SSD1306Driver) SetContrast ¶ added in v1.12.0
func (s *SSD1306Driver) SetContrast(contrast byte) error
SetContrast sets the display contrast (0-255).