Go library that uses fast-gpio approach to access the GPIO pins of Omega2
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
.gitignore
LICENSE
README.md
onion.go

README.md

Go-omega2gpio

This is a go library that exposes the GPIO ports of the Onion Omega2.

The inspiration for this is from Onion fast-gpio https://github.com/OnionIoT/fast-gpio.

Usage

First you have to obtain the library:

go get gihub.com/adiclepcea/go-omega2gpio

That will put the library on your GOPATH.

A simple example usage is:

package main

import (
    "fmt"

    onion "github.com/adiclepcea/go-omega2gpio"
)

func main(){
    onion.Setup()
    fmt.Println(onion.GetDirection(18))
}

This would show you the direction of the pin 18 (0 for input and 1 for output)

You have the following methods:

  • Setup() - this needs to be called once in every program that uses this library. This will map the memory for GPIO.
  • Read(pinNo int) uint32 - will read the value of the pin pinNo (0 or 1).
  • Write(pinNo int, val uint8) - will set the value of the pin pinNo to the value val (0 or 1).
  • SetDirection(pinNo int, val uint8) - will set the direction of the pin pinNo to the val (0 for input or 1 for output) direction
  • func GetDirection(pinNo int) uint32 - will return the direction (0 for input or 1 for output) of the pin pinNo

Compilation

Please remember to compile the program using this library for the mips architecture.

GOOS=linux GOARCH=mipsle go build -o myprogram main.go

This will compile the program that you can just copy to your Onion Omega2 and run.

Example

There is one example in the example directory. This is a partial reimplementation of the fast-gpio executable.

The present library does not implement pwm, but this should be trivial.

To compile you can just cd to the example directory and run make

The directory should now contain an executable called go-fast-gpio. You can copy it to your Onion Omega2:

scp go-fast-gpio root@<ipaddress_of_omega2>:/root/

You will asked for the password. After you write it and hit enter, the executable will be copied on your Omega2.