Adafruit RGBmatrixPanel in esp-idf and eclipse

tsctrl
Posts: 30
Joined: Tue Dec 08, 2020 1:37 pm

Adafruit RGBmatrixPanel in esp-idf and eclipse

Postby tsctrl » Tue Dec 08, 2020 1:56 pm

Hi,

While migrating my codes from arduino.ino to idf project. I have some difficulties to initiate RGBmatrixPanel.
I have installed the library thru arduino as idf components and is able to build and flash.
The issue that i have is,

1. i did not know how to instantiate the library using c++ .h and .cpp files.
2. i not able to light up the led on standard idf main_app() file.

For issue 1:
In eclipse, my codes are separated into different files, where calling function require static declaration as such. Similar like using arduino ide. but if using arduino ide, i did not have to include the .h and my matrix variable that was declared are become public variable and can be refers from other files automatically.

i have tried two approaches which both fail to light my led panel
1. as a pubic variable, use extern in h and init in .cpp files as below:

.h:

Code: Select all

extern RGBmatrixPanel matrix;
.cpp:

Code: Select all

uint8_t rgbpins[6] = { 25, 26, 27, 14, 12, 13 };
RGBmatrixPanel matrix(23, 19, 5, 17, 16, 4, 15, true, 64, rgbpins);
2. as singleton cpp class as below:
.h:

Code: Select all

public:
   static Matrix* Instance();
   RGBmatrixPanel matrix() {
	   uint8_t rgbpins[6] = { 25, 26, 27, 14, 12, 13 };
	   RGBmatrixPanel matrix(23, 19, 5, 17, 16, 4, 15, true, 64, rgbpins);
	   return matrix;
   }

private:
   static Matrix* m_pInstance;
.cpp:

Code: Select all

Matrix* Matrix::m_pInstance = NULL;
Matrix* Matrix::Instance()
{
   if (!m_pInstance){   
      m_pInstance = new Matrix();
   }
   return m_pInstance;
}
Matrix::Matrix(){}
one of the issue is i not able to run matrix.swapBuffers(false); where the controller will be not responding other then the led not light up. come delay() issue?

I might think this is probably because of i did not properly include the arduino components inside my idf project.
The way i include in CMake is as below:
idf_component_register(
SRCS "src/variable.cpp"
INCLUDE_DIRS "./include"
REQUIRES arduino
PRIV_REQUIRES main nvs_flash
)

Please help me. Thank you.
Last edited by tsctrl on Thu Dec 10, 2020 1:28 pm, edited 2 times in total.

tsctrl
Posts: 30
Joined: Tue Dec 08, 2020 1:37 pm

Re: Adafruit RGBmatrixPanel in esp-idf and eclipse

Postby tsctrl » Wed Dec 09, 2020 5:07 pm

I have created basic project with codes below to replicate the issue:

PIN CONFIGURATION:
*
* HUB 75 PANEL ESP 32 PIN
* +-----------+
* | R1 G1 | R1 -> IO25 G1 -> IO26
* | B1 GND | B1 -> IO27
* | R2 G2 | R2 -> IO14 G2 -> IO12
* | B2 GND | B2 -> IO13
* | A B | A -> IO23 B -> IO19
* | C D | C -> IO 5 D -> IO17
* | CLK LAT | CLK -> IO16 LAT -> IO 4
* | OE GND | OE -> IO15 GND -> ESP32 GND
* +-----------+
*
main/app_main.cpp

Code: Select all

#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>

extern "C" {
void app_main();
}

const int ledPinInternal = 2;

uint8_t rgbpins[6] = { 25, 26, 27, 14, 12, 13 };
RGBmatrixPanel matrix(23, 19, 5, 17, 16, 4, 15, true, 64, rgbpins);

void app_main(void) {

	initArduino();
	
	printf("Hello world!\n");
	pinMode(ledPinInternal, OUTPUT);

	matrix.begin();
	matrix.setCursor(0, 0);
	matrix.print("TEST !");

	while (1) {
		digitalWrite(ledPinInternal, LOW);
		delay(500);
		printf("BLINK!\n");
		digitalWrite(ledPinInternal, HIGH);
		delay(500);
	}
}
i have added 3 Adafruit library to the arduino libraries folder as below:

Arduino CMakeFiles.txt: *excerpt
libraries/Adafruit_BusIO/Adafruit_I2CDevice.cpp
libraries/Adafruit_BusIO/Adafruit_SPIDevice.cpp
libraries/Adafruit_BusIO/Adafruit_BusIO_Register.cpp
libraries/Adafruit-GFX-Library/Adafruit_GFX.cpp
libraries/Adafruit-GFX-Library/Adafruit_GrayOLED.cpp
libraries/Adafruit-GFX-Library/Adafruit_SPITFT.cpp
libraries/RGB-matrix-Panel/RGBmatrixPanel.cpp
Last edited by tsctrl on Thu Dec 10, 2020 1:26 pm, edited 1 time in total.

tsctrl
Posts: 30
Joined: Tue Dec 08, 2020 1:37 pm

Re: Adafruit RGBmatrixPanel in esp-idf and eclipse

Postby tsctrl » Thu Dec 10, 2020 1:19 pm

some update regarding this issue.

the led light up when i use setup() loop() and enable arduino loop autorun in menuconfig in esp-idf.
the issue still exist on the app_main() .cpp while(1) approach.

no error whatsoever, the while are looping. am i missing something.
please help. :(

Who is online

Users browsing this forum: No registered users and 42 guests