Skip to content

Commit a82e82f

Browse files
Added tutorial
1 parent 2c9a2f3 commit a82e82f

File tree

6 files changed

+160
-0
lines changed

6 files changed

+160
-0
lines changed
250 KB
Loading
178 KB
Loading
339 KB
Loading
293 KB
Loading
360 KB
Loading
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
title: 'Getting Started with Nicla Vision'
3+
description: 'This tutorial teaches you how to set up the board, how to use the OpenMV IDE and how to run a MicroPython sketch.'
4+
difficulty: easy
5+
tags:
6+
- Getting Started
7+
- OpenMV
8+
- Setup
9+
- MicroPython
10+
author: 'Benjamin Dannegård'
11+
libraries:
12+
- name: MicroPython
13+
url: http://docs.MicroPython.org/en/latest/
14+
software:
15+
- openMV
16+
---
17+
## Overview
18+
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. The Nicla Vision board has OpenMV firmware on the board by default, making it easy to connect to the OpenMV IDE.
19+
20+
## Goals
21+
- The basic features of the OpenMV IDE
22+
- How to create a simple MicroPython script
23+
- How to use the OpenMV IDE to run MicroPython on Nicla Vision
24+
25+
26+
### Required Hardware and Software
27+
- Nicla Vision board (<https://store.arduino.cc/products/nicla-vision>)
28+
- Micro USB cable (either USB A to Micro USB or USB C to Micro USB)
29+
- OpenMV IDE 2.6.4+
30+
31+
## Instructions
32+
33+
Using the OpenMV IDE you can run [MicroPython](http://docs.MicroPython.org/en/latest/) scripts on the Nicla Vision board. MicroPython provides a lot of classes and modules that make it easy to quickly explore the features of the Nicla Vision. In this tutorial you will first download the OpenMV IDE and set up the development environment. [Here](https://openmv.io/) 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.
34+
35+
### 1. Downloading the OpenMV IDE
36+
37+
Before you can start programming OpenMV scripts for the Nicla Vision you need to download and install the OpenMV IDE.
38+
39+
Open the [OpenMV download](https://openmv.io/pages/download) page in your browser, download the version that you need for your operating system and follow the instructions of the installer.
40+
41+
### 2. Flashing the OpenMV Firmware
42+
43+
Connect the Nicla Vision to your computer via the USB cable if you haven't done so yet.
44+
45+
![The OpenMV IDE after starting it](assets/por_openmv_open_ide.png)
46+
47+
Click on the "connect" symbol at the bottom of the left toolbar.
48+
49+
![Click the connect button to attach the Portenta to the OpenMV IDE](assets/por_openmv_click_connect.png)
50+
51+
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 Nicla Vision. You can leave the option of erasing the internal file system unselected and click "OK".
52+
53+
![Install the latest version of the OpenMV firmware](assets/por_openmv_reset_firmware.png)
54+
55+
Nicla Vision'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.
56+
57+
![Installing firmware on portenta board in OpenMV](assets/por_openmv_firmware_updater.png)
58+
59+
The board will start flashing its blue LED when it's ready to be connected. After confirming the completion dialog the Nicla Vision should already be connected to the OpenMV IDE, otherwise click the "connect" button (plug symbol) once again.
60+
61+
![When the Portenta H7 is successfully connected a green play button appears](assets/por_openmv_board_connected.png)
62+
63+
### 3. Preparing the Script
64+
65+
Create a new script by clicking the "New File" button in the toolbar on the left side. Import the required module `pyb`:
66+
67+
```python
68+
import pyb # Import module for board related functions
69+
```
70+
71+
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](https://docs.micropython.org/en/latest/library/pyb.html).
72+
73+
Now we can create the variables that will control our built-in RGB LED. With `pyb` we can easily control each color.
74+
75+
```python
76+
redLED = pyb.LED(1) # built-in red LED
77+
greenLED = pyb.LED(2) # built-in green LED
78+
blueLED = pyb.LED(3) # built-in blue LED
79+
```
80+
81+
Now we can easily distinguish between which color we control in the script.
82+
83+
### 4. Creating the Main Loop in the Script
84+
85+
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 color.
86+
87+
```python
88+
while True:
89+
# Turns on the red LED
90+
redLED.on()
91+
# Makes the script wait for 1 second (1000 milliseconds)
92+
pyb.delay(1000)
93+
# Turns off the red LED
94+
redLED.off()
95+
pyb.delay(1000)
96+
greenLED.on()
97+
pyb.delay(1000)
98+
greenLED.off()
99+
pyb.delay(1000)
100+
blueLED.on()
101+
pyb.delay(1000)
102+
blueLED.off()
103+
pyb.delay(1000)
104+
```
105+
106+
### 5. Uploading the Script
107+
108+
Here you can see the complete blink script:
109+
110+
```python
111+
import pyb # Import module for board related functions
112+
113+
redLED = pyb.LED(1) # built-in red LED
114+
greenLED = pyb.LED(2) # built-in green LED
115+
blueLED = pyb.LED(3) # built-in blue LED
116+
117+
while True:
118+
119+
# Turns on the red LED
120+
redLED.on()
121+
# Makes the script wait for 1 second (1000 milliseconds)
122+
pyb.delay(1000)
123+
# Turns off the red LED
124+
redLED.off()
125+
pyb.delay(1000)
126+
greenLED.on()
127+
pyb.delay(1000)
128+
greenLED.off()
129+
pyb.delay(1000)
130+
blueLED.on()
131+
pyb.delay(1000)
132+
blueLED.off()
133+
pyb.delay(1000)
134+
```
135+
136+
Connect your board to the OpenMV IDE and upload the above script by pressing the play button in the lower left corner.
137+
138+
![Press the green play button to upload the script](assets/por_openmv_board_connected.png)
139+
140+
Now the built-in LED on your Nicla Vision board should be blinking red, green and then blue repeatedly.
141+
142+
## Using the Nicla Vision with Arduino IDE
143+
144+
As mentioned before, the Nicla Vision comes with OpenMV firmware pre installed. This makes it easier to use the board with OpenMV out of the box. It is possible to use the Nicla Vision with the Arduino IDE. First make sure that you have the latest core installed. To install the core navigate into **Tools > Board > Boards Manager...**, in the Boards Manager window search for **Nicla Vision MBED** and install it. When this core is installed and you have your board connected to your computer, put the board into bootloader mode. You do this by double pressing the reset button, located next to the LED.
145+
146+
The board should now be selectable in the Arduino IDE, allowing you to upload sketches to it.
147+
148+
## Conclusion
149+
In this tutorial you learned how to use the OpenMV IDE with your Portenta board. You also learned how to control the Nicla Vision's RGB LED with MicroPython functions and to upload the script to your board using the OpenMV IDE.
150+
151+
### Next Steps
152+
- Experiment with MicroPythons capabilities. If you want some examples of what to do, take a look at the examples included in the OpenMV IDE. Go to: **File>Examples>Arduino>** in the OpenMV IDE.
153+
- Take a look at our other Nicla Vision tutorials which showcase its many uses. You can find them [here](https://docs.arduino.cc/hardware/nicla-vision#tutorials)
154+
155+
## Troubleshooting
156+
157+
### OpenMV Firmware Flashing Issues
158+
- If the upload of the OpenMV firmware fails during the download, put the board back in bootloader mode and try again. Repeat until the firmware gets successfully uploaded.
159+
- If the OpenMV IDE still can't connect after flashing the firmware, try uploading the latest firmware using the "Load Specific Firmware File" option. You can find the latest firmware in the [OpenMV Github repository](https://github.com/openmv/openmv/releases). Look for a file named **firmware.bin** in the PORTENTA folder.
160+
- If you see a "OSError: Reset Failed" message, reset the board by pressing the reset button. Wait until you see the blue LED flashing, connect the board to the OpenMV IDE and try running the script again.

0 commit comments

Comments
 (0)