Go binding for rpi-rgb-led-matrix an excellent C++ library to control RGB LED displays with Raspberry Pi GPIO.

Overview

go-rpi-rgb-led-matrix GoDoc Build Status

Go binding for rpi-rgb-led-matrix an excellent C++ library to control RGB LED displays with Raspberry Pi GPIO.

This library includes the basic bindings to control de LED Matrix directly and also a convenient ToolKit with more high level functions. Also some examples are included to test the library and the configuration.

The Canvas struct implements the image.Image interface from the Go standard library. This makes the interaction with the matrix simple as work with a normal image in Go, allowing the usage of any Go library build around the image.Image interface.

To learn about the configuration and the wiring go to the original library, is highly detailed and well explained.

Installation

The recommended way to install go-rpi-rgb-led-matrix is:

go get github.com/mcuadros/go-rpi-rgb-led-matrix

Then you will get an expected error like this:

# github.com/mcuadros/go-rpi-rgb-led-matrix
/usr/bin/ld: cannot find -lrgbmatrix
collect2: error: ld returned 1 exit status

This happens because you need to compile the rgbmatrix C bindings:

cd $GOPATH/src/github.com/mcuadros/go-rpi-rgb-led-matrix/vendor/rpi-rgb-led-matrix/
git submodule update --init
make
cd $GOPATH/src/github.com/mcuadros/go-rpi-rgb-led-matrix/
go install -v ./...

Examples

Setting all the pixels to white:

// create a new Matrix instance with the DefaultConfig
m, _ := rgbmatrix.NewRGBLedMatrix(&rgbmatrix.DefaultConfig)

// create the Canvas, implements the image.Image interface
c := rgbmatrix.NewCanvas(m)
defer c.Close() // don't forgot close the Matrix, if not your leds will remain on
 
// using the standard draw.Draw function we copy a white image onto the Canvas
draw.Draw(c, c.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)

// don't forget call Render to display the new led status
c.Render()

Playing a GIF into your matrix during 30 seconds:

// create a new Matrix instance with the DefaultConfig
m, _ := rgbmatrix.NewRGBLedMatrix(&rgbmatrix.DefaultConfig)

// create a ToolKit instance
tk := rgbmatrix.NewToolKit(m)
defer tk.Close() // don't forgot close the Matrix, if not your leds will remain on

// open the gif file for reading
file, _ := os.Open("mario.gif")

// play of the gif using the io.Reader
close, _ := tk.PlayGIF(f)
fatal(err)

// we wait 30 seconds and then we stop the playing gif sending a True to the returned chan
time.Sleep(time.Second * 30)
close <- true

The image of the header was recorded using this few lines, the running Mario gif, and three 32x64 pannels.

Check the folder examples folder for more examples

Matrix Emulation

As part of the library an small Matrix emulator is provided. The emulator renderize a virtual RGB matrix on a window in your desktop, without needing a real RGB matrix connected to your computer.

To execute the emulator set the MATRIX_EMULATOR environment variable to 1, then when NewRGBLedMatrix is used, a emulator.Emulator is returned instead of a interface the real board.

License

MIT, see LICENSE

