gpio

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 8

README

GPIO

This package provides drivers for General Purpose Input/Output (GPIO) devices. It is normally used by connecting an adaptor such as Raspberry Pi that supports the needed interfaces for GPIO devices.

Getting Started

Please refer to the main README.md

Hardware Support

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

  • AIP1640 LED Dot Matrix/7 Segment Controller
  • Button
  • Buzzer
  • Direct Pin
  • EasyDriver
  • Grove Button (by using driver for Button)
  • Grove Buzzer (by using driver for Buzzer)
  • Grove LED (by using driver for LED)
  • Grove Magnetic Switch (by using driver for Button)
  • Grove Relay (by using driver for Relay)
  • Grove Touch Sensor (by using driver for Button)
  • HC-SR04 Ultrasonic Ranging Module
  • HD44780 LCD controller
  • LED
  • Makey Button (by using driver for Button)
  • MAX7219 LED Dot Matrix
  • Motor
  • Proximity Infra Red (PIR) Motion Sensor
  • Relay
  • RGB LED
  • Servo
  • Stepper Motor
  • TM1638 LED Controller

Documentation

Overview

Package gpio provides Gobot drivers for General Purpose Input/Output devices.

Installing:

Please refer to the main [README.md](https://github.com/hybridgroup/gobot/blob/release/README.md)

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

Index

Constants

View Source
const (
	AIP1640DataCmd  = 0x40
	AIP1640DispCtrl = 0x88
	AIP1640AddrCmd  = 0xC0

	AIP1640FixedAddr = 0x04
)

Commands of the driver

View Source
const (
	Whole   = 4
	Half    = 2
	Quarter = 1
	Eighth  = 0.500
)

Some useful divider

View Source
const (
	Rest = 0
	C0   = 16.35
	Db0  = 17.32
	D0   = 18.35
	Eb0  = 19.45
	E0   = 20.60
	F0   = 21.83
	Gb0  = 23.12
	G0   = 24.50
	Ab0  = 25.96
	A0   = 27.50
	Bb0  = 29.14
	B0   = 30.87
	C1   = 32.70
	Db1  = 34.65
	D1   = 36.71
	Eb1  = 38.89
	E1   = 41.20
	F1   = 43.65
	Gb1  = 46.25
	G1   = 49.00
	Ab1  = 51.91
	A1   = 55.00
	Bb1  = 58.27
	B1   = 61.74
	C2   = 65.41
	Db2  = 69.30
	D2   = 73.42
	Eb2  = 77.78
	E2   = 82.41
	F2   = 87.31
	Gb2  = 92.50
	G2   = 98.00
	Ab2  = 103.83
	A2   = 110.00
	Bb2  = 116.54
	B2   = 123.47
	C3   = 130.81
	Db3  = 138.59
	D3   = 146.83
	Eb3  = 155.56
	E3   = 164.81
	F3   = 174.61
	Gb3  = 185.00
	G3   = 196.00
	Ab3  = 207.65
	A3   = 220.00
	Bb3  = 233.08
	B3   = 246.94
	C4   = 261.63
	Db4  = 277.18
	D4   = 293.66
	Eb4  = 311.13
	E4   = 329.63
	F4   = 349.23
	Gb4  = 369.99
	G4   = 392.00
	Ab4  = 415.30
	A4   = 440.00
	Bb4  = 466.16
	B4   = 493.88
	C5   = 523.25
	Db5  = 554.37
	D5   = 587.33
	Eb5  = 622.25
	E5   = 659.25
	F5   = 698.46
	Gb5  = 739.99
	G5   = 783.99
	Ab5  = 830.61
	A5   = 880.00
	Bb5  = 932.33
	B5   = 987.77
	C6   = 1046.50
	Db6  = 1108.73
	D6   = 1174.66
	Eb6  = 1244.51
	E6   = 1318.51
	F6   = 1396.91
	Gb6  = 1479.98
	G6   = 1567.98
	Ab6  = 1661.22
	A6   = 1760.00
	Bb6  = 1864.66
	B6   = 1975.53
	C7   = 2093.00
	Db7  = 2217.46
	D7   = 2349.32
	Eb7  = 2489.02
	E7   = 2637.02
	F7   = 2793.83
	Gb7  = 2959.96
	G7   = 3135.96
	Ab7  = 3322.44
	A7   = 3520.00
	Bb7  = 3729.31
	B7   = 3951.07
	C8   = 4186.01
	Db8  = 4434.92
	D8   = 4698.63
	Eb8  = 4978.03
	E8   = 5274.04
	F8   = 5587.65
	Gb8  = 5919.91
	G8   = 6271.93
	Ab8  = 6644.88
	A8   = 7040.00
	Bb8  = 7458.62
	B8   = 7902.13
)

Some items of the musical scale

View Source
const (
	// Error event
	Error = "error"
	// ButtonRelease event
	ButtonRelease = "release"
	// ButtonPush event
	ButtonPush = "push"
	// MotionDetected event
	MotionDetected = "motion-detected"
	// MotionStopped event
	MotionStopped = "motion-stopped"
)
View Source
const (
	HD44780_CLEARDISPLAY        = 0x01
	HD44780_RETURNHOME          = 0x02
	HD44780_ENTRYMODESET        = 0x04
	HD44780_DISPLAYCONTROL      = 0x08
	HD44780_CURSORSHIFT         = 0x10
	HD44780_FUNCTIONSET         = 0x20
	HD44780_SETCGRAMADDR        = 0x40
	HD44780_SETDDRAMADDR        = 0x80
	HD44780_ENTRYRIGHT          = 0x00
	HD44780_ENTRYLEFT           = 0x02
	HD44780_ENTRYSHIFTINCREMENT = 0x01
	HD44780_ENTRYSHIFTDECREMENT = 0x00
	HD44780_DISPLAYON           = 0x04
	HD44780_DISPLAYOFF          = 0x00
	HD44780_CURSORON            = 0x02
	HD44780_CURSOROFF           = 0x00
	HD44780_BLINKON             = 0x01
	HD44780_BLINKOFF            = 0x00
	HD44780_DISPLAYMOVE         = 0x08
	HD44780_CURSORMOVE          = 0x00
	HD44780_MOVERIGHT           = 0x04
	HD44780_MOVELEFT            = 0x00
	HD44780_1LINE               = 0x00
	HD44780_2LINE               = 0x08
	HD44780_5x8DOTS             = 0x00
	HD44780_5x10DOTS            = 0x04
	HD44780_4BITBUS             = 0x00
	HD44780_8BITBUS             = 0x10
)

Commands for the driver

View Source
const (
	MAX7219Digit0 = 0x01
	MAX7219Digit1 = 0x02
	MAX7219Digit2 = 0x03
	MAX7219Digit3 = 0x04
	MAX7219Digit4 = 0x05
	MAX7219Digit5 = 0x06
	MAX7219Digit6 = 0x07
	MAX7219Digit7 = 0x08

	MAX7219DecodeMode  = 0x09
	MAX7219Intensity   = 0x0a
	MAX7219ScanLimit   = 0x0b
	MAX7219Shutdown    = 0x0c
	MAX7219DisplayTest = 0x0f
)

Access and command constants for the driver

View Source
const (

	// StepperDriverForward is to set the stepper to run in forward direction (e.g. turn clock wise)
	StepperDriverForward = "forward"
	// StepperDriverBackward is to set the stepper to run in backward direction (e.g. turn counter clock wise)
	StepperDriverBackward = "backward"
)
View Source
const (
	TM1638None = iota
	TM1638Red
	TM1638Green
)

Colors of the display

View Source
const (
	TM1638DataCmd  = 0x40
	TM1638DispCtrl = 0x80
	TM1638AddrCmd  = 0xC0

	TM1638WriteDisp = 0x00
	TM1638ReadKeys  = 0x02
	TM1638FixedAddr = 0x04
)

Commands of the driver

View Source
const (
	HD44780_2NDLINEOFFSET = 0x40
)

Some useful constants for the driver

Variables

View Source
var (
	// ErrServoWriteUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrServoWriteUnsupported = errors.New("ServoWrite is not supported by this platform")
	// ErrPwmWriteUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrPwmWriteUnsupported = errors.New("PwmWrite is not supported by this platform")
	// ErrDigitalWriteUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrDigitalWriteUnsupported = errors.New("DigitalWrite is not supported by this platform")
	// ErrDigitalReadUnsupported is the error resulting when a driver attempts to use
	// hardware capabilities which a connection does not support
	ErrDigitalReadUnsupported = errors.New("DigitalRead is not supported by this platform")
)
View Source
var StepperModes = struct {
	SinglePhaseStepping phase
	DualPhaseStepping   phase
	HalfStepping        phase
}{

	SinglePhaseStepping: phase{
		{1, 0, 0, 0},
		{0, 1, 0, 0},
		{0, 0, 1, 0},
		{0, 0, 0, 1},
	},

	DualPhaseStepping: phase{
		{1, 0, 0, 1},
		{1, 1, 0, 0},
		{0, 1, 1, 0},
		{0, 0, 1, 1},
	},

	HalfStepping: phase{
		{1, 0, 0, 1},
		{1, 0, 0, 0},
		{1, 1, 0, 0},
		{0, 1, 0, 0},
		{0, 1, 1, 0},
		{0, 0, 1, 0},
		{0, 0, 1, 1},
		{0, 0, 0, 1},
	},
}

StepperModes to decide on Phase and Stepping

Functions

func NewTM1638Fonts

func NewTM1638Fonts() map[string]byte

NewTM1638Fonts returns a map with fonts and their corresponding byte for proper representation on the 7-segment LCD

func WithButtonDefaultState added in v2.3.0

func WithButtonDefaultState(s int) buttonOptionApplier

WithButtonDefaultState change the default state from default 0 to the given value.

func WithButtonPollInterval added in v2.3.0

func WithButtonPollInterval(interval time.Duration) buttonOptionApplier

WithButtonPollInterval change the asynchronous cyclic reading interval from default 10ms to the given value.

func WithEasyDirectionPin added in v2.3.0

func WithEasyDirectionPin(pin string) easyOptionApplier

WithEasyDirectionPin configure a pin for change the moving direction.

func WithEasyEnablePin added in v2.3.0

func WithEasyEnablePin(pin string) easyOptionApplier

WithEasyEnablePin configure a pin for disabling/enabling the driver.

func WithEasySleepPin added in v2.3.0

func WithEasySleepPin(pin string) easyOptionApplier

WithEasySleepPin configure a pin for sleep/wake the driver.

func WithHCSR04UseEdgePolling added in v2.3.0

func WithHCSR04UseEdgePolling() hcsr04OptionApplier

WithHCSR04UseEdgePolling use discrete edge polling instead pin edge detection by "cdev" from gpiod.

func WithHD44780RWPin added in v2.3.0

func WithHD44780RWPin(pin string) hd44780OptionApplier

WithHD44780RWPin sets the RW pin for next initializing.

func WithMotorAnalog added in v2.3.0

func WithMotorAnalog() motorOptionApplier

WithMotorAnalog change the default mode "digital" to analog for the motor.

func WithMotorBackwardPin added in v2.3.0

func WithMotorBackwardPin(pin string) motorOptionApplier

WithMotorBackwardPin introduces a pin for setting the direction to backward.

func WithMotorDirectionPin added in v2.3.0

func WithMotorDirectionPin(pin string) motorOptionApplier

WithMotorDirectionPin introduces a pin for change the direction of the motor.

func WithMotorForwardPin added in v2.3.0

func WithMotorForwardPin(pin string) motorOptionApplier

WithMotorForwardPin introduces a pin for setting the direction to forward.

func WithName added in v2.3.0

func WithName(name string) optionApplier

WithName is used to replace the default name of the driver.

func WithPIRMotionPollInterval added in v2.3.0

func WithPIRMotionPollInterval(interval time.Duration) pirMotionOptionApplier

WithPIRMotionPollInterval change the asynchronous cyclic reading interval from default 10ms to the given value.

func WithRelayInverted added in v2.3.0

func WithRelayInverted() relayOptionApplier

WithRelayInverted change the relay action to inverted.

Types

type AIP1640Driver

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

AIP1640Driver is the gobot driver for the AIP1640 LED driver used in the WEMOS D1 mini Matrix LED Shield. It has some similarities with the TM16xx LED drivers

Datasheet CN: https://datasheet.lcsc.com/szlcsc/AiP1640_C82650.pdf

Library ported from: https://github.com/wemos/WEMOS_Matrix_LED_Shield_Arduino_Library

func NewAIP1640Driver

func NewAIP1640Driver(a gobot.Connection, clockPin string, dataPin string, opts ...interface{}) *AIP1640Driver

NewAIP1640Driver return a new driver for AIP1640 LED driver given a gobot.Connection and the clock, data and strobe pins.

Supported options:

"WithName"

func (*AIP1640Driver) Clear

func (d *AIP1640Driver) Clear()

Clear empties the buffer (turns off all the LEDs)

func (AIP1640Driver) Connection

func (d AIP1640Driver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*AIP1640Driver) Display

func (d *AIP1640Driver) Display() error

Display sends the buffer to the display (ie. turns on/off the corresponding LEDs)

func (*AIP1640Driver) DrawMatrix

func (d *AIP1640Driver) DrawMatrix(data [8]byte)

DrawMatrix sets the whole buffer

func (*AIP1640Driver) DrawPixel

func (d *AIP1640Driver) DrawPixel(x, y byte, enabled bool)

DrawPixel turns on or off a specific in the buffer

func (*AIP1640Driver) DrawRow

func (d *AIP1640Driver) DrawRow(row, data byte)

DrawRow sets any given row of LEDs in the buffer

func (AIP1640Driver) Halt

func (d AIP1640Driver) Halt() error

Halt halts the gpio device.

func (AIP1640Driver) Name

func (d AIP1640Driver) Name() string

Name returns the name of the gpio device.

func (AIP1640Driver) Pin added in v2.3.0

func (d AIP1640Driver) Pin() string

Pin returns the pin associated with the driver.

func (*AIP1640Driver) SetIntensity

func (d *AIP1640Driver) SetIntensity(level byte)

SetIntensity changes the intensity (from 1 to 7) of the display

func (AIP1640Driver) SetName

func (d AIP1640Driver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (AIP1640Driver) Start

func (d AIP1640Driver) Start() error

Start initializes the gpio device.

type ButtonDriver

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

ButtonDriver Represents a digital Button

func NewButtonDriver

func NewButtonDriver(a DigitalReader, pin string, opts ...interface{}) *ButtonDriver

NewButtonDriver returns a driver for a button with a polling interval for changed state of 10 milliseconds, given a DigitalReader and pin.

Supported options:

"WithName"
"WithButtonPollInterval"

func (*ButtonDriver) Active

func (d *ButtonDriver) Active() bool

Active gets the current state

func (ButtonDriver) Connection

func (d ButtonDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (ButtonDriver) Halt

func (d ButtonDriver) Halt() error

Halt halts the gpio device.

func (ButtonDriver) Name

func (d ButtonDriver) Name() string

Name returns the name of the gpio device.

func (ButtonDriver) Pin

func (d ButtonDriver) Pin() string

Pin returns the pin associated with the driver.

func (*ButtonDriver) SetDefaultState added in v2.3.0

func (d *ButtonDriver) SetDefaultState(s int)

SetDefaultState for the next start. Deprecated: Please use option gpio.WithButtonDefaultState instead.

func (ButtonDriver) SetName

func (d ButtonDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (ButtonDriver) Start

func (d ButtonDriver) Start() error

Start initializes the gpio device.

type BuzzerDriver

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

BuzzerDriver represents a digital buzzer

func NewBuzzerDriver

func NewBuzzerDriver(a DigitalWriter, pin string, opts ...interface{}) *BuzzerDriver

NewBuzzerDriver return a new BuzzerDriver given a DigitalWriter and pin.

Supported options:

"WithName"

func (*BuzzerDriver) BPM

func (d *BuzzerDriver) BPM() float64

BPM gets the current bpm value.

func (BuzzerDriver) Connection

func (d BuzzerDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (BuzzerDriver) Halt

func (d BuzzerDriver) Halt() error

Halt halts the gpio device.

func (BuzzerDriver) Name

func (d BuzzerDriver) Name() string

Name returns the name of the gpio device.

func (*BuzzerDriver) Off

func (d *BuzzerDriver) Off() error

Off sets the buzzer to a low state.

func (*BuzzerDriver) On

func (d *BuzzerDriver) On() error

On sets the buzzer to a high state.

func (BuzzerDriver) Pin

func (d BuzzerDriver) Pin() string

Pin returns the pin associated with the driver.

func (*BuzzerDriver) SetBPM added in v2.3.0

func (d *BuzzerDriver) SetBPM(val float64)

SetBPM change the bpm value.

func (BuzzerDriver) SetName

func (d BuzzerDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (BuzzerDriver) Start

func (d BuzzerDriver) Start() error

Start initializes the gpio device.

func (*BuzzerDriver) State

func (d *BuzzerDriver) State() bool

State return true if the buzzer is on and false if the buzzer is off

func (*BuzzerDriver) Toggle

func (d *BuzzerDriver) Toggle() error

Toggle sets the buzzer to the opposite of it's current state

func (*BuzzerDriver) Tone

func (d *BuzzerDriver) Tone(hz, duration float64) error

Tone is to make a sound with the given frequency

type DigitalReader

type DigitalReader interface {
	DigitalRead(pin string) (val int, err error)
}

DigitalReader interface represents an Adaptor which has DigitalRead capabilities

type DigitalWriter

type DigitalWriter interface {
	DigitalWrite(pin string, val byte) error
}

DigitalWriter interface represents an Adaptor which has DigitalWrite capabilities

type DirectPinDriver

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

DirectPinDriver represents a GPIO pin

func NewDirectPinDriver

func NewDirectPinDriver(a gobot.Connection, pin string, opts ...interface{}) *DirectPinDriver

NewDirectPinDriver return a new DirectPinDriver given a Connection and pin.

Supported options:

"WithName"

Adds the following API Commands:

"DigitalRead" - See DirectPinDriver.DigitalRead
"DigitalWrite" - See DirectPinDriver.DigitalWrite
"PwmWrite" - See DirectPinDriver.PwmWrite
"ServoWrite" - See DirectPinDriver.ServoWrite

func (DirectPinDriver) Connection

func (d DirectPinDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*DirectPinDriver) DigitalRead

func (d *DirectPinDriver) DigitalRead() (int, error)

DigitalRead returns the current digital state of the pin

func (*DirectPinDriver) DigitalWrite

func (d *DirectPinDriver) DigitalWrite(level byte) error

DigitalWrite writes to the pin. Acceptable values are 1 or 0

func (DirectPinDriver) Halt

func (d DirectPinDriver) Halt() error

Halt halts the gpio device.

func (DirectPinDriver) Name

func (d DirectPinDriver) Name() string

Name returns the name of the gpio device.

func (*DirectPinDriver) Off

func (d *DirectPinDriver) Off() error

Off turn off pin

func (*DirectPinDriver) On

func (d *DirectPinDriver) On() error

On turn on pin

func (DirectPinDriver) Pin

func (d DirectPinDriver) Pin() string

Pin returns the pin associated with the driver.

func (*DirectPinDriver) PwmWrite

func (d *DirectPinDriver) PwmWrite(level byte) error

PwmWrite writes the 0-254 value to the specified pin

func (*DirectPinDriver) ServoWrite

func (d *DirectPinDriver) ServoWrite(level byte) error

ServoWrite writes value to the specified pin

func (DirectPinDriver) SetName

func (d DirectPinDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (DirectPinDriver) Start

func (d DirectPinDriver) Start() error

Start initializes the gpio device.

type EasyDriver

type EasyDriver struct {
	*StepperDriver
	// contains filtered or unexported fields
}

EasyDriver is an driver for stepper hardware board from SparkFun (https://www.sparkfun.com/products/12779) This should also work for the BigEasyDriver (untested). It is basically a wrapper for the common StepperDriver{} with the specific additions for the board, e.g. direction, enable and sleep outputs.

func NewEasyDriver

func NewEasyDriver(a DigitalWriter, anglePerStep float32, stepPin string, opts ...interface{}) *EasyDriver

NewEasyDriver returns a new driver TODO: Support selecting phase input instead of hard-wiring MS1 and MS2 to board truth table A - DigitalWriter anglePerStep - Step angle of motor stepPin - Pin corresponding to step input on EasyDriver

Supported options:

"WithName"
"WithEasyDirectionPin"
"WithEasyEnablePin"
"WithEasySleepPin"

func (EasyDriver) Connection

func (d EasyDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*EasyDriver) Disable

func (d *EasyDriver) Disable() error

Disable disables all motor output

func (*EasyDriver) Enable

func (d *EasyDriver) Enable() error

Enable enables all motor output

func (EasyDriver) Halt

func (d EasyDriver) Halt() error

Halt halts the gpio device.

func (*EasyDriver) IsEnabled

func (d *EasyDriver) IsEnabled() bool

IsEnabled returns a bool stating whether motor is enabled

func (*EasyDriver) IsSleeping

func (d *EasyDriver) IsSleeping() bool

IsSleeping returns a bool stating whether motor is sleeping

func (EasyDriver) Name

func (d EasyDriver) Name() string

Name returns the name of the gpio device.

func (EasyDriver) Pin added in v2.3.0

func (d EasyDriver) Pin() string

Pin returns the pin associated with the driver.

func (*EasyDriver) SetDirection

func (d *EasyDriver) SetDirection(direction string) error

SetDirection sets the direction to be moving.

func (EasyDriver) SetName

func (d EasyDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (EasyDriver) Start

func (d EasyDriver) Start() error

Start initializes the gpio device.

func (*EasyDriver) Wake

func (d *EasyDriver) Wake() error

Wake wakes up the driver

type GroveButtonDriver

type GroveButtonDriver struct {
	*ButtonDriver
}

GroveButtonDriver represents a button sensor with a Grove connector

func NewGroveButtonDriver deprecated

func NewGroveButtonDriver(a DigitalReader, pin string, opts ...interface{}) *GroveButtonDriver

NewGroveButtonDriver returns a new driver for Grove button with a polling interval of 10 milliseconds given a DigitalReader and pin.

Supported options:

"WithName"
"WithButtonPollInterval"

Deprecated: Please use gpio.NewButtonDriver instead. Development will be discontinued.

func (GroveButtonDriver) Connection added in v2.3.0

func (d GroveButtonDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (GroveButtonDriver) Halt added in v2.3.0

func (d GroveButtonDriver) Halt() error

Halt halts the gpio device.

func (GroveButtonDriver) Name added in v2.3.0

func (d GroveButtonDriver) Name() string

Name returns the name of the gpio device.

func (GroveButtonDriver) Pin added in v2.3.0

func (d GroveButtonDriver) Pin() string

Pin returns the pin associated with the driver.

func (GroveButtonDriver) SetName added in v2.3.0

func (d GroveButtonDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (GroveButtonDriver) Start added in v2.3.0

func (d GroveButtonDriver) Start() error

Start initializes the gpio device.

type GroveBuzzerDriver

type GroveBuzzerDriver struct {
	*BuzzerDriver
}

GroveBuzzerDriver represents a buzzer with a Grove connector

func NewGroveBuzzerDriver deprecated

func NewGroveBuzzerDriver(a DigitalWriter, pin string, opts ...interface{}) *GroveBuzzerDriver

NewGroveBuzzerDriver return a new driver for Grove buzzer given a DigitalWriter and pin.

Supported options:

"WithName"

Deprecated: Please use gpio.NewBuzzerDriver instead. Development will be discontinued.

func (GroveBuzzerDriver) Connection added in v2.3.0

func (d GroveBuzzerDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (GroveBuzzerDriver) Halt added in v2.3.0

func (d GroveBuzzerDriver) Halt() error

Halt halts the gpio device.

func (GroveBuzzerDriver) Name added in v2.3.0

func (d GroveBuzzerDriver) Name() string

Name returns the name of the gpio device.

func (GroveBuzzerDriver) Pin added in v2.3.0

func (d GroveBuzzerDriver) Pin() string

Pin returns the pin associated with the driver.

func (GroveBuzzerDriver) SetName added in v2.3.0

func (d GroveBuzzerDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (GroveBuzzerDriver) Start added in v2.3.0

func (d GroveBuzzerDriver) Start() error

Start initializes the gpio device.

type GroveLedDriver

type GroveLedDriver struct {
	*LedDriver
}

GroveLedDriver represents an LED with a Grove connector

func NewGroveLedDriver deprecated

func NewGroveLedDriver(a DigitalWriter, pin string) *GroveLedDriver

NewGroveLedDriver return a new driver for Grove Led given a DigitalWriter and pin.

Supported options:

"WithName"

Adds the following API Commands:

"Brightness" - See LedDriver.Brightness
"Toggle" - See LedDriver.Toggle
"On" - See LedDriver.On
"Off" - See LedDriver.Off

Deprecated: Please use gpio.NewLedDriver instead. Development will be discontinued.

func (GroveLedDriver) Connection added in v2.3.0

func (d GroveLedDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (GroveLedDriver) Halt added in v2.3.0

func (d GroveLedDriver) Halt() error

Halt halts the gpio device.

func (GroveLedDriver) Name added in v2.3.0

func (d GroveLedDriver) Name() string

Name returns the name of the gpio device.

func (GroveLedDriver) Pin added in v2.3.0

func (d GroveLedDriver) Pin() string

Pin returns the pin associated with the driver.

func (GroveLedDriver) SetName added in v2.3.0

func (d GroveLedDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (GroveLedDriver) Start added in v2.3.0

func (d GroveLedDriver) Start() error

Start initializes the gpio device.

type GroveMagneticSwitchDriver

type GroveMagneticSwitchDriver struct {
	*ButtonDriver
}

GroveMagneticSwitchDriver represent a magnetic switch sensor with a Grove connector

func NewGroveMagneticSwitchDriver deprecated

func NewGroveMagneticSwitchDriver(a DigitalReader, pin string, opts ...interface{}) *GroveMagneticSwitchDriver

NewGroveMagneticSwitchDriver returns a new driver for Grove magnetic switch sensor with a polling interval of 10 milliseconds given a DigitalReader, name and pin.

Supported options:

"WithName"
"WithButtonPollInterval"

Deprecated: Please use gpio.NewButtonDriver instead. Development will be discontinued.

func (GroveMagneticSwitchDriver) Connection added in v2.3.0

func (d GroveMagneticSwitchDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (GroveMagneticSwitchDriver) Halt added in v2.3.0

func (d GroveMagneticSwitchDriver) Halt() error

Halt halts the gpio device.

func (GroveMagneticSwitchDriver) Name added in v2.3.0

func (d GroveMagneticSwitchDriver) Name() string

Name returns the name of the gpio device.

func (GroveMagneticSwitchDriver) Pin added in v2.3.0

func (d GroveMagneticSwitchDriver) Pin() string

Pin returns the pin associated with the driver.

func (GroveMagneticSwitchDriver) SetName added in v2.3.0

func (d GroveMagneticSwitchDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (GroveMagneticSwitchDriver) Start added in v2.3.0

func (d GroveMagneticSwitchDriver) Start() error

Start initializes the gpio device.

type GroveRelayDriver

type GroveRelayDriver struct {
	*RelayDriver
}

GroveRelayDriver represents a Relay with a Grove connector

func NewGroveRelayDriver deprecated

func NewGroveRelayDriver(a DigitalWriter, pin string) *GroveRelayDriver

NewGroveRelayDriver return a new GroveRelayDriver given a DigitalWriter and pin.

Supported options:

"WithName"

Adds the following API Commands:

"Toggle" - See RelayDriver.Toggle
"On" - See RelayDriver.On
"Off" - See RelayDriver.Off

Deprecated: Please use gpio.NewRelayDriver instead. Development will be discontinued.

func (GroveRelayDriver) Connection added in v2.3.0

func (d GroveRelayDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (GroveRelayDriver) Halt added in v2.3.0

func (d GroveRelayDriver) Halt() error

Halt halts the gpio device.

func (GroveRelayDriver) Name added in v2.3.0

func (d GroveRelayDriver) Name() string

Name returns the name of the gpio device.

func (GroveRelayDriver) Pin added in v2.3.0

func (d GroveRelayDriver) Pin() string

Pin returns the pin associated with the driver.

func (GroveRelayDriver) SetName added in v2.3.0

func (d GroveRelayDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (GroveRelayDriver) Start added in v2.3.0

func (d GroveRelayDriver) Start() error

Start initializes the gpio device.

type GroveTouchDriver

type GroveTouchDriver struct {
	*ButtonDriver
}

GroveTouchDriver represents a touch button sensor with a Grove connector

func NewGroveTouchDriver deprecated

func NewGroveTouchDriver(a DigitalReader, pin string, opts ...interface{}) *GroveTouchDriver

NewGroveTouchDriver returns a new driver for Grove touch sensor with a polling interval of 10 milliseconds given a DigitalReader and pin.

Supported options:

"WithName"
"WithButtonPollInterval"

Deprecated: Please use gpio.NewButtonDriver instead. Development will be discontinued.

func (GroveTouchDriver) Connection added in v2.3.0

func (d GroveTouchDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (GroveTouchDriver) Halt added in v2.3.0

func (d GroveTouchDriver) Halt() error

Halt halts the gpio device.

func (GroveTouchDriver) Name added in v2.3.0

func (d GroveTouchDriver) Name() string

Name returns the name of the gpio device.

func (GroveTouchDriver) Pin added in v2.3.0

func (d GroveTouchDriver) Pin() string

Pin returns the pin associated with the driver.

func (GroveTouchDriver) SetName added in v2.3.0

func (d GroveTouchDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (GroveTouchDriver) Start added in v2.3.0

func (d GroveTouchDriver) Start() error

Start initializes the gpio device.

type HCSR04Driver added in v2.2.0

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

HCSR04Driver is a driver for ultrasonic range measurement.

func NewHCSR04Driver added in v2.2.0

func NewHCSR04Driver(a gobot.Adaptor, triggerPinID, echoPinID string, opts ...interface{}) *HCSR04Driver

NewHCSR04Driver creates a new instance of the driver for HC-SR04 (same as SEN-US01).

Datasheet: https://www.makershop.de/download/HCSR04-datasheet-version-1.pdf

Supported options:

"WithName"

func (HCSR04Driver) Connection added in v2.3.0

func (d HCSR04Driver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*HCSR04Driver) Distance added in v2.2.0

func (d *HCSR04Driver) Distance() float64

Distance returns the last distance measured in meter, it does not trigger a distance measurement

func (HCSR04Driver) Halt added in v2.3.0

func (d HCSR04Driver) Halt() error

Halt halts the gpio device.

func (*HCSR04Driver) MeasureDistance added in v2.2.0

func (d *HCSR04Driver) MeasureDistance() (float64, error)

MeasureDistance retrieves the distance in front of sensor in meters and returns the measure. It is not designed to work in a fast loop! For this specific usage, use StartDistanceMonitor() associated with Distance() instead.

func (HCSR04Driver) Name added in v2.3.0

func (d HCSR04Driver) Name() string

Name returns the name of the gpio device.

func (HCSR04Driver) Pin added in v2.3.0

func (d HCSR04Driver) Pin() string

Pin returns the pin associated with the driver.

func (HCSR04Driver) SetName added in v2.3.0

func (d HCSR04Driver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (HCSR04Driver) Start added in v2.3.0

func (d HCSR04Driver) Start() error

Start initializes the gpio device.

func (*HCSR04Driver) StartDistanceMonitor added in v2.2.0

func (d *HCSR04Driver) StartDistanceMonitor() error

StartDistanceMonitor starts continuous measurement. The current value can be read by Distance()

func (*HCSR04Driver) StopDistanceMonitor added in v2.2.0

func (d *HCSR04Driver) StopDistanceMonitor() error

StopDistanceMonitor stop the monitor process

type HD44780BusMode

type HD44780BusMode int

HD44780BusMode is the data bus mode

const (
	HD44780_4BITMODE HD44780BusMode = iota + 1
	HD44780_8BITMODE
)

Bus modes of the driver

type HD44780DataPin

type HD44780DataPin struct {
	D0 string // not used if 4Bit mode
	D1 string // not used if 4Bit mode
	D2 string // not used if 4Bit mode
	D3 string // not used if 4Bit mode
	D4 string
	D5 string
	D6 string
	D7 string
}

HD44780DataPin are the data bit pins

type HD44780Driver

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

HD44780Driver is the gobot driver for the HD44780 LCD controller Datasheet: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

func NewHD44780Driver

func NewHD44780Driver(
	a gobot.Connection,
	cols int,
	rows int,
	busMode HD44780BusMode,
	pinRS string,
	pinEN string,
	pinDataBits HD44780DataPin,
	opts ...interface{},
) *HD44780Driver

NewHD44780Driver return a new HD44780Driver a: gobot.Connection cols: lcd columns rows: lcd rows busMode: 4Bit or 8Bit pinRS: register select pin pinEN: clock enable pin pinDataBits: databit pins

Supported options:

"WithName"
func (d *HD44780Driver) Blink(on bool) error

Blink turn the blink on and off

func (*HD44780Driver) Clear

func (d *HD44780Driver) Clear() error

Clear clear the display

func (HD44780Driver) Connection

func (d HD44780Driver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*HD44780Driver) CreateChar

func (d *HD44780Driver) CreateChar(pos int, charMap [8]byte) error

CreateChar create custom character

func (*HD44780Driver) Cursor

func (d *HD44780Driver) Cursor(on bool) error

Cursor turn the cursor on and off

func (*HD44780Driver) Display

func (d *HD44780Driver) Display(on bool) error

Display turn the display on and off

func (HD44780Driver) Halt

func (d HD44780Driver) Halt() error

Halt halts the gpio device.

func (*HD44780Driver) Home

func (d *HD44780Driver) Home() error

Home return cursor to home

func (*HD44780Driver) LeftToRight

func (d *HD44780Driver) LeftToRight() error

LeftToRight display text from left to right

func (HD44780Driver) Name

func (d HD44780Driver) Name() string

Name returns the name of the gpio device.

func (HD44780Driver) Pin added in v2.3.0

func (d HD44780Driver) Pin() string

Pin returns the pin associated with the driver.

func (*HD44780Driver) RightToLeft

func (d *HD44780Driver) RightToLeft() error

RightToLeft display text from right to left

func (*HD44780Driver) ScrollLeft

func (d *HD44780Driver) ScrollLeft() error

ScrollLeft scroll text left

func (*HD44780Driver) ScrollRight

func (d *HD44780Driver) ScrollRight() error

ScrollRight scroll text right

func (*HD44780Driver) SendCommand

func (d *HD44780Driver) SendCommand(data int) error

SendCommand send control command

func (*HD44780Driver) SetCursor

func (d *HD44780Driver) SetCursor(col int, row int) error

SetCursor move the cursor to the specified position

func (HD44780Driver) SetName

func (d HD44780Driver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (HD44780Driver) Start

func (d HD44780Driver) Start() error

Start initializes the gpio device.

func (*HD44780Driver) Write

func (d *HD44780Driver) Write(message string) error

Write output text to the display

func (*HD44780Driver) WriteChar

func (d *HD44780Driver) WriteChar(data int) error

WriteChar output a character to the display

type LedDriver

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

LedDriver represents a digital Led

func NewLedDriver

func NewLedDriver(a DigitalWriter, pin string, opts ...interface{}) *LedDriver

NewLedDriver return a new LedDriver given a DigitalWriter and pin.

Supported options:

"WithName"

Adds the following API Commands:

"Brightness" - See LedDriver.Brightness
"Toggle" - See LedDriver.Toggle
"On" - See LedDriver.On
"Off" - See LedDriver.Off

func (*LedDriver) Brightness

func (d *LedDriver) Brightness(level byte) error

Brightness sets the led to the specified level of brightness

func (LedDriver) Connection

func (d LedDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (LedDriver) Halt

func (d LedDriver) Halt() error

Halt halts the gpio device.

func (LedDriver) Name

func (d LedDriver) Name() string

Name returns the name of the gpio device.

func (*LedDriver) Off

func (d *LedDriver) Off() error

Off sets the led to a low state.

func (*LedDriver) On

func (d *LedDriver) On() error

On sets the led to a high state.

func (LedDriver) Pin

func (d LedDriver) Pin() string

Pin returns the pin associated with the driver.

func (LedDriver) SetName

func (d LedDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (LedDriver) Start

func (d LedDriver) Start() error

Start initializes the gpio device.

func (*LedDriver) State

func (d *LedDriver) State() bool

State return true if the led is On and false if the led is Off

func (*LedDriver) Toggle

func (d *LedDriver) Toggle() error

Toggle sets the led to the opposite of it's current state

type MAX7219Driver

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

MAX7219Driver is the gobot driver for the MAX7219 LED driver

Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf

func NewMAX7219Driver

func NewMAX7219Driver(
	a gobot.Connection,
	clockPin, dataPin, csPin string,
	count uint,
	opts ...interface{},
) *MAX7219Driver

NewMAX7219Driver return a new MAX7219Driver given a gobot.Connection, pins and how many chips are chained

Supported options:

"WithName"

func (*MAX7219Driver) All

func (d *MAX7219Driver) All(address byte, data byte) error

All sends the same data to all the modules

func (*MAX7219Driver) ClearAll

func (d *MAX7219Driver) ClearAll() error

ClearAll turns off all LEDs of all modules

func (*MAX7219Driver) ClearOne

func (d *MAX7219Driver) ClearOne(which uint) error

ClearOne turns off all LEDs of the given module

func (MAX7219Driver) Connection

func (d MAX7219Driver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (MAX7219Driver) Halt

func (d MAX7219Driver) Halt() error

Halt halts the gpio device.

func (MAX7219Driver) Name

func (d MAX7219Driver) Name() string

Name returns the name of the gpio device.

func (*MAX7219Driver) One

func (d *MAX7219Driver) One(which uint, address byte, data byte) error

One sends data to a specific module

func (MAX7219Driver) Pin added in v2.3.0

func (d MAX7219Driver) Pin() string

Pin returns the pin associated with the driver.

func (*MAX7219Driver) SetIntensity

func (d *MAX7219Driver) SetIntensity(level byte) error

SetIntensity changes the intensity (from 1 to 7) of the display

func (MAX7219Driver) SetName

func (d MAX7219Driver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (MAX7219Driver) Start

func (d MAX7219Driver) Start() error

Start initializes the gpio device.

type MotorDriver

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

MotorDriver Represents a Motor

func NewMotorDriver

func NewMotorDriver(a DigitalWriter, speedPin string, opts ...interface{}) *MotorDriver

NewMotorDriver return a new MotorDriver given a DigitalWriter and pin. This defaults to digital mode and just switch on and off in forward direction. Optional pins can be given, depending on your hardware. So the direction can be changed with one pin or by using separated forward and backward pins.

If the given pin supports the PwmWriter the motor can be used/switched to analog mode by writing once to SetSpeed() or by calling SetAnalogMode(). The optional pins can be used for direction control.

Supported options:

"WithName"
"WithMotorAnalog"
"WithMotorDirectionPin"
"WithMotorForwardPin"
"WithMotorBackwardPin"

func (*MotorDriver) Backward

func (d *MotorDriver) Backward(speed byte) error

Backward runs the motor backward with the specified speed.

func (MotorDriver) Connection

func (d MotorDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*MotorDriver) Direction

func (d *MotorDriver) Direction() string

Direction returns the current direction ("forward" or "backward") of the motor.

func (*MotorDriver) Forward

func (d *MotorDriver) Forward(speed byte) error

Forward runs the motor forward with the specified speed.

func (MotorDriver) Halt

func (d MotorDriver) Halt() error

Halt halts the gpio device.

func (*MotorDriver) IsAnalog added in v2.3.0

func (d *MotorDriver) IsAnalog() bool

IsAnalog returns true if the motor is in analog mode.

func (*MotorDriver) IsDigital added in v2.3.0

func (d *MotorDriver) IsDigital() bool

IsDigital returns true if the motor is in digital mode.

func (*MotorDriver) IsOff

func (d *MotorDriver) IsOff() bool

IsOff returns true if the motor is off.

func (*MotorDriver) IsOn

func (d *MotorDriver) IsOn() bool

IsOn returns true if the motor is on.

func (MotorDriver) Name

func (d MotorDriver) Name() string

Name returns the name of the gpio device.

func (*MotorDriver) Off

func (d *MotorDriver) Off() error

Off turns the motor off or sets the motor to a 0 speed.

func (*MotorDriver) On

func (d *MotorDriver) On() error

On turns the motor on or sets the motor to a maximum speed.

func (MotorDriver) Pin added in v2.3.0

func (d MotorDriver) Pin() string

Pin returns the pin associated with the driver.

func (*MotorDriver) RunMax added in v2.3.0

func (d *MotorDriver) RunMax() error

RunMax sets the motor to the maximum speed.

func (*MotorDriver) RunMin added in v2.3.0

func (d *MotorDriver) RunMin() error

RunMin sets the motor to the minimum speed.

func (*MotorDriver) SetDirection added in v2.3.0

func (d *MotorDriver) SetDirection(direction string) error

Direction sets the direction pin to the specified direction.

func (MotorDriver) SetName

func (d MotorDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (*MotorDriver) SetSpeed added in v2.3.0

func (d *MotorDriver) SetSpeed(value byte) error

SetSpeed change the speed of the motor, without change the direction.

func (*MotorDriver) Speed

func (d *MotorDriver) Speed() byte

Speed returns the current speed of the motor.

func (MotorDriver) Start

func (d MotorDriver) Start() error

Start initializes the gpio device.

func (*MotorDriver) Toggle

func (d *MotorDriver) Toggle() error

Toggle sets the motor to the opposite of it's current state.

type PIRMotionDriver

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

PIRMotionDriver represents a digital Proximity Infra Red (PIR) motion detecter

Supported options:

"WithName"

func NewPIRMotionDriver

func NewPIRMotionDriver(a DigitalReader, pin string, opts ...interface{}) *PIRMotionDriver

NewPIRMotionDriver returns a new driver for PIR motion sensor with a polling interval of 10 Milliseconds, given a DigitalReader and pin.

Supported options:

"WithName"
"WithButtonPollInterval"

func (*PIRMotionDriver) Active

func (d *PIRMotionDriver) Active() bool

Active gets the current state

func (PIRMotionDriver) Connection

func (d PIRMotionDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (PIRMotionDriver) Halt

func (d PIRMotionDriver) Halt() error

Halt halts the gpio device.

func (PIRMotionDriver) Name

func (d PIRMotionDriver) Name() string

Name returns the name of the gpio device.

func (PIRMotionDriver) Pin

func (d PIRMotionDriver) Pin() string

Pin returns the pin associated with the driver.

func (PIRMotionDriver) SetName

func (d PIRMotionDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (PIRMotionDriver) Start

func (d PIRMotionDriver) Start() error

Start initializes the gpio device.

type PwmWriter

type PwmWriter interface {
	PwmWrite(pin string, val byte) error
}

PwmWriter interface represents an Adaptor which has Pwm capabilities

type RelayDriver

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

RelayDriver represents a digital relay

func NewRelayDriver

func NewRelayDriver(a DigitalWriter, pin string, opts ...interface{}) *RelayDriver

NewRelayDriver return a new RelayDriver given a DigitalWriter and pin.

Supported options:

"WithName"
"WithRelayInverted"

Adds the following API Commands:

"Toggle" - See RelayDriver.Toggle
"On" - See RelayDriver.On
"Off" - See RelayDriver.Off

func (RelayDriver) Connection

func (d RelayDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (RelayDriver) Halt

func (d RelayDriver) Halt() error

Halt halts the gpio device.

func (*RelayDriver) IsInverted added in v2.3.0

func (d *RelayDriver) IsInverted() bool

IsInverted returns true if the relay acts inverted

func (RelayDriver) Name

func (d RelayDriver) Name() string

Name returns the name of the gpio device.

func (*RelayDriver) Off

func (d *RelayDriver) Off() error

Off sets the relay to a low state.

func (*RelayDriver) On

func (d *RelayDriver) On() error

On sets the relay to a high state.

func (RelayDriver) Pin

func (d RelayDriver) Pin() string

Pin returns the pin associated with the driver.

func (RelayDriver) SetName

func (d RelayDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (RelayDriver) Start

func (d RelayDriver) Start() error

Start initializes the gpio device.

func (*RelayDriver) State

func (d *RelayDriver) State() bool

State return true if the relay is On and false if the relay is Off

func (*RelayDriver) Toggle

func (d *RelayDriver) Toggle() error

Toggle sets the relay to the opposite of it's current state

type RgbLedDriver

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

RgbLedDriver represents a digital RGB Led

func NewRgbLedDriver

func NewRgbLedDriver(a PwmWriter, redPin string, greenPin string, bluePin string, opts ...interface{}) *RgbLedDriver

NewRgbLedDriver return a new RgbLedDriver given a PwmWriter and 3 pins: redPin, greenPin, and bluePin

Supported options:

"WithName"

Adds the following API Commands:

"SetRGB" - See RgbLedDriver.SetRGB
"Toggle" - See RgbLedDriver.Toggle
"On" - See RgbLedDriver.On
"Off" - See RgbLedDriver.Off

func (*RgbLedDriver) BluePin

func (d *RgbLedDriver) BluePin() string

BluePin returns the RgbLedDrivers bluePin

func (RgbLedDriver) Connection

func (d RgbLedDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*RgbLedDriver) GreenPin

func (d *RgbLedDriver) GreenPin() string

GreenPin returns the RgbLedDrivers redPin

func (RgbLedDriver) Halt

func (d RgbLedDriver) Halt() error

Halt halts the gpio device.

func (RgbLedDriver) Name

func (d RgbLedDriver) Name() string

Name returns the name of the gpio device.

func (*RgbLedDriver) Off

func (d *RgbLedDriver) Off() error

Off sets the led to black.

func (*RgbLedDriver) On

func (d *RgbLedDriver) On() error

On sets the led's pins to their various states

func (*RgbLedDriver) Pin

func (d *RgbLedDriver) Pin() string

Pin returns the RgbLedDrivers pins

func (*RgbLedDriver) RedPin

func (d *RgbLedDriver) RedPin() string

RedPin returns the RgbLedDrivers redPin

func (*RgbLedDriver) SetLevel

func (d *RgbLedDriver) SetLevel(pin string, level byte) error

SetLevel sets the led to the specified color level

func (RgbLedDriver) SetName

func (d RgbLedDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (*RgbLedDriver) SetRGB

func (d *RgbLedDriver) SetRGB(r, g, b byte) error

SetRGB sets the Red Green Blue value of the LED.

func (RgbLedDriver) Start

func (d RgbLedDriver) Start() error

Start initializes the gpio device.

func (*RgbLedDriver) State

func (d *RgbLedDriver) State() bool

State return true if the led is On and false if the led is Off

func (*RgbLedDriver) Toggle

func (d *RgbLedDriver) Toggle() error

Toggle sets the led to the opposite of it's current state

type ServoDriver

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

ServoDriver Represents a Servo

func NewServoDriver

func NewServoDriver(a ServoWriter, pin string, opts ...interface{}) *ServoDriver

NewServoDriver returns a new ServoDriver given a ServoWriter and pin.

Supported options:

"WithName"

Adds the following API Commands:

"Move" - See ServoDriver.Move
"Min" - See ServoDriver.ToMin
"Center" - See ServoDriver.ToCenter
"Max" - See ServoDriver.ToMax

func (*ServoDriver) Angle added in v2.3.0

func (d *ServoDriver) Angle() uint8

Angle returns the current angle

func (ServoDriver) Connection

func (d ServoDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (ServoDriver) Halt

func (d ServoDriver) Halt() error

Halt halts the gpio device.

func (*ServoDriver) Move

func (d *ServoDriver) Move(angle uint8) error

Move sets the servo to the specified angle. Acceptable angles are 0-180

func (ServoDriver) Name

func (d ServoDriver) Name() string

Name returns the name of the gpio device.

func (ServoDriver) Pin

func (d ServoDriver) Pin() string

Pin returns the pin associated with the driver.

func (ServoDriver) SetName

func (d ServoDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (ServoDriver) Start

func (d ServoDriver) Start() error

Start initializes the gpio device.

func (*ServoDriver) ToCenter added in v2.3.0

func (d *ServoDriver) ToCenter() error

Center sets the servo to it's center position

func (*ServoDriver) ToMax added in v2.3.0

func (d *ServoDriver) ToMax() error

Max sets the servo to its maximum position

func (*ServoDriver) ToMin added in v2.3.0

func (d *ServoDriver) ToMin() error

Min sets the servo to it's minimum position

type ServoWriter

type ServoWriter interface {
	ServoWrite(pin string, val byte) error
}

ServoWriter interface represents an Adaptor which has Servo capabilities

type StepperDriver

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

StepperDriver is a common driver for stepper motors. It supports 3 different stepping modes.

func NewStepperDriver

func NewStepperDriver(
	a DigitalWriter,
	pins [4]string,
	phase phase,
	stepsPerRev uint,
	opts ...interface{},
) *StepperDriver

NewStepperDriver returns a new StepperDriver given a DigitalWriter Pins - To which the stepper is connected Phase - Defined by StepperModes {SinglePhaseStepping, DualPhaseStepping, HalfStepping} Steps - No of steps per revolution of Stepper motor

Supported options:

"WithName"

func (StepperDriver) Connection

func (d StepperDriver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (*StepperDriver) CurrentStep added in v2.3.0

func (d *StepperDriver) CurrentStep() int

CurrentStep gives the current step of motor

func (StepperDriver) Halt

func (d StepperDriver) Halt() error

Halt halts the gpio device.

func (*StepperDriver) IsMoving

func (d *StepperDriver) IsMoving() bool

IsMoving returns a bool stating whether motor is currently in motion

func (*StepperDriver) MaxSpeed added in v2.3.0

func (d *StepperDriver) MaxSpeed() uint

MaxSpeed gives the max RPM of motor max. speed is limited by: * motor friction, inertia and inductance, load inertia * full step rate is normally below 1000 per second (1kHz), typically not more than ~400 per second * mostly not more than 1000-2000rpm (20-40 revolutions per second) are possible * higher values can be achieved only by ramp-up the velocity * duration of GPIO write (PI1 can reach up to 70kHz, typically 20kHz, so this is most likely not the limiting factor) * the hardware driver, to force the high current transitions for the max. speed * there are CNC steppers with 1000..20.000 steps per revolution, which works with faster step rates (e.g. 200kHz)

func (*StepperDriver) Move

func (d *StepperDriver) Move(stepsToMove int) error

Move moves the motor for given number of steps.

func (*StepperDriver) MoveDeg added in v2.3.0

func (d *StepperDriver) MoveDeg(degs int) error

MoveDeg moves the motor given number of degrees at current speed. Negative values cause to move backward.

func (StepperDriver) Name

func (d StepperDriver) Name() string

Name returns the name of the gpio device.

func (StepperDriver) Pin added in v2.3.0

func (d StepperDriver) Pin() string

Pin returns the pin associated with the driver.

func (*StepperDriver) Run

func (d *StepperDriver) Run() error

Run runs the stepper continuously. Stop needs to be done with call Stop().

func (*StepperDriver) SetDirection

func (d *StepperDriver) SetDirection(direction string) error

SetDirection sets the direction in which motor should be moving, default is forward. Changing the direction affects the next step, also for asynchronous running.

func (*StepperDriver) SetHaltIfRunning added in v2.3.0

func (d *StepperDriver) SetHaltIfRunning(val bool)

SetHaltIfRunning with the given value. Normally a call of Run() returns an error if already running. If set this to true, the next call of Run() cause a automatic stop before.

func (StepperDriver) SetName

func (d StepperDriver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (*StepperDriver) SetSpeed

func (d *StepperDriver) SetSpeed(rpm uint) error

SetSpeed sets the rpm for the next move or run. A valid value is between 1 and MaxSpeed(). The run needs to be stopped and called again after set this value.

func (*StepperDriver) Sleep added in v2.3.0

func (d *StepperDriver) Sleep() error

Sleep release all pins to the same output level, so no current is consumed anymore.

func (StepperDriver) Start

func (d StepperDriver) Start() error

Start initializes the gpio device.

func (*StepperDriver) Stop added in v2.3.0

func (d *StepperDriver) Stop() error

Stop running the stepper

type TM1638Driver

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

TM1638Driver is the driver for modules based on the TM1638, which has 8 7-segment displays, 8 LEDs and 8 buttons. Buttons are not supported yet by this driver.

Datasheet EN: https://retrocip.cz/files/tm1638.pdf Datasheet CN: http://www.datasheetspdf.com/pdf/775356/TitanMicro/TM1638/1

Ported from the Arduino driver https://github.com/rjbatista/tm1638-library

func NewTM1638Driver

func NewTM1638Driver(a gobot.Connection, clockPin, dataPin, strobePin string, opts ...interface{}) *TM1638Driver

NewTM1638Driver return a new TM1638Driver given a gobot.Connection and the clock, data and strobe pins

Supported options:

"WithName"

func (*TM1638Driver) AddFonts

func (d *TM1638Driver) AddFonts(fonts map[string]byte)

AddFonts adds new custom fonts or modify the representation of existing ones

func (*TM1638Driver) ClearFonts

func (d *TM1638Driver) ClearFonts()

ClearFonts removes all the fonts from the driver

func (TM1638Driver) Connection

func (d TM1638Driver) Connection() gobot.Connection

Connection returns the connection of the gpio device.

func (TM1638Driver) Halt

func (d TM1638Driver) Halt() error

Halt halts the gpio device.

func (TM1638Driver) Name

func (d TM1638Driver) Name() string

Name returns the name of the gpio device.

func (TM1638Driver) Pin added in v2.3.0

func (d TM1638Driver) Pin() string

Pin returns the pin associated with the driver.

func (*TM1638Driver) SendChar

func (d *TM1638Driver) SendChar(pos byte, data byte, dot bool) error

SendChar sends one byte to the specific position in the display

func (*TM1638Driver) SetDisplay

func (d *TM1638Driver) SetDisplay(data []byte) error

SetDisplay cuts and sends a byte array to the display (without dots)

func (*TM1638Driver) SetDisplayText

func (d *TM1638Driver) SetDisplayText(text string) error

SetDisplayText cuts and sends a string to the display (without dots)

func (*TM1638Driver) SetLED

func (d *TM1638Driver) SetLED(color byte, pos byte) error

SetLED changes the color (TM1638None, TM1638Red, TM1638Green) of the specific LED

func (TM1638Driver) SetName

func (d TM1638Driver) SetName(name string)

SetName sets the name of the gpio device. Deprecated: Please use option gpio.WithName instead.

func (TM1638Driver) Start

func (d TM1638Driver) Start() error

Start initializes the gpio device.

Jump to

Keyboard shortcuts

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