firmata

package
v0.0.0-...-21b411a Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2014 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 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
}

func NewFirmataAdaptor

func NewFirmataAdaptor(name string, args ...interface{}) *FirmataAdaptor

NewFirmataAdaptor returns a new firmata adaptor 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. NOTE pins are numbered A0-A5, which translate to digital pins 14-19

func (*FirmataAdaptor) Connect

func (f *FirmataAdaptor) Connect() (errs []error)

Connect returns true if connection to board is succesfull

func (*FirmataAdaptor) DigitalRead

func (f *FirmataAdaptor) DigitalRead(pin string) (val int, err error)

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

DigitalWrite writes digital values to specified pin

func (*FirmataAdaptor) Disconnect

func (f *FirmataAdaptor) Disconnect() (err error)

close finishes connection to serial port Prints error message on error

func (*FirmataAdaptor) Finalize

func (f *FirmataAdaptor) Finalize() (errs []error)

Finalize disconnects firmata adaptor

func (*FirmataAdaptor) I2cRead

func (f *FirmataAdaptor) I2cRead(size uint) (data []byte, err error)

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

func (*FirmataAdaptor) I2cStart

func (f *FirmataAdaptor) I2cStart(address byte) (err error)

I2cStart initializes board with i2c configuration

func (*FirmataAdaptor) I2cWrite

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

I2cWrite retrieves i2c data

func (*FirmataAdaptor) Name

func (f *FirmataAdaptor) Name() string

func (*FirmataAdaptor) Port

func (f *FirmataAdaptor) Port() string

func (*FirmataAdaptor) PwmWrite

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

PwmWrite writes analog value to specified pin

func (*FirmataAdaptor) ServoWrite

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

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