Comments
  • [Issue] Unprecedented Installation Error

    [Issue] Unprecedented Installation Error

    Hi, I was trying to install the binding. It throws an error as mentioned in the readme. But not the same.

    # github.com/mcuadros/go-rpi-rgb-led-matrix
    ../../../work/pkg/mod/github.com/mcuadros/[email protected]/matrix.go:6:10: fatal error: led-matrix-c.h: No such file or directory
     #include <led-matrix-c.h>
              ^~~~~~~~~~~~~~~~
    compilation terminated.
    

    How should i deal with it ?

    go env

    GO111MODULE="on"
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/home/username/.cache/go-build"
    GOENV="/home/username/.config/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOINSECURE=""
    GOMODCACHE="/home/username/work/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="linux"
    GOPATH="/home/username/work"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/usr/local/go"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
    GCCGO="gccgo"
    AR="ar"
    CC="gcc"
    CXX="g++"
    CGO_ENABLED="1"
    GOMOD="/home/username/gocv_work/src/rgbtest/go.mod"
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build058517942=/tmp/go-build -gno-record-gcc-switches"
    

    Any guidance?

    opened by hiteshhedwig 5
  • Update rpi-rgb-led-matrix, fix column calculation, add several missing configuration options

    Update rpi-rgb-led-matrix, fix column calculation, add several missing configuration options

    There are a few things in this PR:

    • Updated the submodule for https://github.com/hzeller/rpi-rgb-led-matrix to that of the current master (as of yesterday).
    • Added HardwareConfig.Cols, allowing for the specification of the number of columns in an LED matrix panel. This corresponds to the "--led-cols" cli option in all of the rpi-rgb-led-matrix demo code.
    • Fixed a bug in the calculation of geometry columns, which had previously expected a square panel (columns == rows). In my case, my panels have 32 columns and 16 rows.
    • Added HardwareConfig.HardwareMapping, allowing for the specification of the GPIO mapping type (ex: 'regular', 'adafruit-hat', 'adafruit-hat-pwm', etc).
    • Modified HardwareConfig.toC() so that it now sets bit field options for show_refresh_rate (HardwareConfig.ShowRefreshRate), inverse_colors (HardwareConfig.InverseColors), and disable_hardware_pulsing (HadwareConfig.DisableHardwarePulsing). cgo does not allow for access to bit fields in C structures, so I created setter functions in C to take care of that.
    • Added relevant new cli options to all of the example code.

    I realize, now,

    opened by justfalter 5
  • Crashes when not run as root

    Crashes when not run as root

    The library panics when not run as root, because the rip-rgb-led-matrix needs to do some low-level stuff which requires root access. Instead of panicing, it might be better to recover and return an error in NewRGBLedMatrix().

    opened by lukasmalkmus 3
  • Install fails.

    Install fails.

    Followed the instructions on the in README.md but got this:

    [email protected]:~/gocode/src/github.com/mcuadros/go-rpi-rgb-led-matrix $ go install -v ./...
    matrix.go: malformed #cgo argument: -I${SRCDIR}/vendor/rpi-rgb-led-matrix/include
    examples/basic/main.go:8:2: /home/borud/gocode/src/github.com/mcuadros/go-rpi-rgb-led-matrix/matrix.go: malformed #cgo argument: -I${SRCDIR}/vendor/rpi-rgb-led-matrix/include
    
    opened by borud 3
  • Adafruit bonnet: examples work in C, but not in GO

    Adafruit bonnet: examples work in C, but not in GO

    Hello,

    I am trying to use your library with an Adafruit Bonnet adapter board. I have installed the C and Python code with the script that Adafruit recommends for installation:

    curl https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/rgb-matrix.sh >rgb-matrix.sh
    sudo bash rgb-matrix.sh
    
    

    The script runs fine, it installs everything.

    I have tried the examples in the examples-api-use folder, they run fine, for example with the following code: sudo ./clock --led-rows=32 --led-cols=64 --led-slowdown-gpio=1 --led-multiplexing=1 -f ../fonts/7x13.bdf -d "%H:%M:%S"

    But if I install your library (including the compilation of the C code) and try to run any of your examples, they run, but nothing shows up in the RGB matrix. I have the feeling that I am missing some obvious step. Could you please help me?

    (If I try the C library examples downloaded with Adafruit they still work...)

    opened by lg007 1
  • Show emulator gutters/margins, tweak layout

    Show emulator gutters/margins, tweak layout

    This started out with an effort to provide contrast between the gutters/margins and the LED. Without the gutters being visible, it was very difficult to that the right LEDs were being lit up. I found, though, the math to locate LEDs, gutters, etc to be a bit challenging. In the end, I rewrote some portions in order to consolidate the mathematics, simplifying (in my opinion) things a little bit. I should note that the math became easier when I started expressing things in terms of the gutter width (ex: PixelPitch = 2*Gutter).

    • Gutters and margins are now drawn in a contrasting color (gray), so that it is easy to distinguish the LED pixels from the background.
    • The initial emulator window dimensions are calculated based on the initial pixel pitch.
    • LED matrix resizing is a bit more precise as the window is resized.

    I've tested this code quite extensively on Linux and am quite happy with the results.

    opened by justfalter 1
  • 2 panels 32x64 - which are the correct parameters?

    2 panels 32x64 - which are the correct parameters?

    Got little bit confused with program parameters, so with 2 panels 32x64 I have to pass:

    go run main.go -image mariosmall.gif -led-chain 2 -led-parallel 2 -led-rows 32

    is this correct?

    Thanks,

    opened by marcinguy 1
  • Fails to render with Raspbian stretch

    Fails to render with Raspbian stretch

    programs run but fail to render to matrix under raspbian stretch due to magic memory value. See https://github.com/hzeller/rpi-rgb-led-matrix/commit/9c1f6bbc1fa756459cf21ca32cc95db849d6dbe5

    pulling in latest version to vendor fixes on stretch but I have not verified on other systems.

    opened by NeuralSpaz 1
  • Invalid License?

    Invalid License?

    This repository is licensed MIT, but the vendor repository is GPL 2. Doesn't that mean that this must be released as GPL 2 or later? The upstream author calls this out explicitly.

    opened by kellertk 1
  • Gpio slowdown

    Gpio slowdown

    Added passing of command line arguments to C library so runtime options can be used. It is now possible to set --led-slowdown-gpio 2 so that 64x32 LED matrix works correctly.

    opened by brendanporter 2
  • Re-allocating the led buffer makes matrix.At() method unusable

    Re-allocating the led buffer makes matrix.At() method unusable

    Hi @mcuadros. If a user of this package wants to get the image currently showing on the matrix (for example by using the draw package) he is not able to do so. The reason for this is located in this single line. After rendering, the led buffer is re-allocated and thus initialised with zero values. So after calling the Render() method on a matrix (or canvas), you only get 0 (color.Black). An easy fix is to just remove the mentioned line and keep the led buffer filled. Since users will usually just draw over with new content, this shouldn't be an issue.

    Any hints or other ideas on this? I can also prepare a PR if you want to.

    opened by lukasmalkmus 0
  • Panic when invalid config is passed

    Panic when invalid config is passed

    Hi @mcuadros. A while back I blindly submitted a PR which I prepared in my head. My idea was to catch panics which were caused by an invalid config or not running as root. But I just noticed that this doesn't work as expected.

    The reason why the code panics is located in these two lines.

    m := C.led_matrix_create_from_options(config.toC(), nil, nil)
    b := C.led_matrix_create_offscreen_canvas(m)
    // Some other code ...
    if m == nil {
    	return nil, fmt.Errorf("unable to allocate memory")
    }
    

    If the application is not running as root, m will benil. Why this case is handled, m is still passed to b := C.led_matrix_create_offscreen_canvas(m) without checking that m is not nil! This causes the panic.

    A simple solution could look like this:

    m := C.led_matrix_create_from_options(config.toC(), nil, nil)
    if m == nil {
    	return nil, fmt.Errorf("unable to allocate memory for matrix")
    }
    b := C.led_matrix_create_offscreen_canvas(m)
    if b == nil {
    	return nil, fmt.Errorf("unable to allocate memory for offscreen canvas")
    }
    // Do some other stuff ...
    

    Feel free to suggest a different solution or drop me line if you want me to prepare a PR.

    opened by lukasmalkmus 0
  • RPC Client Server with Emulator

    RPC Client Server with Emulator

    Started the client. It listens on IPv6 (tcp6)

    tcp6 0 0 :::1234 :::* LISTEN 29868/main

    adjusted the client to connect to:

    rpc.NewClient("tcp6", "[::]:1234")

    Testing it with emulator, but unfortunately the window remains black. Nothing is displayed.

    I tested it under user root.

    Does this also work with emulator?

    opened by marcinguy 0
