firmata

package
v0.0.0-...-79c9657 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2015 License: Apache-2.0, Apache-2.0 Imports: 8 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 -d -u 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()
}

How to Connect

Upload the Firmata Firmware to the Arduino

This section assumes you're using an Arduino Uno or another compatible board. If you already have the Firmata sketch installed, you can skip straight to the examples.

OS X

First plug the Arduino into your computer via the USB/serial port. A dialog box will appear telling you that a new network interface has been detected. Click "Network Preferences...", and when it opens, simply click "Apply".

Once plugged in, use Gort's gort scan serial command to find out your connection info and serial port address:

$ gort scan serial

Use the gort arduino install command to install avrdude, this will allow you to upload firmata to the arduino:

$ gort arduino install

Once the avrdude uploader is installed we upload the firmata protocol to the arduino, use the arduino serial port address found when you ran gort scan serial:

$ gort arduino upload firmata /dev/tty.usbmodem1421

Now you are ready to connect and communicate with the Arduino using serial port connection

Ubuntu

First plug the Arduino into your computer via the USB/serial port.

Once plugged in, use Gort's gort scan serial command to find out your connection info and serial port address:

$ gort scan serial

Use the gort arduino install command to install avrdude, this will allow you to upload firmata to the arduino:

$ gort arduino install

Once the avrdude uploader is installed we upload the firmata protocol to the arduino, use the arduino serial port address found when you ran gort scan serial, or leave it blank to use the default address ttyACM0:

$ gort arduino upload firmata /dev/ttyACM0

Now you are ready to connect and communicate with the Arduino using serial port connection

Windows

First download and install gort for your OS from the gort.io downloads page and install it.

Open a command prompt window by right clicking on the start button and choose Command Prompt (Admin) (on windows 8.1). Then navigate to the folder where you uncompressed gort (uncomress to a folder first if you haven't done this yet).

Once inside the gort folder, first install avrdude which we'll use to upload firmata to the arduino.

$ gort arduino install

When the installation is complete, close the command prompt window and open a new one. We need to do this for the env variables to reload.

$ gort scan serial

Take note of your arduinos serialport address (COM1 | COM2 | COM3| etc). You need to already have installed the arduino drivers from arduino.cc/en/Main/Software. Finally upload the firmata protocol sketch to the arduino.

$ gort arduino upload firmata <COMX>

Make sure to substitute <COMX> with the apropiate serialport address.

Now you are ready to connect and communicate with the Arduino using serial port connection.

Using arduino IDE

Open arduino IDE and go to File > Examples > Firmata > StandardFirmata and open it. Select the appriate port for your arduino and click upload. Wait for the upload to finish and you should be ready to start using Gobot with your arduino.

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

Jump to

Keyboard shortcuts

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