firmata

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: Apache-2.0, Apache-2.0 Imports: 10 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

You can connect to the microcontroller using either a serial connection, or a TCP connection to a WiFi-connected microcontroller such as the ESP8266.

For more info about the Arduino platform, go to http://arduino.cc/.

How to Install

go get -d -u gobot.io/x/gobot/...

You must install Firmata on your microcontroller before you can connect to it using Gobot. You can do this in many cases using Gort (http://gort.io).

In order to use a TCP connection with a WiFi-enbaled microcontroller, you must install WifiFirmata on the microcontroller. You can use the Arduino IDE to do this.

How to Use

With a serial connection:

package main

import (
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/firmata"
)

func main() {
	firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
	led := gpio.NewLedDriver(firmataAdaptor, "13")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("bot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{led},
		work,
	)

	robot.Start()
}

With a TCP connection, use the NewTCPAdaptor:

package main

import (
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/firmata"
)

func main() {
	firmataAdaptor := firmata.NewTCPAdaptor("192.168.0.66:3030")
	led := gpio.NewLedDriver(firmataAdaptor, "2")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("bot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{led},
		work,
	)

	robot.Start()
}

Important note that analog pins A4 and A5 are normally used by the Firmata I2C interface, so you will not be able to use them as analog inputs without changing the Firmata sketch.

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

Note that Gobot works best with the tty. version of the serial port as shown above, not the cu. version.

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 known to work:

- [Arduino Uno R3](http://arduino.cc/en/Main/arduinoBoardUno)
- [Arduino/Genuino 101](https://www.arduino.cc/en/Main/ArduinoBoard101)
- [Teensy 3.0](http://www.pjrc.com/store/teensy3.html)

The following WiFi devices have been tested and are known to work: - NodeMCU 1.0

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 gobot.io/x/gobot/... && go get gobot.io/x/gobot/platforms/firmata

Example:

package main

import (
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/firmata"
)

func main() {
	firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
	led := gpio.NewLedDriver(firmataAdaptor, "13")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("bot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{led},
		work,
	)

	robot.Start()
}

For further information refer to firmata readme: https://github.com/hybridgroup/gobot/blob/master/platforms/firmata/README.md

Index

Constants

View Source
const (
	// ReceiveID is the BLE characteristic ID for receiving serial data
	ReceiveID = "6e400003b5a3f393e0a9e50e24dcca9e"

	// TransmitID is the BLE characteristic ID for transmitting serial data
	TransmitID = "6e400002b5a3f393e0a9e50e24dcca9e"
)

Variables

This section is empty.

Functions

func NewFirmataI2cConnection added in v1.2.0

func NewFirmataI2cConnection(adaptor *Adaptor, address int) (connection *firmataI2cConnection)

NewFirmataI2cConnection creates an I2C connection to an I2C device at the specified address

Types

type Adaptor added in v1.0.0

type Adaptor struct {
	Board firmataBoard

	PortOpener func(port string) (io.ReadWriteCloser, error)
	gobot.Eventer
	// contains filtered or unexported fields
}

Adaptor is the Gobot Adaptor for Firmata based boards

func NewAdaptor added in v1.0.0

func NewAdaptor(args ...interface{}) *Adaptor

NewAdaptor returns a new Firmata Adaptor which optionally accepts:

string: port the Adaptor uses to connect to a serial port with a baude rate of 57600
io.ReadWriteCloser: connection the Adaptor uses to communication with the hardware

If an io.ReadWriteCloser is not supplied, the Adaptor will open a connection to a serial port with a baude rate of 57600. If an io.ReadWriteCloser is supplied, then the Adaptor will use the provided io.ReadWriteCloser and use the string port as a label to be displayed in the log and api.

func (*Adaptor) AnalogRead added in v1.0.0

func (f *Adaptor) 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 (*Adaptor) Connect added in v1.0.0

func (f *Adaptor) Connect() (err error)

Connect starts a connection to the board.

func (*Adaptor) DigitalRead added in v1.0.0

func (f *Adaptor) 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 (*Adaptor) DigitalWrite added in v1.0.0

func (f *Adaptor) DigitalWrite(pin string, level byte) (err error)

DigitalWrite writes a value to the pin. Acceptable values are 1 or 0.

func (*Adaptor) Disconnect added in v1.0.0

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

Disconnect closes the io connection to the Board

func (*Adaptor) Finalize added in v1.0.0

func (f *Adaptor) Finalize() (err error)

Finalize terminates the firmata connection

func (*Adaptor) GetConnection added in v1.2.0

func (f *Adaptor) GetConnection(address int, bus int) (connection i2c.Connection, err error)

GetConnection returns an i2c connection to a device on a specified bus. Only supports bus number 0

func (*Adaptor) GetDefaultBus added in v1.2.0

func (f *Adaptor) GetDefaultBus() int

GetDefaultBus returns the default i2c bus for this platform

func (*Adaptor) Name added in v1.0.0

func (f *Adaptor) Name() string

Name returns the Firmata Adaptors name

func (*Adaptor) Port added in v1.0.0

func (f *Adaptor) Port() string

Port returns the Firmata Adaptors port

func (*Adaptor) PwmWrite added in v1.0.0

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

PwmWrite writes the 0-254 value to the specified pin

func (*Adaptor) ServoConfig added in v1.0.0

func (f *Adaptor) ServoConfig(pin string, min, max int) error

ServoConfig sets the pulse width in microseconds for a pin attached to a servo

func (*Adaptor) ServoWrite added in v1.0.0

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

ServoWrite writes the 0-180 degree angle to the specified pin.

func (*Adaptor) SetName added in v1.0.0

func (f *Adaptor) SetName(n string)

SetName sets the Firmata Adaptors name

func (*Adaptor) WriteSysex added in v1.6.0

func (f *Adaptor) WriteSysex(data []byte) error

type BLEAdaptor added in v1.2.0

type BLEAdaptor struct {
	*Adaptor
}

BLEAdaptor represents a Bluetooth LE based connection to a microcontroller running FirmataBLE

func NewBLEAdaptor added in v1.2.0

func NewBLEAdaptor(args ...interface{}) *BLEAdaptor

NewBLEAdaptor opens and uses a BLE connection to a microcontroller running FirmataBLE

type FirmataAdaptor

type FirmataAdaptor interface {
	Connect() (err error)
	Finalize() (err error)
	Name() string
	SetName(n string)
	WriteSysex(data []byte) error
	gobot.Eventer
}

type TCPAdaptor added in v1.1.0

type TCPAdaptor struct {
	*Adaptor
}

TCPAdaptor represents a TCP based connection to a microcontroller running WiFiFirmata

func NewTCPAdaptor added in v1.1.0

func NewTCPAdaptor(args ...interface{}) *TCPAdaptor

NewTCPAdaptor opens and uses a TCP connection to a microcontroller running WiFiFirmata

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