The OpenMV IDE is meant to provide an Arduino like experience for simple machine vision tasks using a camera sensor. In this tutorial, you will learn about some of the basic features of the OpenMV IDE and how to create a simple MicroPython script.
Using the OpenMV IDE you can run MicroPython scripts on the Portenta H7 board. MicroPython provides a lot of classes and modules that make it easy to quickly explore the features of the Portenta H7. In this tutorial you will first download the OpenMV IDE and set up the development environment. Here you can read more about the OpenMV IDE. OpenMV comes with its own firmware that is built on MicroPython. You will then learn to write a simple script that will blink the on-board RGB LED using some basic MicroPython commands.
Before you can start programming OpenMV scripts for the Portenta you need to download and install the OpenMV IDE.
IMPORTANT: Before you connect the Portenta to the OpenMV IDE make sure you update the bootloader as explained in the "Flashing the OpenMV Firmware" section!
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 Portenta to your computer via the USB-C cable if you haven't done so yet. Make sure you first update the bootloader to the latest version using the PortentaH7_updateBootloader sketch in the examples menu in the Arduino IDE.
Instructions on how to update the bootloader can be found in the "Updating the Portenta Bootloader" tutorial.
After updating the bootloader put the Portenta in bootloader mode by double-pressing the reset button on the board. The built-in green LED will start fading in and out. Now open the OpenMV IDE.
Click on the "connect" symbol at the bottom of the left toolbar.
A pop-up will ask you how you would like to proceed. Select "Reset Firmware to Release Version". This will install the latest OpenMV firmware on the Portenta H7. You can leave the option of erasing the internal file system unselected and click "OK".
Portenta H7's green LED will start flashing while the OpenMV firmware is being uploaded to the board. A terminal window will open which shows you the flashing progress. Wait until the green LED stops flashing and fading. 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 Portenta H7. Also the M7 port won't be exposed in the Arduino IDE anymore. To re-flash the M7 with an Arduino firmware you need to put the board into bootloader mode. To do so double press the reset button on the Portenta H7 board. The built-in green LED will start fading in and out. In bootloader mode you will see the Portenta M7 port again in the Arduino IDE.
The board will start flashing its blue LED when it's ready to be connected. After confirming the completion dialog the Portenta H7 should already be connected to the OpenMV IDE, otherwise click the "connect" button (plug symbol) once again.
Create a new script by clicking the "New File" button in the toolbar on the left side. Import the required module
import pyb # Import module for board related functions
A module in Python is a confined bundle of functionality. By importing it into the script it gets made available. For this example we only need
pyb, which is a module that contains board related functionality such as PIN handling. You can read more about its functions here.
Now we can create the variables that will control our built-in RGB LED. With
pyb we can easily control each colour.
redLED = pyb.LED(1) # built-in red LED greenLED = pyb.LED(2) # built-in green LED blueLED = pyb.LED(3) # built-in blue LED
Now we can easily distinguish between which color we control in the script.
Putting our code inside a while loop will make the code run continuously. In the loop we turn on an LED with
on, then we use the
delay function to create a delay. This function will wait with execution of the next instruction in the script. The duration of the delay can be controlled by changing the value inside the parentheses. The number defines how many milliseconds the board will wait. After the specified time has passed, we turn off the LED with the
off function. We repeat that for each colour.
while True: # Turns on the red LED redLED.on() # Makes the script wait for 1 second (1000 milliseconds) pyb.delay(1000) # Turns off the red LED redLED.off() pyb.delay(1000) greenLED.on() pyb.delay(1000) greenLED.off() pyb.delay(1000) blueLED.on() pyb.delay(1000) blueLED.off() pyb.delay(1000)
Here you can see the complete blink script:
import pyb # Import module for board related functions redLED = pyb.LED(1) # built-in red LED greenLED = pyb.LED(2) # built-in green LED blueLED = pyb.LED(3) # built-in blue LED while True: # Turns on the red LED redLED.on() # Makes the script wait for 1 second (1000 milliseconds) pyb.delay(1000) # Turns off the red LED redLED.off() pyb.delay(1000) greenLED.on() pyb.delay(1000) greenLED.off() pyb.delay(1000) blueLED.on() pyb.delay(1000) blueLED.off() pyb.delay(1000)
Connect your board to the OpenMV IDE and upload the above script by pressing the play button in the lower left corner.
Now the built-in LED on your Portenta board should be blinking red, green and then blue repeatedly.
In this tutorial you learned how to use the OpenMV IDE with your Portenta board. You also learned how to control the Portenta H7's RGB LED with MicroPython functions and to upload the script to your board using the OpenMV IDE.