Documentation ¶
Overview ¶
Package firmata provides the Gobot adaptor for microcontrollers that support the Firmata protocol.
Installing:
go get -d -u gobot.io/x/gobot/... && go get gobot.io/x/gobot/platforms/firmata
Example:
package main import ( "time" "gobot.io/x/gobot" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/firmata" ) func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
For further information refer to firmata readme: https://github.com/hybridgroup/gobot/blob/master/platforms/firmata/README.md
Index ¶
- Constants
- func NewFirmataI2cConnection(adaptor *Adaptor, address int) (connection *firmataI2cConnection)
- type Adaptor
- func (f *Adaptor) AnalogRead(pin string) (val int, err error)
- func (f *Adaptor) Board() FirmataBoard
- func (f *Adaptor) Connect() (err error)
- func (f *Adaptor) DigitalRead(pin string) (val int, err error)
- func (f *Adaptor) DigitalWrite(pin string, level byte) (err error)
- func (f *Adaptor) Disconnect() (err error)
- func (f *Adaptor) Finalize() (err error)
- func (f *Adaptor) GetConnection(address int, bus int) (connection i2c.Connection, err error)
- func (f *Adaptor) GetDefaultBus() int
- func (f *Adaptor) Name() string
- func (f *Adaptor) Port() string
- func (f *Adaptor) PulseIn(pin string, value int, timeout time.Duration) (time.Duration, error)
- func (f *Adaptor) PwmWrite(pin string, level byte) (err error)
- func (f *Adaptor) ServoConfig(pin string, min, max int) error
- func (f *Adaptor) ServoWrite(pin string, angle byte) (err error)
- func (f *Adaptor) SetName(n string)
- type BLEAdaptor
- type FirmataBoard
- type TCPAdaptor
Constants ¶
const ( // ReceiveID is the BLE characteristic ID for receiving serial data ReceiveID = "6e400003b5a3f393e0a9e50e24dcca9e" // TransmitID is the BLE characteristic ID for transmitting serial data TransmitID = "6e400002b5a3f393e0a9e50e24dcca9e" )
Variables ¶
This section is empty.
Functions ¶
func NewFirmataI2cConnection ¶
NewFirmataI2cConnection creates an I2C connection to an I2C device at the specified address
Types ¶
type Adaptor ¶
type Adaptor struct { PortOpener func(port string) (io.ReadWriteCloser, error) gobot.Eventer // contains filtered or unexported fields }
Adaptor is the Gobot Adaptor for Firmata based boards
func NewAdaptor ¶
func NewAdaptor(args ...interface{}) *Adaptor
NewAdaptor returns a new Firmata Adaptor which optionally accepts:
string: port the Adaptor uses to connect to a serial port with a baude rate of 57600 io.ReadWriteCloser: connection the Adaptor uses to communication with the hardware
If an io.ReadWriteCloser is not supplied, the Adaptor will open a connection to a serial port with a baude rate of 57600. If an io.ReadWriteCloser is supplied, then the Adaptor will use the provided io.ReadWriteCloser and use the string port as a label to be displayed in the log and api.
func (*Adaptor) AnalogRead ¶
AnalogRead retrieves value from analog pin. Returns -1 if the response from the board has timed out
func (*Adaptor) Board ¶
func (f *Adaptor) Board() FirmataBoard
Board returns the underlying Firmata protocol driver.
func (*Adaptor) DigitalRead ¶
DigitalRead retrieves digital value from specified pin. Returns -1 if the response from the board has timed out
func (*Adaptor) DigitalWrite ¶
DigitalWrite writes a value to the pin. Acceptable values are 1 or 0.
func (*Adaptor) Disconnect ¶
Disconnect closes the io connection to the board
func (*Adaptor) GetConnection ¶
GetConnection returns an i2c connection to a device on a specified bus. Only supports bus number 0
func (*Adaptor) GetDefaultBus ¶
GetDefaultBus returns the default i2c bus for this platform
func (*Adaptor) ServoConfig ¶
ServoConfig sets the pulse width in microseconds for a pin attached to a servo
func (*Adaptor) ServoWrite ¶
ServoWrite writes the 0-180 degree angle to the specified pin.
type BLEAdaptor ¶
type BLEAdaptor struct {
*Adaptor
}
BLEAdaptor represents a Bluetooth LE based connection to a microcontroller running FirmataBLE
func NewBLEAdaptor ¶
func NewBLEAdaptor(args ...interface{}) *BLEAdaptor
NewBLEAdaptor opens and uses a BLE connection to a microcontroller running FirmataBLE
type FirmataBoard ¶
type FirmataBoard interface { Connect(io.ReadWriteCloser) error Disconnect() error Pins() []client.Pin AnalogWrite(int, int) error SetPinMode(int, int) error ReportAnalog(int, int) error ReportDigital(int, int) error DigitalWrite(int, int) error I2cRead(int, int) error I2cWrite(int, []byte) error I2cConfig(int) error ServoConfig(int, int, int) error gobot.Eventer }
FirmataBoard is the interface for the underlying Firmata protocol driver.
type TCPAdaptor ¶
type TCPAdaptor struct {
*Adaptor
}
TCPAdaptor represents a TCP based connection to a microcontroller running WiFiFirmata
func NewTCPAdaptor ¶
func NewTCPAdaptor(args ...interface{}) *TCPAdaptor
NewTCPAdaptor opens and uses a TCP connection to a microcontroller running WiFiFirmata
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package client provies a client for interacting with microcontrollers using the Firmata protocol https://github.com/firmata/protocol.
|
Package client provies a client for interacting with microcontrollers using the Firmata protocol https://github.com/firmata/protocol. |