Microbit_V2 LED Matrix Adafruit_Microbit Library Demo Doesn't work on PlatformIO

I am testing the latest version of the “Adafruit Microbit” Library using the latest version of PIO (VSC 1.75.0) for Microbit_V2 board for Arduino Framework. The test is the straight forward library’s example “matrixdemo.ino” with no modification whatsoever. The example shows how to use the library’s functions to control 5x5 LED Matrix of Microbit_V2. The example and the library are both working as expected in the Arduino IDE 2.0. However, when I run it in the PIO IDE it does not lit any of the LEDs in the Column-4 (or Column-3 counting from 0). When I attempt to control the LEDs by directly affecting the corresponding pins of the Microbit_V2 board WITHOUT using the Arduino Library at all, the result I observe is exactly the same: all LEDs in the Column-4 stay off whatever I do. I verified the GPIO pins controlling the LED matrix to be correct.

I could drop using PIO and switch to Arduino, but I like the environment and the no-hassle debug capabilities it offers for the board.

Any ideas on what to look at would be highly appreciated.

Eugene.

What’s your exact platformio.ini?

Have you made sure to update the nRF52 platform? E.g., CLIpio pkg update -g -p nordicnrf52.

Hi maxgerhardt - thanks for your reply.

Here is the “platformio.ini” content - nothing fancy:

[env:bbcmicrobit_v2]
platform = nordicnrf52
board = bbcmicrobit_v2
framework = arduino
monitor_speed = 115200

After updating the nRF52 platform by using the CLI command you suggested, here is the output:

PS D:\STEM Work\PlatformIO\MicrobitV2_LED_Matrix_Direct> pio pkg update -g -p nordicnrf52 
Platform Manager: Updating nordicnrf52 @ 8.3.0
Platform Manager: Removing nordicnrf52 @ 8.3.0
Platform Manager: nordicnrf52@8.3.0 has been removed!
Platform Manager: Installing platformio/nordicnrf52 @ 9.4.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Platform Manager: nordicnrf52@9.4.0 has been installed!
Tool Manager: toolchain-gccarmnoneeabi@1.70201.0 is already installed
Tool Manager: tool-sreccat@1.164.0 is already installed
Tool Manager: framework-arduinonordicnrf5@1.700.201209 is already up-to-date
Tool Manager: tool-bossac-nordicnrf52@1.10901.201022 is already up-to-date
Tool Manager: tool-sreccat@1.164.0 is already up-to-date
Tool Manager: toolchain-gccarmnoneeabi@1.70201.0 is already up-to-date
PS D:\STEM Work\PlatformIO\MicrobitV2_LED_Matrix_Direct>

Still, the result of executing is exactly the same - the 4th column does not work (does not lit all LEDs of this column). It’s making my mind cringe, yet the fact is undeniable - the simple and straight forward test is not working as expected. With Arduino IDE 2.0 environment, I am getting the expected result I observe for exactly the same C/C++ code, that is LED Matrix can be fully lit - all 25 LEDs in it.

To add to my frustration, when using PIO, I am observing exactly the same wrong and inexplicable behavior for the “standard” Adafruit Microbit library and its testing program “MatrixDemo” demo-ing the functionality of Microbit’s built-in 5x5 LED Matrix.

I am completely puzzled and have no clue even what to look at in PIO. Admittedly - not much experience with PIO though.

Would really appreciate any idea.

Eugene.

What version of the sandeepmistry/arduino-nRF5 core do you have installed in the Arduino 2.0? It should list nRF5 in the Tools->Boards->Board Manager.

I believe - 1.0.2

No that can’t be, that core shouldn’t support the bbc microbit V2. Is there are Sandeep Mistry nRF5 core installed too? What’s the list of used board manager URLs?

Yes - seems that my Arduino 2.0 IDE has also Sandeep Mistry installed too.

Also - here is what I have in Additional Boards Manager URLs:

https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json

Anyway, whatever this may be - it makes the Microbit_V2 LED Matrix library to work correctly. Whatever configuration my Arduino IDE has - this seems to be lacking in PIO. The question is - what is it?

Per

PlatformIO is using the 0.7.0 version too.

Can you produce the verbose compilation logs for both PlatformIO and Arduino IDE 2.0?

For PlatformIO, use the CLI and do

pio run -t clean
pio run -v -j1 > build.log 2>&1

and in Arduino IDE 2.0, go to File->Preferences and tick “Verbose” Build/Compilation, and rebuild.

You can upload the logs to pastebin.com and link them here.

Just did - public paste, name of the paste is “Microbit_V2 LED_Matrix_Direct”.

Thank you very much for looking into that - appreciated.

I really need you to post the direct link here, not sure if searching for it will bring me to it.

This should work I belive:

Microbit_V2 LED_Matrix_Direct - Pastebin.com

Okay, and what about the verbose build log in the Arduino IDE?

Hmmm strange… Just added Arduino’s log (the same link). Not sure if my build was from clean. And yes - I made sure that verbose for compile and build is checked in preferences.

