goduino

package module
v0.0.0-...-95c2dcd Latest Latest
Warning

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

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

README

goduino

Go's package for Arduino

Goduino uses Firmata protocol for Arduino

GoDoc

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/robotic-framework/goduino

Usage

package main

import (
	"fmt"
	"github.com/robotic-framework/goduino"
	"time"
)

func main() {
	arduino := goduino.New("myArduino", "COM1")
	err := arduino.Connect()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer arduino.Disconnect()

	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
)

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

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