electric_plug Raspberry Pi GPIO library for go-lang

License: MIT

Language: Go


Native GPIO-Gophers for your Pi!

go-rpio is a Go library for accessing GPIO-pins on the Raspberry Pi.

It requires no external c libraries such as WiringPI or bcm2835.

There's a tiny bit of additional information over at my blog.



  • 1.0.0 - Supports original rpi A/B/B+
  • 2.0.0 - Adds support for rpi 2, by @akramer
  • 3.0.0 - Add support for /dev/gpiomem, by @dotdoom


import ""

Open memory range for GPIO access in /dev/mem

err := rpio.Open()

Initialize a pin, run basic operations. Pin refers to the bcm2835 pin, not the physical pin on the raspberry pi header. Pin 10 here is exposed on the pin header as physical pin 19.

pin := rpio.Pin(10)

pin.Output()       // Output mode
pin.High()         // Set pin High
pin.Low()          // Set pin Low
pin.Toggle()       // Toggle pin (Low -> High -> Low)

pin.Input()        // Input mode
res := pin.Read()  // Read state from pin (High / Low)

pin.Mode(rpio.Output)   // Alternative syntax
pin.Write(rpio.High)    // Alternative syntax

Pull up/down/off can be set using:



Unmap memory when done


Also see example examples/blinker/blinker.go


Currently, it supports basic functionality such as:

  • Pin Direction (Input / Output)
  • Write (High / Low)
  • Read (High / Low)
  • Pull (Up / Down / Off)

Would be nice to add in the future:

  • PWM
  • I2C
  • SPI
  • etc...

It works by memory-mapping the bcm2835 gpio range, and therefore require root/administrative-rights to run.

Using without root

This library can utilize the new /dev/gpiomem memory range if available.

You will probably need to upgrade to the latest kernel (or wait for the next raspbian release) if you're missing /dev/gpiomem. You will also need to add a gpio group, add your user to the group, and then set up udev rules. I would recommend using if you're unsure how to do this.

Project Statistics

Sourcerank 9
Repository Size 78.1 KB
Stars 1,019
Forks 103
Watchers 49
Open issues 16
Dependencies 0
Contributors 6
Tags 8
Last updated
Last pushed

Top Contributors See all

Stian Eikeland Adam omar Pier-Olivier Thibault Kris Budde Artem Sheremet

Packages Referencing this Repo
:electric_plug: Raspberry Pi GPIO library for go-lang
Latest release v4.3.0 - Published - 1.02K stars

Recent Tags See all

v4.3.0 November 29, 2018
v4.2.0 October 09, 2018
4.2.0 October 09, 2018
4.1.0 June 06, 2018
4.0.0 January 12, 2018
v3.0.0 December 08, 2015
v2.0.0 March 08, 2015
v1.0.0 August 25, 2014

Interesting Forks See all

Raspberry Pi GPIO library for go-lang
MIT - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2016-11-24 15:13:14 UTC

Login to resync this repository