I think the problem is that GPIO_COUNT gets defined as 1. Try lighting pixel (0,GPIO_COUNT). The column 3 pin is 37, which is found on port NRF_P1.

This is because the build thinks it is a NRF52832, and leads to the wrong definitions in the platformio copy of arduino-nRF5/Arduino.h at master · sandeepmistry/arduino-nRF5 · GitHub

NRF52832_XXAA gets defined at line 93 or so in
platformio\packages\framework-arduinonordicnrf5\cores\nRF5\SDK\components\device\nrf.h
because the build defines the macro NRF52. Add a #error in there to prove it.

I didn’t get as far as figuring out why NRF52 is defined. From memory, I think it should define, if anything, NRF52_SERIES instead of NRF52.

Weird, PlatformIO directly sets

Can you get that tracked in Issues · platformio/platform-nordicnrf52 · GitHub?

My attempt to hack the bbcmicrobit_V2.json you are referring to by the brute force and deleting the “-DNRF52833_XXAA” from "“extra_flags”:‘’ line, resulted in the compilation error:

C:\Users\eugene.platformio\packages\framework-arduinonordicnrf5\cores\nRF5\SDK\components\device/nrf.h:182:6:
error: #error “Device must be defined. See nrf.h.”
#error “Device must be defined. See nrf.h.”

My next step was to follow the idea of Martin Williams (thanks, Martin, a lot - appreciate it!) that the core of the problem is the “NRF52832_XXAA” macro definition in
“….platformio\packages\framework-arduinonordicnrf5\cores\nRF5\SDK\components\device\nrf.h”.

After I changed the lines ##92-98 in this file (….platformio\packages\framework-arduinonordicnrf5\cores\nRF5\SDK\components\device\nrf.h) to the following:

/* Redefine “old” too-generic name NRF52 to NRF52832_XXAA to keep backwards compatibility. */
#if defined (NRF52)
#define NRF52_SERIES
// #ifndef NRF52832_XXAA
// #define NRF52832_XXAA
// #endif
#endif

The result was positive - I got my testing program, which manipulates the LED Matrix directly through the pins corresponding to the rows and columns of the LED Matrix, was working fine - the program was able to light all columns of the LED Matrix including the 4th one.

After I added a few #ifdef statements to the program

#if defined (NRF52)
#warning “NRF52 DEFINED!”
#endif

#if defined (NRF52_SERIES)
#warning “NRF52_SERIES DEFINED!”
#endif

#if defined (NRF52832_XXAA)
#warning “NRF52832_XXAA DEFINED!”
#endif

The compilation gave me the following:

src\main.cpp:11:4: warning: #warning “NRF52 DEFINED!” [-Wcpp]
#warning “NRF52 DEFINED!”
^~~~~~~
src\main.cpp:15:4: warning: #warning “NRF52_SERIES DEFINED!” [-Wcpp]
#warning “NRF52_SERIES DEFINED!”

Compiling a small testing program for “Adafruit_Microbit” Library also gave positive results: it was able to display various symbols on LED Matrix including the leds in the 4th column which have not been working correctly, However, the scrolling functionality was not working correctly - the characters were scrolling randomly or even not scrolling at all…

I am not sure how to investigate this problem further in a more robust way than hacking the “nrf.h” file.

Unless there are other ideas, as you suggested, the problem probably should be addressed through the PIO development team.

Thank you very much for your analysis and feedback.

Eugene.

Thanks for opening up this issue and for reporting it on github (issue 171). @maxgerhardt @ivankravets this issue makes the Microbit V2 severely unusable on PlatformIO and a great source of frustration for unaware users. As a workaround I need to instruct my students to modify the nrf.h file as is suggested above.

There is a pragma conflict between the exact chip definition (NRF52833_XXAA) and its family (NRF52) as shown in the auto-generated .vscode\c_cpp_properties.json

image

Because NRF52 is defined the definition NRF52833_XXAA is ignored and a wrong chip the NRF52832 is defined (see line 93 from nrf.h).The NRF52833 has 2 port addresses while the NRF52832 has one which lead to a different port definition and limiting the number of ports on the Microbit V2 (eg. port 16) which is used in motor driver boards like Kitronik 5698. Furthermore, different chip definitions are used which could result in other errors.

The erroneous argument NRF52 seems to be added in line 62 in nrf5.py, and is unneeded when an explicit chip definition is given.

The bbcmicrobit_v2.json board definition does not include the chip family, but obviously line 10 of this definition is being parsed into nrf52 in the final cpp_defines by line 62 from nrf5.py. The addition of the chip family is not needed as can be seen on line 100 from nrf.h which adds the NRF52_SERIES definition given an explicit chip definition.

Every Microbit v2 user would be really grateful if PlatformIO could address this issue.

Thanks, Steven

Then let’s make

more visible by upvoting and commenting.

1 Like

Thanks @maxgerhardt for this push.