You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/06.nicla/boards/nicla-vision/tutorials/proximity/content.md
+40-34Lines changed: 40 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -22,8 +22,6 @@ In this tutorial you will use the Nicla Vision to detect proximity, thanks to th
22
22
23
23
This tutorial teaches you how to create a sketch that will blink the built-in RGB LED and control the speed of its blink with the proximity values. It can be useful for future projects where there is the need to control the camera only when something is detected in front of the sensor.
24
24
25
-
***The Arduino sketch shown is available inside the `Arduino_Pro_Tutorials` library by going to Examples > Nicla Vision > Proximity_Blink***
26
-
27
25
## Goals
28
26
29
27
- Set up the needed libraries
@@ -41,24 +39,24 @@ This tutorial teaches you how to create a sketch that will blink the built-in RG
41
39
42
40

43
41
44
-
To make sure that the sketch works properly, the latest versions of the **Arduino mbed Core** and the **VL53L1X library**needs to be installed. Both can be found inside the Arduino IDE.
42
+
To make sure that the sketch works properly, the latest versions of the **Arduino Mbed OS Nicla**core and the **VL53L1X library**need to be installed. Both can be found inside the Arduino IDE.
45
43
46
-
- The **Arduino mbed Core** can be found in the **boards manager...**.
47
-
- The **VL53L1X library** can be found in the **Library manager**,
44
+
- The **Arduino Mbed OS Nicla**core can be found in the **boards manager...**
45
+
- The **VL53L1X library** can be found in the **Library manager**
48
46
49
-
If you are using version 1.6.2 or later of the Arduino software (IDE), you can use the Library Manager to install the VL53L1X library:
47
+
If you are using version 2.2.0 or later of the Arduino IDE, install the VL53L1X library as follows:
50
48
51
-
- In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
52
-
- Search for "VL53L1X".
49
+
- In the left bar of the Arduino IDE, click on the **Library Manager**.
50
+
- Search for **VL53L1X**.
53
51
- Click the VL53L1X entry in the list, authored by Pololu.
54
-
- Click "Install". More detailed instructions on how to install a library can be found [here](/learn/starting-guide/software-libraries).
52
+
- Click **Install**. More detailed instructions on how to install a library can be found [here](https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-installing-a-library/).
55
53
56
54
57
55
### Include the Needed Libraries and Objects Declaration
58
56
59
57
First of all, declare the sensor's class so you can access it later on in your sketch. You can use variables to control the time elements in the sketch. This will make sure that the readings stay accurate over time.
60
58
61
-
```cpp
59
+
```arduino
62
60
#include "VL53L1X.h"
63
61
VL53L1X proximity;
64
62
@@ -70,11 +68,11 @@ int blinkTime = 2000;
70
68
71
69
### Initialize the Proximity Sensor and the LED
72
70
73
-
Inside the setup you need to initialize and configure the proximity sensor. Also the RGB LED needs to be set as an output to make it light up and enable you to change its behavior.
71
+
Inside the setup you need to initialize and configure the proximity sensor. Also, the RGB LED needs to be set as an output to make it light up and enable you to change its behavior.
74
72
75
73
***The LEDs are accessed in the same way as on the Portenta H7: LEDR, LEDG and LEDB.***
76
74
77
-
```cpp
75
+
```arduino
78
76
void setup(){
79
77
Serial.begin(115200);
80
78
Wire1.begin();
@@ -95,13 +93,13 @@ Inside the setup you need to initialize and configure the proximity sensor. Also
95
93
}
96
94
```
97
95
98
-
***Make sure you initialize `Wire1`, set the clock speed to 400 kHz and set the bus pointer to `Wire1`. It will not work if you do not add these setting.***
96
+
***Make sure you initialize `Wire1`, set the clock speed to 400 kHz and set the bus pointer to `Wire1`. It will not work if you do not add these settings.***
99
97
100
98
### Control the Speed of the Blink
101
99
102
-
The sketch is going to get the reading on every loop, store it and then the state of the LED will change, until the time is up and another proximity reading is taken.
100
+
The sketch is going to get the reading on every loop, store it and then the state of the LED will change until the time is up and another proximity reading is taken.
103
101
104
-
```cpp
102
+
```arduino
105
103
void loop(){
106
104
reading = proximity.read();
107
105
Serial.println(reading);
@@ -117,7 +115,7 @@ The sketch is going to get the reading on every loop, store it and then the stat
117
115
118
116
### Complete Sketch
119
117
120
-
```cpp
118
+
```arduino
121
119
#include "VL53L1X.h"
122
120
VL53L1X proximity;
123
121
@@ -159,26 +157,34 @@ void loop() {
159
157
}
160
158
```
161
159
160
+
Here is a demo video of the example running on the Nicla Vision:
| setAddress(newAddress) | Change the I2C sensor's address (Mandatory to set it to `Wire1`) |`void`|
166
-
| getAddress() | Get the Sensor's I2C address |`uint8_t`|
167
-
| init() | Configures the sensor and needed data. Like the usual begin()|`void`|
168
-
| setDistanceMode(mode) | Set the distance mode (check the datasheet). Available modes `VL53L1X::Short`, `VL53L1X::Medium`, `VL53L1X::Long`, `VL53L1X::Unknown`|`void`|
169
-
| getDistanceMode() | Returns the mode that has been set. Available modes `VL53L1X::Short`, `VL53L1X::Medium`, `VL53L1X::Long`, `VL53L1X::Unknown`|`enum DistanceMode `|
170
-
| setMeasurementTimingBudget(uSeconds) | Set the time to get the measure, greater the value, better precision. In micro seconds. |`void`|
171
-
| getMeasurementTimingBudget() | Get the measure timing value in micro seconds. |`uint32_t`|
172
-
| startContinuous() | Start the non stop readings, set the period inside the parameter, after that time you will get the reading. |`void`|
173
-
| stopContinuous() | Stop the non stop measurements. |`void`|
174
-
| read() | Get the last reading from the continuous mode. |`void`|
175
-
| readSingle() | Trigger one reading and get its result. |`uint16_t`|
176
-
| dataReady() | Returns if the sensor has new data available. |`bool`|
177
-
| setTimeout(mSeconds) | Configure the milliseconds the sensor will wait in case it is not getting the proper reading to abort, and continue with a new one, 0 disables it. |`void`|
178
-
| getTimeout() | Get the configured timeout value. |`uint16_t`|
179
-
| timeoutOccurred() | Returns true whenever the sensor had a timeout. |`bool`|
| setAddress(newAddress) |Change the I2C sensor's address (Mandatory to set it to `Wire1`) |`void`|
172
+
| getAddress() |Get the Sensor's I2C address |`uint8_t`|
173
+
| init() |Configures the sensor and needed data. Like the usual begin()|`void`|
174
+
| setDistanceMode(mode) |Set the distance mode (check the datasheet). Available modes `VL53L1X::Short`, `VL53L1X::Medium`, `VL53L1X::Long`, `VL53L1X::Unknown`|`void`|
175
+
| getDistanceMode() |Returns the mode that has been set. Available modes `VL53L1X::Short`, `VL53L1X::Medium`, `VL53L1X::Long`, `VL53L1X::Unknown`|`enum DistanceMode `|
176
+
| setMeasurementTimingBudget(uSeconds) |Set the time to get the measure, greater the value, better precision. In micro seconds. |`void`|
177
+
| getMeasurementTimingBudget() |Get the measure timing value in micro seconds. |`uint32_t`|
178
+
| startContinuous() |Start the non stop readings, set the period inside the parameter, after that time you will get the reading. |`void`|
179
+
| stopContinuous() |Stop the non stop measurements. |`void`|
180
+
| read() |Get the last reading from the continuous mode. |`void`|
181
+
| readSingle() |Trigger one reading and get its result. |`uint16_t`|
182
+
| dataReady() |Returns if the sensor has new data available. |`bool`|
183
+
| setTimeout(mSeconds) | Configure the milliseconds the sensor will wait in case it is not getting the proper reading to abort, and continue with a new one, 0 disables it. |`void`|
184
+
| getTimeout() |Get the configured timeout value. |`uint16_t`|
185
+
| timeoutOccurred() |Returns true whenever the sensor had a timeout. |`bool`|
180
186
181
187
182
188
## Conclusion
183
189
184
-
In this tutorial we went through how to get readings from the ToF sensor and how use these readings to change how the built-in LED behaves. At the end of the tutorial you can also find a reference list for the ToF library.
190
+
In this tutorial we went through how to get readings from the ToF sensor and how to use these readings to change how the built-in LED behaves. At the end of the tutorial you can also find a reference list for the ToF library.
0 commit comments