Skip to content
/ gpio Public
forked from brian-armstrong/gpio

Go library to do GPIO on systems with /sys/class/gpio

License

Notifications You must be signed in to change notification settings

hbdlb/gpio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

GPIO

This is a Go library for asynchronous inputs on Linux devices with /sys/class/gpio. This implementation conforms to the spec. I have only tested it so far on Raspberry Pi but it should also work on similar systems like the Beaglebone. If you test this library on another system please tell me so that I can confirm it -- I'll give you credit here for the confirmation.

Watcher

The Watcher is a type which listens on the GPIO pins you specify and then notifies you when the values of those pins change. It uses a select() call so that it does not need to actively poll, which saves CPU time and gives you better latencies from your inputs.

Here is an example of how to use the Watcher. Note that the GPIO numbers we want are as the CPU/kernel knows them, not as they may be marked on any external hardware headers.

watcher := gpio.NewWatcher()
watcher.AddPin(gpio.Pin(22))
watcher.AddPin(gpio.Pin(27))
defer watcher.Close()

go func() {
    for {
        pin, value := watcher.Watch()
        fmt.Printf("read %d from gpio %d\n", value, pin)
    }
}()

This example would print once each time the value read on either pin 22 or 27 changes. It also prints each pin once when starting.

License

3-clause BSD

About

Go library to do GPIO on systems with /sys/class/gpio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%