gobot: gobot.io/x/gobot/drivers/spi Index | Files

package spi

import "gobot.io/x/gobot/drivers/spi"

Package spi provides Gobot drivers for spi devices. Uses periph.io for spi Installing:

go get -d -u gobot.io/x/gobot

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

Index

Package Files

apa102.go doc.go mcp3002.go mcp3004.go mcp3008.go mcp3202.go mcp3204.go mcp3208.go mcp3304.go spi.go spi_config.go ssd1306_driver.go

Constants

const MCP3002DriverMaxChannel = 2

MCP3002DriverMaxChannel is the number of channels of this A/D converter.

const MCP3004DriverMaxChannel = 3

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
)

func WithBits Uses

func WithBits(bits int) func(Config)

WithBits sets how many bits to use as a optional param.

func WithBus Uses

func WithBus(bus int) func(Config)

WithBus sets which bus to use as a optional param.

func WithChip Uses

func WithChip(chip int) func(Config)

WithChip sets which chip to use as a optional param.

func WithDCPin Uses

func WithDCPin(val string) func(Config)

WithDCPin option sets the SSD1306Driver DC Pin option.

func WithDisplayHeight Uses

func WithDisplayHeight(val int) func(Config)

WithDisplayHeight option sets the SSD1306Driver DisplayHeight option.

func WithDisplayWidth Uses

func WithDisplayWidth(val int) func(Config)

WithDisplayWidth option sets the SSD1306Driver DisplayWidth option.

func WithExternalVCC Uses

func WithExternalVCC(val bool) func(Config)

WithExternalVCC option sets the SSD1306Driver external vcc option.

func WithMode Uses

func WithMode(mode int) func(Config)

WithMode sets which mode to use as a optional param.

func WithRstPin Uses

func WithRstPin(val string) func(Config)

WithRstPin option sets the SSD1306Driver RST pin option.

func WithSpeed Uses

func WithSpeed(speed int64) func(Config)

WithSpeed sets what speed to use as a optional param.

type APA102Driver Uses

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

APA102Driver is a driver for the APA102 programmable RGB LEDs.

func NewAPA102Driver Uses

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.WithBus(int):    	  bus to use with this driver.
spi.WithChip(int):    	chip to use with this driver.
spi.WithMode(int):    	mode to use with this driver.
spi.WithBits(int):    	number of bits to use with this driver.
spi.WithSpeed(int64):   speed in Hz to use with this driver.

func (*APA102Driver) Brightness Uses

func (d *APA102Driver) Brightness() uint8

Brightness return driver brightness value.

func (*APA102Driver) Connection Uses

func (d *APA102Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*APA102Driver) Draw Uses

func (d *APA102Driver) Draw() error

Draw displays the RGBA values set on the actual LED strip.

func (*APA102Driver) Halt Uses

func (d *APA102Driver) Halt() (err error)

Halt stops the driver.

func (*APA102Driver) Name Uses

func (d *APA102Driver) Name() string

Name returns the name of the device.

func (*APA102Driver) SetBrightness Uses

func (d *APA102Driver) SetBrightness(i uint8)

SetBrightness sets the ith LED's brightness to the given value. Must be between 0 and 31.

func (*APA102Driver) SetName Uses

func (d *APA102Driver) SetName(n string)

SetName sets the name of the device.

func (*APA102Driver) SetRGBA Uses

func (d *APA102Driver) SetRGBA(i int, v color.RGBA)

SetRGBA sets the ith LED's color to the given RGBA value. A subsequent call to Draw is required to transmit values to the LED strip.

func (*APA102Driver) Start Uses

func (d *APA102Driver) Start() (err error)

Start initializes the driver.

type Config Uses

type Config interface {
    // WithBus sets which bus to use
    WithBus(bus int)

    // GetBusOrDefault gets which bus to use
    GetBusOrDefault(def int) int

    // WithChip sets which chip to use
    WithChip(chip int)

    // GetChipOrDefault gets which chip to use
    GetChipOrDefault(def int) int

    // WithMode sets which mode to use
    WithMode(mode int)

    // GetModeOrDefault gets which mode to use
    GetModeOrDefault(def int) int

    // WithBIts sets how many bits to use
    WithBits(bits int)

    // GetBitsOrDefault gets how many bits to use
    GetBitsOrDefault(def int) int

    // WithSpeed sets which speed to use (in Hz)
    WithSpeed(speed 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.

func NewConfig Uses

func NewConfig() Config

NewConfig returns a new SPI Config.

type Connection Uses

type Connection Operations

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.

func GetSpiConnection Uses

func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Connection, error)

GetSpiConnection is a helper to return a SPI device.

type Connector Uses

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)

    // GetSpiDefaultBus returns the default SPI bus index
    GetSpiDefaultBus() int

    // GetSpiDefaultChip returns the default SPI chip index
    GetSpiDefaultChip() int

    // GetDefaultMode returns the default SPI mode (0/1/2/3)
    GetSpiDefaultMode() int

    // GetDefaultMode returns the default SPI number of bits (8)
    GetSpiDefaultBits() int

    // GetSpiDefaultMaxSpeed returns the max SPI speed
    GetSpiDefaultMaxSpeed() int64
}

