I think I just ran into an early-stage bug on the Arduino Uno R4 WiFi.
My previous 2 blog posts separately covered displaying frames on the LED Matrix and Receiving BLE commands.
Combining the 2 sketches, however, caused it to break.
When I first just combined the sketches by putting the lines into the matching places in a new sketch, essentially just merging the two, the BLE no longer advertised the characteristic for the direction.
Commenting out the LED Matrix code brought it back to life. Reinstating it line by line, the issue happens again as soon as I add the line:
ArduinoLEDMatrix matrix;
I thought I would try moving that declaration, and the matrix.begin() line into a function that only gets called later, and that worked to make the BLE behave again, but then as soon as that function is called, the system crashes and reports a "bus fault" in "DisplaySingleFrame.ino" (I'm assuming that's in the library), which it describes as follows:
"Bus fault is caused by precise data access violation"
So I think there's some memory issues in the Arduino code for either the LED Matrix or the BLE code.
I suspect the matrix code is stepping where it shouldn't be stepping.
If I comment out line by line again, the issue happens when loadFrame() is called.
So that's a little annoying. I might need to try a different approach (unless that problem gets fixed).
Edit: Definitely a bug.
Someone else reported a similar situation on the Arduino Forum.
I found a very easy repro-case:
- Start with the built-in example: ArduinoBLE - Peripheral - LED
- Add these 2 lines from the LED_Matrix - DisplaySingleFrame example:
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
If you then comment out the definition of matrix, the BLE example works properly again.
(I added those 2 lines just after the line that includes ArduinoBLE.h)