GithubHelp home page GithubHelp logo

chinadev / go-rpio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stianeikeland/go-rpio

0.0 2.0 0.0 20 KB

:electric_plug: Raspberry Pi GPIO library for go-lang

License: MIT License

Go 100.00%

go-rpio's Introduction

go-rpio

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.

raspberrypi-blink

Releases

  • 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

Usage

import "github.com/stianeikeland/go-rpio"

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:

pin.PullUp()
pin.PullDown()
pin.PullOff()

pin.Pull(rpio.PullUp)

Unmap memory when done

rpio.Close()

Also see example examples/blinker/blinker.go

Other

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 create_gpio_user_permissions.py if you're unsure how to do this.

go-rpio's People

Contributors

stianeikeland avatar akramer avatar dotdoom avatar kbudde avatar pier-oliviert avatar omardelarosa avatar

Watchers

kevin chen avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.