Connector lets Adaptors provide the interface for Drivers to get access to the SPI buses on platforms that support SPI.

type DisplayBuffer Uses

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

DisplayBuffer represents the display buffer intermediate memory

func NewDisplayBuffer Uses

func NewDisplayBuffer(width, height, pageSize int) *DisplayBuffer

NewDisplayBuffer creates a new DisplayBuffer

func (*DisplayBuffer) Clear Uses

func (d *DisplayBuffer) Clear()

Clear the contents of the display buffer

func (*DisplayBuffer) Set Uses

func (d *DisplayBuffer) Set(buf []byte)

Set sets the display buffer with the given buffer

func (*DisplayBuffer) SetPixel Uses

func (d *DisplayBuffer) SetPixel(x, y, c int)

SetPixel sets the x, y pixel with c color

func (*DisplayBuffer) Size Uses

func (d *DisplayBuffer) Size() int

Size returns the memory size of the display buffer

type MCP3002Driver Uses

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

MCP3002Driver is a driver for the MCP3002 A/D converter.

func NewMCP3002Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3002Driver) AnalogRead Uses

func (d *MCP3002Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin

func (*MCP3002Driver) Connection Uses

func (d *MCP3002Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3002Driver) Halt Uses

func (d *MCP3002Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3002Driver) Name Uses

func (d *MCP3002Driver) Name() string

Name returns the name of the device.

func (*MCP3002Driver) Read Uses

func (d *MCP3002Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3002Driver) SetName Uses

func (d *MCP3002Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3002Driver) Start Uses

func (d *MCP3002Driver) Start() (err error)

Start initializes the driver.

type MCP3004Driver Uses

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

MCP3004Driver is a driver for the MCP3008 A/D converter.

func NewMCP3004Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3004Driver) AnalogRead Uses

func (d *MCP3004Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin

func (*MCP3004Driver) Connection Uses

func (d *MCP3004Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3004Driver) Halt Uses

func (d *MCP3004Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3004Driver) Name Uses

func (d *MCP3004Driver) Name() string

Name returns the name of the device.

func (*MCP3004Driver) Read Uses

func (d *MCP3004Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3004Driver) SetName Uses

func (d *MCP3004Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3004Driver) Start Uses

func (d *MCP3004Driver) Start() (err error)

Start initializes the driver.

type MCP3008Driver Uses

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

MCP3008Driver is a driver for the MCP3008 A/D converter.

func NewMCP3008Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3008Driver) AnalogRead Uses

func (d *MCP3008Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin

func (*MCP3008Driver) Connection Uses

func (d *MCP3008Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3008Driver) Halt Uses

func (d *MCP3008Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3008Driver) Name Uses

func (d *MCP3008Driver) Name() string

Name returns the name of the device.

func (*MCP3008Driver) Read Uses

func (d *MCP3008Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3008Driver) SetName Uses

func (d *MCP3008Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3008Driver) Start Uses

func (d *MCP3008Driver) Start() (err error)

Start initializes the driver.

type MCP3202Driver Uses

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

MCP3202Driver is a driver for the MCP3202 A/D converter.

func NewMCP3202Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3202Driver) AnalogRead Uses

func (d *MCP3202Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3202Driver) Connection Uses

func (d *MCP3202Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3202Driver) Halt Uses

func (d *MCP3202Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3202Driver) Name Uses

func (d *MCP3202Driver) Name() string

Name returns the name of the device.

func (*MCP3202Driver) Read Uses

func (d *MCP3202Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3202Driver) SetName Uses

func (d *MCP3202Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3202Driver) Start Uses

func (d *MCP3202Driver) Start() (err error)

Start initializes the driver.

type MCP3204Driver Uses

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

MCP3204Driver is a driver for the MCP3204 A/D converter.

func NewMCP3204Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3204Driver) AnalogRead Uses

func (d *MCP3204Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3204Driver) Connection Uses

func (d *MCP3204Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3204Driver) Halt Uses

func (d *MCP3204Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3204Driver) Name Uses

func (d *MCP3204Driver) Name() string

Name returns the name of the device.

func (*MCP3204Driver) Read Uses

func (d *MCP3204Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3204Driver) SetName Uses

func (d *MCP3204Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3204Driver) Start Uses

func (d *MCP3204Driver) Start() (err error)

Start initializes the driver.

type MCP3208Driver Uses

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

MCP3208Driver is a driver for the MCP3208 A/D converter.

func NewMCP3208Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3208Driver) AnalogRead Uses

func (d *MCP3208Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3208Driver) Connection Uses

func (d *MCP3208Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3208Driver) Halt Uses

func (d *MCP3208Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3208Driver) Name Uses

