firmata

package
v0.0.0-...-1595f01 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2014 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

README

Firmata

This package provides the adaptor for microcontrollers such as Arduino that support the Firmata protocol

Getting Started

go get github.com/hybridgroup/gobot && go install 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()
}

Hardware Support

The following firmata devices have been tested and are currently supported:

More devices are coming soon...

Documentation

Overview

Package firmata provides the Gobot adaptor for microcontrollers that support the Firmata protocol.

Installing:

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FirmataAdaptor

type FirmataAdaptor struct {
	gobot.Adaptor
	// contains filtered or unexported fields
}

func NewFirmataAdaptor

func NewFirmataAdaptor(name, port string) *FirmataAdaptor

NewFirmataAdaptor returns a new firmata adaptor with specified name Generates a connect function that opens serial communication in specified port

func (*FirmataAdaptor) AnalogRead

func (f *FirmataAdaptor) AnalogRead(pin string) int

AnalogRead retrieves value from analog pin. NOTE pins are numbered A0-A5, which translate to digital pins 14-19

func (*FirmataAdaptor) AnalogWrite

func (f *FirmataAdaptor) AnalogWrite(pin string, level byte)

AnalogWrite writes value to ananlog pin

func (*FirmataAdaptor) Connect

func (f *FirmataAdaptor) Connect() bool

Connect returns true if connection to board is succesfull

func (*FirmataAdaptor) DigitalRead

func (f *FirmataAdaptor) DigitalRead(pin string) int

DigitalRead retrieves digital value from specified pin Returns -1 if response from board is timed out

func (*FirmataAdaptor) DigitalWrite

func (f *FirmataAdaptor) DigitalWrite(pin string, level byte)

DigitalWrite writes digital values to specified pin

func (*FirmataAdaptor) Disconnect

func (f *FirmataAdaptor) Disconnect() bool

close finishes connection to serial port Prints error message on error

func (*FirmataAdaptor) Finalize

func (f *FirmataAdaptor) Finalize() bool

Finalize disconnects firmata adaptor

func (*FirmataAdaptor) I2cRead

func (f *FirmataAdaptor) I2cRead(size uint) []byte

I2cRead reads from I2c specified size Returns empty byte array if response is timed out

func (*FirmataAdaptor) I2cStart

func (f *FirmataAdaptor) I2cStart(address byte)

I2cStart initializes board with i2c configuration

func (*FirmataAdaptor) I2cWrite

func (f *FirmataAdaptor) I2cWrite(data []byte)

I2cWrite retrieves i2c data

func (*FirmataAdaptor) InitServo

func (f *FirmataAdaptor) InitServo()

InitServo (not yet implemented)

func (*FirmataAdaptor) PwmWrite

func (f *FirmataAdaptor) PwmWrite(pin string, level byte)

PwmWrite writes analog value to specified pin

func (*FirmataAdaptor) ServoWrite

func (f *FirmataAdaptor) ServoWrite(pin string, angle byte)

ServoWrite sets angle form 0 to 360 to specified servo pin

type FirmataEthernetAdaptor

type FirmataEthernetAdaptor struct {
	gobot.Adaptor
	// contains filtered or unexported fields
}

func NewFirmataEthernetAdaptor

func NewFirmataEthernetAdaptor(name, sockAddress string) *FirmataEthernetAdaptor

NewFirmataEthernetAdaptor returns a new firmata adaptor with specified name Generates a connect function that opens serial communication in specified port

func (*FirmataEthernetAdaptor) AnalogRead

func (f *FirmataEthernetAdaptor) AnalogRead(pin string) int

AnalogRead retrieves value from analog pin. NOTE pins are numbered A0-A5, which translate to digital pins 14-19

func (*FirmataEthernetAdaptor) AnalogWrite

func (f *FirmataEthernetAdaptor) AnalogWrite(pin string, level byte)

AnalogWrite writes value to ananlog pin

func (*FirmataEthernetAdaptor) Connect

func (f *FirmataEthernetAdaptor) Connect() bool

Connect returns true if connection to board is succesfull

func (*FirmataEthernetAdaptor) DigitalRead

func (f *FirmataEthernetAdaptor) DigitalRead(pin string) int

DigitalRead retrieves digital value from specified pin Returns -1 if response from board is timed out

func (*FirmataEthernetAdaptor) DigitalWrite

func (f *FirmataEthernetAdaptor) DigitalWrite(pin string, level byte)

DigitalWrite writes digital values to specified pin

func (*FirmataEthernetAdaptor) Disconnect

func (f *FirmataEthernetAdaptor) Disconnect() bool

close finishes connection to serial port Prints error message on error

func (*FirmataEthernetAdaptor) Finalize

func (f *FirmataEthernetAdaptor) Finalize() bool

Finalize disconnects firmata adaptor

func (*FirmataEthernetAdaptor) I2cRead

func (f *FirmataEthernetAdaptor) I2cRead(size uint) []byte

I2cRead reads from I2c specified size Returns empty byte array if response is timed out

func (*FirmataEthernetAdaptor) I2cStart

func (f *FirmataEthernetAdaptor) I2cStart(address byte)

I2cStart initializes board with i2c configuration

func (*FirmataEthernetAdaptor) I2cWrite

func (f *FirmataEthernetAdaptor) I2cWrite(data []byte)

I2cWrite retrieves i2c data

func (*FirmataEthernetAdaptor) InitServo

func (f *FirmataEthernetAdaptor) InitServo()

InitServo (not yet implemented)

func (*FirmataEthernetAdaptor) PwmWrite

func (f *FirmataEthernetAdaptor) PwmWrite(pin string, level byte)

PwmWrite writes analog value to specified pin

func (*FirmataEthernetAdaptor) ServoWrite

func (f *FirmataEthernetAdaptor) ServoWrite(pin string, angle byte)

ServoWrite sets angle form 0 to 360 to specified servo pin

Jump to

Keyboard shortcuts

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