Documentation ¶
Overview ¶
Package firmata provides the Gobot adaptor for microcontrollers that support the Firmata protocol.
Installing:
go get -d -u github.com/hybridgroup/gobot/... && go get github.com/hybridgroup/gobot/platforms/firmata
Example:
package main import ( "time" "github.com/hybridgroup/gobot" "github.com/hybridgroup/gobot/platforms/firmata" "github.com/hybridgroup/gobot/platforms/gpio" ) func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "led", "13") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
For further information refer to firmata readme: https://github.com/hybridgroup/gobot/blob/master/platforms/firmata/README.md
Index ¶
- type FirmataAdaptor
- func (f *FirmataAdaptor) AnalogRead(pin string) (val int, err error)
- func (f *FirmataAdaptor) Connect() (errs []error)
- func (f *FirmataAdaptor) DigitalRead(pin string) (val int, err error)
- func (f *FirmataAdaptor) DigitalWrite(pin string, level byte) (err error)
- func (f *FirmataAdaptor) Disconnect() (err error)
- func (f *FirmataAdaptor) Finalize() (errs []error)
- func (f *FirmataAdaptor) I2cRead(address int, size int) (data []byte, err error)
- func (f *FirmataAdaptor) I2cStart(address int) (err error)
- func (f *FirmataAdaptor) I2cWrite(address int, data []byte) (err error)
- func (f *FirmataAdaptor) Name() string
- func (f *FirmataAdaptor) Port() string
- func (f *FirmataAdaptor) PwmWrite(pin string, level byte) (err error)
- func (f *FirmataAdaptor) ServoWrite(pin string, angle byte) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FirmataAdaptor ¶
type FirmataAdaptor struct {
// contains filtered or unexported fields
}
FirmataAdaptor is the Gobot Adaptor for Firmata based boards
func NewFirmataAdaptor ¶
func NewFirmataAdaptor(name string, args ...interface{}) *FirmataAdaptor
NewFirmataAdaptor returns a new FirmataAdaptor with specified name and optionally accepts:
string: port the FirmataAdaptor uses to connect to a serial port with a baude rate of 57600 io.ReadWriteCloser: connection the FirmataAdaptor uses to communication with the hardware
If an io.ReadWriteCloser is not supplied, the FirmataAdaptor will open a connection to a serial port with a baude rate of 57600. If an io.ReadWriteCloser is supplied, then the FirmataAdaptor will use the provided io.ReadWriteCloser and use the string port as a label to be displayed in the log and api.
func (*FirmataAdaptor) AnalogRead ¶
func (f *FirmataAdaptor) AnalogRead(pin string) (val int, err error)
AnalogRead retrieves value from analog pin. Returns -1 if the response from the board has timed out
func (*FirmataAdaptor) Connect ¶
func (f *FirmataAdaptor) Connect() (errs []error)
Connect starts a connection to the board.
func (*FirmataAdaptor) DigitalRead ¶
func (f *FirmataAdaptor) DigitalRead(pin string) (val int, err error)
DigitalRead retrieves digital value from specified pin. Returns -1 if the response from the board has timed out
func (*FirmataAdaptor) DigitalWrite ¶
func (f *FirmataAdaptor) DigitalWrite(pin string, level byte) (err error)
DigitalWrite writes a value to the pin. Acceptable values are 1 or 0.
func (*FirmataAdaptor) Disconnect ¶
func (f *FirmataAdaptor) Disconnect() (err error)
Disconnect closes the io connection to the board
func (*FirmataAdaptor) Finalize ¶
func (f *FirmataAdaptor) Finalize() (errs []error)
Finalize terminates the firmata connection
func (*FirmataAdaptor) I2cRead ¶
func (f *FirmataAdaptor) I2cRead(address int, size int) (data []byte, err error)
I2cRead returns size bytes from the i2c device Returns an empty array if the response from the board has timed out
func (*FirmataAdaptor) I2cStart ¶
func (f *FirmataAdaptor) I2cStart(address int) (err error)
I2cStart starts an i2c device at specified address
func (*FirmataAdaptor) I2cWrite ¶
func (f *FirmataAdaptor) I2cWrite(address int, data []byte) (err error)
I2cWrite writes data to i2c device
func (*FirmataAdaptor) Name ¶
func (f *FirmataAdaptor) Name() string
Name returns the FirmataAdaptors name
func (*FirmataAdaptor) Port ¶
func (f *FirmataAdaptor) Port() string
Port returns the FirmataAdaptors port
func (*FirmataAdaptor) PwmWrite ¶
func (f *FirmataAdaptor) PwmWrite(pin string, level byte) (err error)
PwmWrite writes the 0-254 value to the specified pin
func (*FirmataAdaptor) ServoWrite ¶
func (f *FirmataAdaptor) ServoWrite(pin string, angle byte) (err error)
ServoWrite writes the 0-180 degree angle to the specified pin.
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. |