Really noob question

I’ve done a little programming in the past but never any C and never delved into Makefiles at all so I’m probably making some huge assumptions or silly mistakes.

I installed the rpi-rgb-led-matrix stuff on 26th Dec 2020 (so I’m guessing it’s the latest stuff). Due to xmas I finally had time to plug in my panel a few days later, went to the examples folder and ran the ‘./demo’ After I stopped leaping round with joy at the sight of all the pretty colours, I started delving into how to create my own displays. I made a copy of the example* folder to work on and ran ‘make’. The compiled programs do not behave in the same way as the pre-complied ones.

Using the ‘clock’ example program, after running ‘make’ in my working folder, then running the compiled prog I got a message about the sound board. After disabling the on board sound in a boot config file, that message disappeared but there no output on the panel when running the executable. I jumped back to the original folder and ran exactly the same command line on the executable and it worked so I know the panel is still working.

What am I doing wrong to have the programs not run when compiled from the provided source code? Are the executables which come with the source not compiled from the source?

Any help would be appreciated as it’s been 30 years since I’ve dealt with any Unix/Linux, 20 years since any meaningful programming and this is my first experience with RPi.

Linux raspberrypi 5.4.79-v7+ #1373 SMP Mon Nov 23 13:22:33 GMT 2020 armv7l GNU/Linux

Found it. The source code is not the same as the bundled precompiled executables. The default gpio mapping seems to have changed - or the adafruit hat was being detected somehow in the bundled precompiled exe. One simple change to the command line and all was good --led-gpio-mapping=“adafruit-hat”

it’s been a while since I did this, but I remember adafruit having a fork where the adafruit mapping is default, but in the canonical source you have to give --led-gpio-mapping=“adafruit-hat”

Cheers marcmerlin.

I managed to get it working using that flag. I was mostly confused why the pre-compiled exe behaved differently from the default build with the source code, like doing a jigsaw to find the final picture was different from the box.

As is always the case, I learned a lot more by having and researching the issue than if everything had worked perfectly first time :smiley:

Thanks again

1 Like

Hi Xenonbright!

I’m having the same issue although am significantly even more of a noob with this stuff than you. Where do you put this flag? I’m looking in the Makefile and not seeing a great place to add it. Thank you so much!

Hi Matt

Put it on the command line when you call your compiled program

eg sudo ./demo -D0 --led-gpio-mapping=“adafruit-hat”

or hardcode it into your code. It’s part of the Options structure (defined in include/led-matrix.h) passed into RGBMatrix::CreateFromOptions when creating the matrix .

Hope this makes sense and helps

So do we simply copy the files from examples into a folder and then write my code there? Or do I need the files from /include as well?

you don’t need to copy include files, but you need to include the directory they are in with -I at compile time.

What would I need to write in order to hardcode this into the program? Do I need to add this chunk of code with my specifics?

#include “led-matrix.h”

using rgb_matrix::RGBMatrix;

int main(int argc, char **argv) {
// Set some defaults
RGBMatrix::Options my_defaults;
my_defaults.hardware_mapping = “regular”; // or e.g. “adafruit-hat” or “adafruit-hat-pwm”
my_defaults.chain_length = 3;
my_defaults.show_refresh_rate = true;
rgb_matrix::RuntimeOptions runtime_defaults;
// If you drop privileges, the root user you start the program with
// to be able to initialize the hardware will be switched to an unprivileged
// user to minimize a potential security attack surface.
runtime_defaults.drop_privileges = 1;
RGBMatrix *matrix = RGBMatrix::CreateFromFlags(&argc, &argv,
&my_defaults,
&runtime_defaults);
if (matrix == NULL) {
PrintMatrixFlags(stderr, my_defaults, runtime_defaults);
return 1;
}

// matrix->ApplyPixelMapper(…); // Optional

// Do your own command line handling with the remaining options.

// … now use matrix

delete matrix; // Make sure to delete it in the end.
}

thanks!