This tutorial will show you how to update the bootloader with an Arduino IDE sketch. This is required to run the OpenMV firmware. It shows you how to connect the board in OpenMV and upload a MicroPython script that controls the built-in RGB LED.
The updated bootloader will first look for a valid sketch at the memory address
. This ensures backwards compatibility with the standard sketches uploaded from the Arduino IDE. If no valid sketch is found, because maybe a softdevice has been placed in that portion of the flash, the bootloader looks for a valid firmware at
and this is the one that you will upload as part of this tutorial.
With your board connected, open up the Arduino IDE. This step is the same for both the IDE 1 and the IDE 2. Open the board manager and search for "mbed". Find the "Arduino Mbed OS Nano Boards" core and click on "Install" to install the latest version.
Then, open: File>Examples>Nano33_System>Nano33_updateBLandSoftDevice
Upload the sketch to your board and open the serial monitor. If you haven't installed the latest bootloader yet, in the serial monitor you will get the option to do so. Enter "y" into the serial monitor and press the return key. Once the process is done, you will be asked if you want to install the softdevice. Enter "y" and press the return key. Wait for the update to finish. Your board will restart when the process is done and put itself into bootloader mode.
Before you can start programming OpenMV scripts for the Nano 33 BLE sense you need to download and install the OpenMV IDE.
Open the OpenMV download page in your browser, download the version that you need for your operating system and follow the instructions of the installer.
Connect the Nano 33 BLE sense to your computer via the USB cable if you haven't done so yet. Make sure you have installed the latest bootloader and softdevice as indicated in the previous step.
After updating the bootloader put the Nano 33 BLE sense in bootloader mode if necessary. The board automatically goes into booloader mode after the update is finished. However, if you restarted the board in the mean time, double click the reset button to bring it into bootloader mode.
Click on the "connect" symbol at the bottom of the left toolbar.
A pop-up will ask you how you would like to proceed "DFU bootloader(s) found. What would you like to do?". Select "Reset Firmware to Release Version". This will install the latest OpenMV firmware on the Nano. If it asks you whether it should erase the internal file system you can click "No".
A terminal window will open which shows you the upload progress. You will see a message saying "DFU firmware update complete!" when the process is done.
Installing the OpenMV firmware will overwrite any existing sketches in the internal flash of your board. Also the board's port won't be accessible in the Arduino IDE anymore. To re-flash the board with an Arduino firmware you need to put the board into bootloader mode. To do so double press the reset button on the board. The built-in yellow LED will start fading in and out.
After confirming the completion dialog the board should already be connected to the OpenMV IDE, otherwise click the "connect" button once again.
Now let's create a version of the classic Arduino blink example with MicroPython in OpenMV. First, we need to import some modules in our script, to help us control the board with MicroPython. We do this by adding these lines of code at the beginning of our script.
1import time2from board import LED
from the board module, allows us to control the built-in LED on the board. The
module will help us with timed functions, such as a delay.
Now let's take a look at how to create the main loop of the script. The main loop will turn on the LED in a specific color, wait a short moment, turn it off and move on to a different color. But first, we need to define the variables that control the LED.
1led_red = LED(1)2led_green = LED(2)3led_blue = LED(3)4led_yellow = LED(4)
The built-in LEDs on the board can now be easily controlled with these different variables. Each variable corresponds to one color of the built-in RGB LED except of yellow which is used for the yellow built-in LED.
1while (True):2 # Turns on the blue built-in LED3 led_blue.on()4 # Adds a 250 millisecond delay5 time.sleep_ms(250)6 # Turns off the blue built-in LED7 led_blue.off()89 led_red.on()10 time.sleep_ms(250)11 led_red.off()1213 led_green.on()14 time.sleep_ms(250)15 led_green.off()1617 led_yellow.on()18 time.sleep_ms(250)19 led_yellow.off()2021 time.sleep_ms(500)
We use the function
to determine the length of the delay between turning the LED on and off. The number inside the parentheses indicates how many milliseconds the delay should last. Putting the code inside a
function will make it run in a continuous loop.
To upload the script with OpenMV, enter all the code previously explained into an empty script, then simply press the green play button in the lower left corner.
The complete script is as follows:
1import time2from board import LED34led_red = LED(1)5led_green = LED(2)6led_blue = LED(3)7led_yellow = LED(4)89while (True):10 # Turns on the blue built-in LED11 led_blue.on()12 # Adds a 250 millisecond delay13 time.sleep_ms(250)14 # Turns off the blue built-in LED15 led_blue.off()1617 led_red.on()18 time.sleep_ms(250)19 led_red.off()2021 led_green.on()22 time.sleep_ms(250)23 led_green.off()2425 led_yellow.on()26 time.sleep_ms(250)27 led_yellow.off()2829 time.sleep_ms(500)
If everything went correctly the built-in LEDs should blink in the color sequence indicated in the code.
Here are some reasons why the softdevice may have to be re-flashed:
and will hence overwrite the SoftDevice. If you want to be able to use OpenMV again, you will need to re-flash the Soft Device.
If the code is not working, there are some common issues you can troubleshoot:
In this tutorial you learned how to update the bootloader and install a softdevice. You were also introduced to OpenMV and MicroPython scripts. Now that you know how to use these, you can explore more of MicroPython's capabilities, check their documentation here.