goduino

package module
v0.0.0-...-200cc4a Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

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) DhtHeatIndexC

func (ino *Goduino) DhtHeatIndexC() string

DhtHeatIndexC returns dht heat index celsius value

func (*Goduino) DhtHeatIndexF

func (ino *Goduino) DhtHeatIndexF() string

DhtHeatIndexF returns dht heat index fahrenheit value

func (*Goduino) DhtHumidity

func (ino *Goduino) DhtHumidity() string

DhtHumidity returns dht humidity value

func (*Goduino) DhtReport

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

DhtReport read temperature and humidity from DHT sensor.

func (*Goduino) DhtTempC

func (ino *Goduino) DhtTempC() string

DhtTempC returns dht temperature celsius value

func (*Goduino) DhtTempF

func (ino *Goduino) DhtTempF() string

DhtTempF returns dht temperature fahrenheit value

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) EcAverage

func (ino *Goduino) EcAverage() string

EcAverage returns ec average

func (*Goduino) EcCurrent

func (ino *Goduino) EcCurrent() string

EcCurrent returns ec currrent

func (*Goduino) EcReport

func (ino *Goduino) EcReport(ec_pin int, temp_pin int) (err error)

EcReport read ec from ec meter

func (*Goduino) EcTemperature

func (ino *Goduino) EcTemperature() string

EcTemperature returns ec temperature

func (*Goduino) EcVoltage

func (ino *Goduino) EcVoltage() string

EcVoltage returns ec voltage

func (*Goduino) LeakReport

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

LeakReport read leak status from liquid leak sensor

func (*Goduino) LeakStatus

func (ino *Goduino) LeakStatus() string

LeakStatus returns leak status

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) PhReport

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

PhReport read ph from ph meter

func (*Goduino) PhValue

func (ino *Goduino) PhValue() string

PhValue returns ph value

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