goduino

package module
v0.0.0-...-4be33c3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

goduino

Go's package for Arduino

Goduino uses Firmata protocol for Arduino

GoDoc

Referenced from platforms/firmata of gobot

Prerequisites

  1. Download and install the Arduio IDE
  2. Plug in your Arduino via USB
  3. Open the Arduino IDE and open: File > Examples > StandardFirmata
  4. Select Arduino´s board: Tools > Board
  5. Select Arduino´s serial port: Tools > Serial Port
  6. Click the Upload button

Installation

	go get github.com/argandas/goduino

Usage

package main

import (
	"fmt"
	"github.com/argandas/goduino"
	"time"
)

func main() {
	arduino := goduino.New("myArduino", "COM1")
	err := arduino.Connect()
	defer arduino.Disconnect()
	if err != nil {
		fmt.Println(err)
	}
	arduino.PinMode(13, goduino.Output)
	for {
		arduino.DigitalWrite(13, 1)
		arduino.Delay(time.Millisecond * 500)
		arduino.DigitalWrite(13, 0)
		arduino.Delay(time.Millisecond * 500)
	}
}

Note: For this example the selected serial port is COM1, be sure your Arduino is connected on this serial port.

Stable versions

This package has been tested on Go v1.4.2 & Firmata v2.4

Documentation

Index

Constants

View Source
const (
	Input  = firmata.Input
	Output = firmata.Output
	Analog = firmata.Analog
	Pwm    = firmata.Pwm
	Servo  = firmata.Servo
	Pullup = firmata.Pullup
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Goduino

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

Arduino Firmata client for golang

func New

func New(name string, args ...interface{}) *Goduino

Creates a new Goduino object and connects to the Arduino board over specified serial port. This function blocks till a connection is succesfullt established and pin mappings are retrieved.

func (*Goduino) AnalogRead

func (ino *Goduino) AnalogRead(pin int) (value int, err error)

AnalogRead retrieves value from analog pin. Returns -1 if the response from the board has timed out

func (*Goduino) AnalogWrite

func (ino *Goduino) AnalogWrite(pin, value int) error

func (*Goduino) Connect

func (ino *Goduino) Connect() error

Connect starts a connection to the firmata board.

func (*Goduino) Delay

func (ino *Goduino) Delay(duration time.Duration)

Close the serial connection to properly clean up after ourselves Usage: defer client.Close()

func (*Goduino) DigitalRead

func (ino *Goduino) DigitalRead(pin int) (value int, err error)

DigitalRead reads the value from a specified digital pin, either HIGH or LOW.

func (*Goduino) DigitalWrite

func (ino *Goduino) DigitalWrite(pin, value int) error

DigitalWrite write a HIGH or a LOW value to a digital pin.

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.

func (*Goduino) Disconnect

func (ino *Goduino) Disconnect() (err error)

Disconnect closes the io connection to the firmata board

func (*Goduino) Name

func (ino *Goduino) Name() string

Name returns the FirmataAdaptors name

func (*Goduino) NeopixelControl

func (ino *Goduino) NeopixelControl(pin int, numpixels int, color int, state int) (err error)

NeopixelControl set state of neopixel.

func (*Goduino) PinMode

func (ino *Goduino) PinMode(pin, mode int) error

PinMode configures the specified pin to behave either as an input or an output.

func (*Goduino) Port

func (ino *Goduino) Port() string

Port returns the FirmataAdaptors port

func (*Goduino) PwmWrite

func (ino *Goduino) PwmWrite(pin int, level byte) (err error)

PwmWrite writes the 0-254 value to the specified pin

func (*Goduino) ServoConfig

func (ino *Goduino) ServoConfig(pin, min, max int) error

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

func (*Goduino) ServoWrite

func (ino *Goduino) ServoWrite(pin int, angle byte) (err error)

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

func (*Goduino) UltrasoundDistance

func (ino *Goduino) UltrasoundDistance() string

UltrasoundDistance returns the distance cm unit

func (*Goduino) UltrasoundReport

func (ino *Goduino) UltrasoundReport(pin int) (err error)

UltrasoundReport read distance from Ultrasound sensor.

type PinMode

type PinMode uint8

func (PinMode) String

func (m PinMode) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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