Looks like it was released this morning, and both Arduino IDE 2.x and App Lab
has been updated ![]()
Lots of good things have been fixed, like for example I can now use kernel events with threads. Example scrolling text on the matrix using a thread and events:
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"
Arduino_LED_Matrix matrix;
struct k_event my_event;
volatile bool thread_active = false;
volatile uint32_t loop_count = 0;
#define STACK_SIZE 1024
#define PRIORITY 7
K_THREAD_STACK_DEFINE(thread1_stack, STACK_SIZE);
struct k_thread thread1_data;
k_tid_t thread1_tid;
char led_text[20];
void thread1(void *p1, void *p2, void *p3) {
UNUSED(p1);
UNUSED(p2);
UNUSED(p3);
uint32_t events;
uint32_t thread_loop_count = 0;
while (1) {
events = k_event_wait(&my_event, 0xFFF, true, K_MSEC(2000));
if (events == 0) {
sprintf(led_text, "Timeout");
} else {
thread_loop_count++;
sprintf(led_text, "L:%u t:%u", loop_count, thread_loop_count);
}
matrix.beginText(0, 0, 127, 0, 0); // X, Y, then R, G, B
matrix.print(led_text);
matrix.endText(SCROLL_LEFT);
thread_active = false;
}
}
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
matrix.begin();
matrix.textFont(Font_5x7);
matrix.textScrollSpeed(100);
matrix.clear();
k_event_init(&my_event);
thread1_tid = k_thread_create(&thread1_data, thread1_stack, K_THREAD_STACK_SIZEOF(thread1_stack),
thread1, NULL, NULL, NULL, PRIORITY, 0, K_NO_WAIT);
}
void loop() {
loop_count++;
digitalWrite(LED_BUILTIN, (loop_count & 1) ? HIGH : LOW);
if (!thread_active) {
thread_active = true;
k_event_set(&my_event, 0x001);
}
delay(250);
}
There may have been some improvements on how much memory you can malloc at run time over the previous release. Where on some boards now we can at least maybe be able to allocate a frame buffer for smaller displays or cameras. Like an ILI9341 (320x240x2) = 153600
However probably not for slightly larger display like ILI9488 or ST7796 (480x320x2) = 307200
Simple sketch:
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
delay(250);
Serial.println("Check max malloc");
Serial.print("Enter max KB to start: ");
pinMode(LED_BUILTIN, OUTPUT);
//printk("KB: %u Buffer: %p\n", buffer);
}
void loop() {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
if (Serial.available()) {
int kb_max = Serial.parseInt();
int kb;
void *buffer;
Serial.println(kb_max);
for (kb = kb_max; kb > 0; kb--) {
buffer = malloc(kb * 1024);
if (buffer) break;
}
Serial.print(kb);
Serial.print(": ");
Serial.print((uint32_t)buffer, HEX);
if (buffer) {
Serial.print(" - ");
Serial.print((uint32_t)buffer + kb * 1024, HEX);
}
Serial.print(" Stack var: ");
Serial.println((uint32_t)&buffer, HEX);
free(buffer);
Serial.print("Enter max KB to start: ");
while (Serial.read() != -1) {}
}
delay(500);
}
I tried this on a few of the boards, only the Q has enough for these larger ones:
Q: 566K
Portenta H7: 270
GIGA: 233
Portenta C33: 25
Nicla Sense: 8
With this now released, I am wondering if this is a good time to go through the Github project and do something similar like Zephyr does, and clear out any issues/pr's we issued that have not been commented on or addressed over some period of time and/or releases?
