firmata

package
v0.0.0-...-ebf36af Latest Latest
Warning

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

Go to latest
Published: May 1, 2015 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0

README

Firmata

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments.

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

For more info about the arduino platform click here.

How to Install

go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/firmata

How to Use

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 -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

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(size uint) (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 byte) (err error)

I2cStart starts an i2c device at specified address

func (*FirmataAdaptor) I2cWrite

func (f *FirmataAdaptor) I2cWrite(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.

Jump to

Keyboard shortcuts

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