TensorFlow on Arduino Nano BLE 33 cause the board not responding

Recently I tried to use TensorFlow on my Arduino Nano BLE 33. I followed this post and everything went well until I uploaded the IMU_Classifier.ino. Once I opened the serial monitor and expected to see the output, I found nothing except two lines of IMU sample rate.

After a long time debugging, I found my program was stuck at the following line
tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter);
The method I used to find it out was that I added print before and after this line, all the print message after this line never printed.

In the meanwhile, the serial port was not available, and the yellow built-in LED started to blink in a patter, which I have no idea why it happened. It seemed like the entire board is not responding.

The weird thing is that I strictly followed the post, and did not even change one word from the code. What could the problem here, could anyone give me some help? Thanks a lot.

BTW, my board is bought on Amazon:

The tricky thing about the boards with native USB functionality like your board is that the USB code that creates the CDC serial port is running on the same microcontroller as your sketch. This means your sketch code can break the USB code, or stop it from running.

Fortunately, there is an easy way to recover from this situation:

  • Press and release the reset button on your board quickly twice. You should now see the LED on the board pulsing, which means the bootloader is running. The double press causes the bootloader to run indefinitely (until the board is reset, powered off, or an upload is done), which means you don't need to get the timing of the reset just right.
  • Select the port of your board from the Tools > Port menu. The port number may be different when the bootloader is running so don't assume you already have the correct port selected.
  • Start an upload in the Arduino IDE.

The upload should now finish successfully. After this, you should be able to go back to doing normal uploads without needing to press the reset button.

It's likely that if you upload the same TensorFlow sketch again, the problem will just come back. But if you upload a sketch that doesn't affect the USB code (a simple example being the File > Examples > 01.Basics > BareMinimum sketch), then you should not have the problem.

Unfortunately, I am not knowledgeable enough about the TensorFlow library to be able to tell you why it does this. I have seen other reports of this issue, so you're not the only one having the problem. Maybe someone else here on the forum with more knowledge on this subject will be able to help with using the TensorFlow library.

I solved the problem by using a different version of the Library. Instead of using 2.1.0-ALPHA precompiled, I use 2.1.0-ALPHA. I am not sure the difference between “precompiled” version and “non-precompiled” one. But this switch solved the problem.

Thank you for taking the time to post an update with your solution. I'm sure those who find this thread while searching for a solution to the same problem will be very grateful.

The precompiled version is intended to make the sketch compilation time faster by pre-compiling the library in advance. But if I had to chose between a fast compilation that crashes the board and a little bit slower one that works fine, I know which one I would pick!

Regards, Per