gofirmata: github.com/choffee/gofirmata Index | Files

package firmata

import "github.com/choffee/gofirmata"

Package: Firmata

This is a binding for the arduino Firmata package.

You need to burn the simple Firmata image onto your Arduino then you
can control it over the USB using this library.

import "github.com/choffee/gofirmata"

func main () {

  board, err := NewBoard("/dev/ttyUSB1", 57600)
  if err != nil {
    log.Fatal("Could not setup board")
  }
  // Set the mode of a pin
  println("set 13 to output")
  board.SetPinMode(13,MODE_OUTPUT)

  // Turn on pin 13
  println("set 13 to 1")
  board.WriteDigital(13,1)
}

Pins and colors

Index

Package Files

firmata.go led.go

Constants

const (
    MODE_INPUT  byte = 0x00
    MODE_OUTPUT byte = 0x01
    MODE_ANALOG byte = 0x02
    MODE_PWM    byte = 0x03
    MODE_SERVO  byte = 0x04
    MODE_SHIFT  byte = 0x05
    MODE_I2C    byte = 0x06

    I2C_MODE_WRITE           byte = 0x00
    I2C_MODE_READ            byte = 0x01
    I2C_MODE_CONTINIOUS_READ byte = 0x02
    I2C_MODE_STOP_READING    byte = 0x03

    HIGH byte = 1
    LOW  byte = 0

    UNKNOWN                 byte = 0xFF // I just invented this it could be used elsewhere
    START_SYSEX             byte = 0xF0 // start a MIDI Sysex message
    END_SYSEX               byte = 0xF7 // end a MIDI Sysex message
    PIN_MODE_QUERY          byte = 0x72 // ask for current and supported pin modes
    PIN_MODE_RESPONSE       byte = 0x73 // reply with current and supported pin modes
    PIN_STATE_QUERY         byte = 0x6D
    PIN_STATE_RESPONSE      byte = 0x6E
    CAPABILITY_QUERY        byte = 0x6B
    CAPABILITY_RESPONSE     byte = 0x6C
    ANALOG_MAPPING_QUERY    byte = 0x69
    ANALOG_MAPPING_RESPONSE byte = 0x6A
    REPORT_FIRMWARE         byte = 0x79 // report name and version of the firmware
    PIN_MODE                byte = 0xF4 // Set the pin mode
    ANALOG_MESSAGE          byte = 0xE0
    I2C_REQUEST             byte = 0x76
    I2C_REPLY               byte = 0x77
    I2C_CONFIG              byte = 0x78
    SAMPLING_INTERVAL       byte = 0x7A

    DIGITAL_WRITE byte = 0x90
    DIGITAL_READ  byte = 0xD0
    ANALOG_WRITE  byte = 0xE0
    ANALOG_READ   byte = 0xC0
    PROTOCOL_VER  byte = 0xF9
)

Variables

var Colors = map[string][3]byte{
    "red":   [3]byte{0xFF, 00, 00},
    "green": [3]byte{00, 0xFF, 00},
    "blue":  [3]byte{00, 00, 0xFF},
    "black": [3]byte{00, 00, 00},
    "white": [3]byte{0xFF, 0xFF, 0xFF},
}

func FromHex Uses

func FromHex(s string) ([3]byte, error)

type Board Uses

type Board struct {
    Name string

    Debug int // 0 no debug

    Reader chan FirmataMsg
    Writer chan FirmataMsg
    // contains filtered or unexported fields
}

func NewBoard Uses

func NewBoard(device string, baud int) (*Board, error)

Setup the board to start reading and writing It needs a device in the format "/dev/ttyUSB0" and a baud rate eg. 57600

func (*Board) Baud Uses

func (board *Board) Baud() int

Return the baud rate the device is using

func (*Board) Device Uses

func (board *Board) Device() string

Return the Device the board is using

func (*Board) GetAnalogMapping Uses

func (board *Board) GetAnalogMapping()

func (*Board) GetCapabilities Uses

func (board *Board) GetCapabilities()

func (*Board) GetReader Uses

func (board *Board) GetReader()

Sets up the reader channel You can then fetch read events from <- board.Reader

func (*Board) I2CConfig Uses

func (board *Board) I2CConfig(delay int)

Send the I2C config command Should be run before sending I2C commands

func (*Board) I2CWrite Uses

func (board *Board) I2CWrite(addr, mode byte, msg []byte)

Send an I2C message addr is the address on the I2C bus to send it too msg is a slice containg the message to send mode: Should be one of I2C_MODE_WRITE, I2C_MODE_READ,

I2C_MODE_CONTINIOUS_READ or I2C_MODE_STOP_READING

We are only supporting 7bit addresses

func (*Board) SetPinMode Uses

func (board *Board) SetPinMode(pin, mode byte)

Set the mode for a pin mode should be one of: MODE_INPUT MODE_OUTPUT, MODE_ANALOG,

MODE_PWM, MODE_SERVO, MODE_SHIFT, MODE_I2C

func (*Board) SetReadAnalog Uses

func (board *Board) SetReadAnalog(pin, state byte)

Starts and stops the analog pin reporting state: 0/1 disable/enable

func (*Board) SetReadDigital Uses

func (board *Board) SetReadDigital(pin, state byte)

Starts and stops the digital pin reading for a port state: 0/1 disable/enable ( It start reading for the whole port )

func (*Board) SetSamplingInterval Uses

func (board *Board) SetSamplingInterval(interval int)

Send analog report interval command interval (millisecond)

func (*Board) Version Uses

func (board *Board) Version() map[string]byte

Show the board version

func (*Board) WriteAnalog Uses

func (board *Board) WriteAnalog(pin, value byte)

Write an analog value to a pin

func (*Board) WriteDigital Uses

func (board *Board) WriteDigital(pin, value byte)

Write a value to a pin value should be firmata.HIGH or firmata.LOW

type ColorError Uses

type ColorError struct {
    Desc string
}

An error if we get a bad color

func (ColorError) Error Uses

func (e ColorError) Error() string

type FirmataMsg Uses

type FirmataMsg struct {
    // contains filtered or unexported fields
}

type RGBLED Uses

type RGBLED struct {
    Red, Green, Blue byte
    Invert           bool
    // contains filtered or unexported fields
}

A type for holding some colors You can set the color bytes The invert bool is for LED's that are wired backwards.

func NewRGBLED Uses

func NewRGBLED(rp, gp, bp uint8) *RGBLED

Create a new RGB LED Expects to have the pin numbers

func (*RGBLED) Color Uses

func (l *RGBLED) Color(c [3]byte)

Set the color values from 3 byte array

func (*RGBLED) HexString Uses

func (l *RGBLED) HexString() string

Return the color of the LED as a hex string "RRGGBB"

func (*RGBLED) Pins Uses

func (l *RGBLED) Pins(r, g, b uint8)

Set the LED pins

func (*RGBLED) QuickColor Uses

func (l *RGBLED) QuickColor(s string) error

Given a string try and convert it to a color Strings like "blue", "red" "green" or "#FFFE34" or "DEDEDE"

func (*RGBLED) SendColor Uses

func (l *RGBLED) SendColor(b *Board)

Send the current color of this led to the board

func (*RGBLED) SetupPins Uses

func (l *RGBLED) SetupPins(b *Board)

Package firmata imports 7 packages (graph) and is imported by 1 packages. Updated 2016-07-29. Refresh now. Tools for package owners.