I'm working on a remote controlled car using the Arduino Nano BLE33.
I am using the Arduino IDE 1.8.13.
It worked fine until today. I reprogrammed the Arduino and my program seems to be running. However the LED next to the USB port (LED_BUILTIN) is blinking. I have not programmed it to do so. It blinks 4x short and 4x long and then repeats.
When connecting the Arduino to the PC I can hear the "connect-sound" and a new USB device shows up in the device manager. It also shows up in the Arduino IDE. However, I can neither open the Serial Monitor nor program it, as the IDE freezes until I disconnect the Arduino.
Do you have any ideas how to fix that? Is there any documentation about the blink code?
Edit: Just found out that pressing the reset button twice makes the arduino programmable again. Still, I would like to know what the blink code means.
A 4X long, 4X short blink pattern indicates Mbed OS has crashed. This causes the USB code that creates the CDC serial port to stop running, thus no port.
You can recover from this by putting the board in bootloader mode:
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 Arduino IDE's Tools > Port menu. The port may be different when the bootloader is running so don't assume you already have the correct port selected.
Select Sketch > Upload from the Arduino IDE's menus.
The upload should now complete successfully. However, if you upload the same sketch you were running when you had the problem, it will probably just occur again. You will need to figure out what part of the sketch is crashing Mbed OS. Now that you know how to recover the board from a crash, you can start working on that.
Debug information is printed on Serial1 when Mbed OS crashes. You can view the debug output by following these instructions (no guarantee it will be helpful though):
Unplug your Nano 33 BLE board from the computer or power supply.
Make the following connections between a USB to TTL serial adapter (AKA "FTDI") and your Nano 33 BLE:
Adapter
Nano 33 BLE
RX
TX1
GND
GND
You will also need to power the Nano 33 BLE. You can do this via the USB socket, or power it from the USB to TTL serial adapter’s VCC pin. If the serial adapter’s VCC pin is outputting 5 V, connect it to the Nano 33 BLE’s VIN pin. If the serial adapter’s VCC pin is outputting 3.3 V, connect it to the Nano 33 BLE’s 3.3 V pin.
Connect the serial adapter to your computer with a USB cable.
Select the port of the serial adapter from the Arduino IDE’s Tools > Port menu.
Select Tools > Serial Monitor from the Arduino IDE's menus.
Set the baud rate menu at the bottom right corner of Serial Monitor to 115200.
Press and release the reset button on the Nano 33 BLE. You should now see the "MbedOS Error Info" output in the Serial Monitor output field.
The truth is that every time I've hooked up a USB to TTL serial adapter to my Nano 33 BLE board to check the crash debug output, it was cryptic and or uninformative. Probably to someone with more knowledge of Mbed OS it would be more useful.
However, either way, a USB to TTL serial adapter is a very useful (and fairly inexpensive) tool in general for anyone involved in Arduino, etc. to have on hand. I use mine all the time, even if not so much for debugging Mbed OS.
Even without the detailed serial output, it's useful to know the general meaning of this blink patten.
I have wondered the same, but I've only ever seen the 4X long, 4X short pattern from the Nano 33 BLE boards and the Portenta H7 (the Portenta also uses Mbed OS). That includes my own use (which frequently consists of intentionally trying to crash Mbed OS), as well as in a year of closely monitoring the forum and the issue trackers for this sort of information.
So my guess is there is only the one blink pattern. Of course, a specific sketch or library could use other blink patterns as its own indicator, completely separate from the Mbed crash situation.
Soon after my last post I figured out, that a call to map(...) was the problem. However I could not find out why, so I replaced it with something else in the code.
Now I know why mbed crashed:
I called map(value, 8.2, 8.8, toLow, toHigh) which leads to a division by zero. The problem is that map only has integer parameters, so actually map(value, 8, 8, toLow, toHigh) is called.
For me, it is strange that the Arduino Reference does not specify the types more clearly. I understand that it may confuse newcomers and I do not want to blame the Arduino Reference as the parameter types are stated in the Appendix of map and there even is a warning about integer math. However, stating the parameter types in the section about the syntax may have prevented the error.
Before starting with my project I even turned on compiler warnings, but I am using the ArduinoBLE library which also generates warnings, so warnings in my own code do not stick out as much.
I called map(value, 8.2, 8.8, toLow, toHigh) which leads to a division by zero. The problem is that map only has integer parameters, so actually map(value, 8, 8, toLow, toHigh) is called.
Thanks for taking the time to report your findings @chris1235! That is certainly valuable information for others who will have the same problem.
I'm also seen this cause of the Mbed OS crash.
chris1235:
For me, it is strange that the Arduino Reference does not specify the types more clearly.
...
However, stating the parameter types in the section about the syntax may have prevented the error.
I agree 100% that all parameter and return types should be clearly documented. This is very important information.