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.
Failed to load latest commit information.



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.


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 (

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

func main(){

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


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.


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.