Owner
Máximo Cuadros
Máximo Cuadros
Graphic library supporting various displays

eve Package eve provides interface to FTDI/BRTCHIP Embedded Video Engine display controllers (FT80x, FT81x, BT1x). font Package font provides a simple

Embedded Go 21 Jul 5, 2022
Go bindings for Raspberry Pi PWM library for WS281X LEDs

go-rpi-ws281x golang binding for rpi_ws281x, userspace Raspberry Pi PWM library for WS281X LEDs. Supports any Raspberry and WS2812, SK6812RGB and SK68

Máximo Cuadros 35 Aug 18, 2022
Viewnode displays Kubernetes cluster nodes with their pods and containers.

viewnode The viewnode shows Kubernetes cluster nodes with their pods and containers. It is very useful when you need to monitor multiple resources suc

NTTDATA-DACH 9 Nov 23, 2022
Kubectl plugin shows pod x node matrix with suitable colors to mitigate troubleshooting effort.

kubectl-pod-node-matrix WORK IN PROGRESS!! This plugin shows pod x node matrix with suitable colors to mitigate troubleshooting effort. Details Troubl

Arda Güçlü 2 May 11, 2022
Network scanner for Raspberry Pi

╔═╗╦═╗╔═╗╦ ╠═╣╠╦╝╠═╝║ ╩ ╩╩╚═╩ ╩ Basic network scanner for Raspberry Pi Install Note: Prebuilt binaries (32-bit) doesn't require Go. Prereq

