Giter Club home page Giter Club logo

go-rpi-rgb-led-matrix's Introduction

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

go-rpi-rgb-led-matrix's People

Contributors

justfalter avatar lukasmalkmus avatar mcuadros avatar neuralspaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-rpi-rgb-led-matrix's Issues

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.

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?

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.

MATRIX_EMULATOR doesn't work

When you use the emulator a X window appears with nothing within (just a sort of screenshot of your current desktop).

image

Scrolling text display

Really a good work. It helped me alot to understand and start our own development further.

I am able to display the text with tk.DrawString function, however, I am looking for a function to scroll the text. I have gone through the resources, I didn't find any related to scroll text in golang. I am new to this language, learning it with small steps. Would be great if anybody can help me.

Install fails.

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

borud@raspberrypi:~/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

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...)

[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?

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().

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.