func (d *MCP3208Driver) Name() string

Name returns the name of the device.

func (*MCP3208Driver) Read Uses

func (d *MCP3208Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3208Driver) SetName Uses

func (d *MCP3208Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3208Driver) Start Uses

func (d *MCP3208Driver) Start() (err error)

Start initializes the driver.

type MCP3304Driver Uses

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

MCP3304Driver is a driver for the MCP3304 A/D converter.

func NewMCP3304Driver Uses

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.WithBus(int):    	bus to use with this driver
	spi.WithChip(int):    	chip to use with this driver
 spi.WithMode(int):    	mode to use with this driver
 spi.WithBits(int):    	number of bits to use with this driver
 spi.WithSpeed(int64):   speed in Hz to use with this driver

func (*MCP3304Driver) AnalogRead Uses

func (d *MCP3304Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3304Driver) Connection Uses

func (d *MCP3304Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3304Driver) Halt Uses

func (d *MCP3304Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3304Driver) Name Uses

func (d *MCP3304Driver) Name() string

Name returns the name of the device.

func (*MCP3304Driver) Read Uses

func (d *MCP3304Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3304Driver) SetName Uses

func (d *MCP3304Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3304Driver) Start Uses

func (d *MCP3304Driver) Start() (err error)

Start initializes the driver.

type Operations Uses

type Operations interface {
    Close() error
    Tx(w, r []byte) error
}

Operations are the wrappers around the actual functions used by the SPI device interface

type SSD1306Driver Uses

type SSD1306Driver struct {
    DisplayWidth  int
    DisplayHeight int
    DCPin         string
    RSTPin        string
    ExternalVcc   bool

    Config
    gobot.Commander
    // contains filtered or unexported fields
}

SSD1306Driver is a Gobot Driver for a SSD1306 Display

func NewSSD1306Driver Uses

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.WithBus(int):    		bus to use with this driver
	spi.WithChip(int):    		chip to use with this driver
 spi.WithMode(int):    		mode to use with this driver
 spi.WithBits(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 Uses

func (s *SSD1306Driver) Clear() (err error)

Clear clears the display buffer.

func (*SSD1306Driver) Connection Uses

func (s *SSD1306Driver) Connection() gobot.Connection

Connection returns the connection for the Driver

func (*SSD1306Driver) Display Uses

func (s *SSD1306Driver) Display() (err error)

Display sends the memory buffer to the display.

func (*SSD1306Driver) Halt Uses

func (s *SSD1306Driver) Halt() (err error)

Halt returns true if device is halted successfully.

func (*SSD1306Driver) Name Uses

func (s *SSD1306Driver) Name() string

Name returns the Name for the Driver

func (*SSD1306Driver) Off Uses

func (s *SSD1306Driver) Off() (err error)

Off turns off the display.

func (*SSD1306Driver) On Uses

func (s *SSD1306Driver) On() (err error)

On turns on the display.

func (*SSD1306Driver) Reset Uses

func (s *SSD1306Driver) Reset() (err error)

Reset re-initializes the device to a clean state.

func (*SSD1306Driver) Set Uses

func (s *SSD1306Driver) Set(x, y, c int)

Set sets a pixel in the display buffer.

func (*SSD1306Driver) SetBufferAndDisplay Uses

func (s *SSD1306Driver) SetBufferAndDisplay(buf []byte) (err error)

SetBufferAndDisplay sets the display buffer with the given buffer and displays the image.

func (*SSD1306Driver) SetContrast Uses

func (s *SSD1306Driver) SetContrast(contrast byte) (err error)

SetContrast sets the display contrast (0-255).

func (*SSD1306Driver) SetName Uses

func (s *SSD1306Driver) SetName(n string)

SetName sets the Name for the Driver

func (*SSD1306Driver) ShowImage Uses

func (s *SSD1306Driver) ShowImage(img image.Image) (err error)

ShowImage takes a standard Go image and shows it on the display in monochrome.

func (*SSD1306Driver) Start Uses

func (s *SSD1306Driver) Start() (err error)

Start sets up the needed connection, and initialized the device.

type SpiConnection Uses

type SpiConnection struct {
    Operations
    // contains filtered or unexported fields
}

SpiConnection is the implementation of the SPI interface using the periph.io sysfs implementation for Linux.

func NewConnection Uses

func NewConnection(port xspi.PortCloser, conn xspi.Conn) (connection *SpiConnection)

NewConnection creates and returns a new connection to a specific spi device on a bus/chip using the periph.io interface.

func (*SpiConnection) Close Uses

func (c *SpiConnection) Close() error

Close the SPI connection.

func (*SpiConnection) Tx Uses

func (c *SpiConnection) Tx(w, r []byte) error

Tx uses the SPI device to send/receive data.

Package spi imports 12 packages (graph) and is imported by 7 packages. Updated 2019-10-16. Refresh now. Tools for package owners.