PierreKieffer 40 Jun 13, 2022
Raspberry Pi Archlinux Automated Offline Installer with Wi-Fi. Windows, Mac and more features coming.

Raspberry Pi Archlinux Automated Installer with Wi-Fi. Windows, Mac and more features coming. Download Go to releases page and download the zip file f

Mansour Behabadi 9 Nov 22, 2022
[WIP] Cheap, portable and secure NAS based on the Raspberry Pi Zero - with encryption, backups, and more

PortaDisk - Affordable Raspberry Pi Portable & Secure NAS Project Project Status: Early work in progress. web-unlock is still not ready for production

null 2 Nov 23, 2022
Turn your Go program(s) into an appliance running on the Raspberry Pi 3 or 4 (or on amd64 PCs!)

Overview gokrazy packs your Go application(s) into an SD card image for the Raspberry Pi 3 or 4 which — aside from the Linux kernel and proprietary Ra

null 2.5k Nov 21, 2022
Serves images taken on a FLIR Lepton connected to a Raspberry Pi SPI port to over HTTP.

go-lepton Streams images taken on a FLIR Lepton connected to a Raspberry Pi SPI port to over via WebSockets via embedded HTTP server. It sends the raw

M-A 24 Oct 29, 2022
Capture the stream of Images for a Raspberry Pi Camera in GoLang

piCamera This package is a wrapper for the raspivid command on the Raspberry Pi. To make development easier on a PC, there is are different Start() me

Technomancers 28 Mar 5, 2022
Go library to create resilient feedback loop/control controllers.

Gontroller A Go library to create feedback loop/control controllers, or in other words... a Go library to create controllers without Kubernetes resour

Spotahome 148 Oct 31, 2022
Lightweight, CRD based envoy control plane for kubernetes

Lighweight, CRD based Envoy control plane for Kubernetes: Implemented as a Kubernetes Operator Deploy and manage an Envoy xDS server using the Discove

null 51 Nov 3, 2022
This project for solving the problem of chaincode being free from k8s control

Peitho - Hyperledger Fabric chaincode Cloud-native managed system The chaincode of Hyperledger Fabric can be handed over to k8s for management, which

null 7 Aug 14, 2022
Asynchronously control the different roles available in the kubernetes cluster

RBAC audit Introduction This tool allows you to asynchronously control the different roles available in the kubernetes cluster. These audits are enter

null 0 Oct 19, 2021
Working towards a control plane for the MiCo Tool and the MiCoProxy

A simple control plane for MiCo This is still largely a work in progress The overall idea is to build a kubernetes DaemonSet that watches kubernetes s

null 0 May 4, 2022
L3AFD kernel function control plane

L3AFD: Lightweight eBPF Application Foundation Daemon L3AFD is a crucial part of the L3AF ecosystem. For more information on L3AF see https://l3af.io/

L3AF 119 Nov 18, 2022
⚡️ Control plane management agent for FD.io's VPP

VPP Agent The VPP Agent is a Go implementation of a control/management plane for VPP based cloud-native Virtual Network Functions (VNFs). The VPP Agen

EMnify 0 Aug 3, 2020
Pulumi-awscontroltower - A Pulumi provider for AWS Control Tower

Terraform Bridge Provider Boilerplate This repository contains boilerplate code

Lee Briggs 4 Nov 14, 2022
Sapfun - Utility that takes control over your video card coolers to keep it cool and steady

What? sapfun - Utility that takes control over your video card coolers to keep i

Vadim Kuznetsov 1 Feb 18, 2022