Skip to content

Commit e81ac74

Browse files
authored
Merge pull request #496 from arduino/karlsoderby/rp2040-iotc-update
[MKC-659] Update RP2040 IoTC tutorial
2 parents 45950ac + 8f88b24 commit e81ac74

32 files changed

+88
-134
lines changed

content/hardware/03.nano/boards/nano-rp2040-connect/tutorials/rp2040-iot-cloud/rp2040-iot-cloud.md

Lines changed: 88 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ software:
1717
- iot-cloud
1818
---
1919

20+
![Nano RP2040 Connect.](assets/nano-board.png)
21+
2022
## Introduction
2123

2224
In this tutorial, we will go through the steps needed to connect the [Nano RP2040 Connect](https://store.arduino.cc/nano-rp2040-connect) to the [Arduino IoT Cloud](https://create.arduino.cc/iot/).
@@ -40,168 +42,127 @@ The goals of this project are:
4042

4143
Follow the circuit below to connect the buttons and LEDs to your Arduino board.
4244

43-
>**Note:** Remember that the pinouts are different on a Nano 33 IoT board. This circuit works for the MKR WiFi 1000/1010 boards.
44-
45-
![This tutorial requires no additional circuit.](assets/rp2040-iot-cloud-01.png)
45+
![This tutorial requires no additional circuit.](assets/circuit.png)
4646

4747
## The Arduino IoT Cloud
4848

49-
To start, we will need to head over to the [Arduino IoT Cloud](https://create.arduino.cc/iot/). This is also accessible through the menu at the top right.
50-
51-
![Navigate to the cloud.](assets/rp2040-iot-cloud-02.png)
52-
53-
### Step 1: Setting up the Device
54-
55-
**1.** Once we are in the IoT Cloud, we need to first create a Thing, by clicking on the **"Create a Thing"** button.
56-
57-
![Creating a Thing.](assets/rp2040-iot-cloud-03.png)
58-
59-
**2.** Now, we need to configure our device, by clicking on the **"Select Device"** button.
60-
61-
![Select the device.](assets/rp2040-iot-cloud-04.png)
62-
63-
**3.** Next we need to select the **"Set up an Arduino device"** option. After a while, your device should appear. Click on the **"Configure"** button.
64-
65-
![Click on configure.](assets/rp2040-iot-cloud-05.png)
66-
67-
**4.** Name the board, and click on **"Next"** which will start a configuration process. Do not disconnect the board during this process.
68-
69-
![Choose the name of the board.](assets/rp2040-iot-cloud-06.png)
70-
71-
**5.** After some time, the installation will complete, and your Nano RP2040 is ready for the IoT Cloud.
49+
To start, we will need to head over to the [Arduino IoT Cloud](https://create.arduino.cc/iot/).
7250

73-
![Installation is successful.](assets/rp2040-iot-cloud-07.png)
51+
### Step 1: Configure Your Device
7452

75-
### Step 2: Creating Variables
53+
Once we are in the IoT Cloud, to configure our device, click on the **"Devices"** tab. Click on **"Add Device"** and follow the configuration to set up your board.
7654

77-
Now, we will need to create variables that will be used to control and read data from the board. This is done by clicking on the **"Add Variable"** button.
55+
***Make sure your device is connected to your computer via USB at this point.***
7856

79-
![Click on the "Add Variable" button.](assets/rp2040-iot-cloud-08.png)
57+
![Configure a device.](assets/devices.png)
8058

81-
We will add variables to control the **RGB** and to read the **Accelerometer**.
8259

60+
### Step 2: Create a Thing
8361

84-
| Variable Name | Data Type | Permission |
85-
| ------------- | --------- | ------------ |
86-
| a_x | float | read only |
87-
| a_y | float | read only |
88-
| a_z | float | read only |
89-
| red | boolean | read & write |
90-
| green | boolean | read & write |
91-
| blue | boolean | read & write |
62+
The next step is to create a new Thing. Navigate to the **"Things"** tab, and click on **"Create Thing".**
9263

93-
The final overview should look something like this:
64+
![Create a Thing.](assets/thing.png)
9465

95-
![The final view.](assets/rp2040-iot-cloud-09.png)
66+
When you create a Thing, you will see a number of options:
67+
- **Select Device** - the device you configured can be selected here.
68+
- **Select Network** - enter your network credentials (Wi-Fi name and password).
69+
- **Add Variables** - here we add variables that we will synchronize with our sketch.
9670

97-
>**Tip:** You can also name your Thing, by clicking on the "Untitled XX" tag. We renamed this Thing RP2040 Cloud Project. This makes it easier to track if you have multiple things.
71+
![Thing overview.](assets/variables.png)
9872

99-
### Step 3: Network Details
73+
The variables we will add are for controlling the **RGB** and to reading the **Accelerometer**. You can create them based on the table below:
10074

101-
For our board to connect to our Wi-Fi network, we also need to enter the credentials. This is done by clicking the button inside the **"Network Section"**
10275

103-
![The network section.](assets/rp2040-iot-cloud-10.png)
76+
| Variable Name | Data Type | Permission |
77+
| ------------- | ------------- | ------------ |
78+
| a_x | float | read only |
79+
| a_y | float | read only |
80+
| a_z | float | read only |
81+
| rgb_light | Colored Light | read & write |
10482

105-
Then, enter your credentials (network and password). Remember that it is case-sensitive.
83+
Once the variables are created, your Thing overview should look similar to the image below:
10684

107-
![Enter the credentials to your network.](assets/rp2040-iot-cloud-11.png)
85+
![The final view.](assets/final-thing.png)
10886

109-
### Step 4: Creating the Program
87+
### Step 3: The Sketch
11088

111-
Now, we need to create the program for our Thing. First, let's head over to the **"Sketch"** tab in the Arduino IoT Cloud.
89+
Now, we need to create the program for our Thing. First, let's head over to the **"Sketch"** tab in the Arduino IoT Cloud. At the top, your board should be available in the dropdown menu by default.
11290

113-
![Click on the "Sketch" tab to edit the sketch.](assets/rp2040-iot-cloud-12.png)
91+
![Nano RP2040 Connect from board list.](assets/boardfound.png)
11492

115-
The code that is needed can be found in the snippet below. Upload the sketch to the first board.
93+
The code can be found in the snippet below. Upload the code to your board.
11694

11795
```arduino
118-
11996
#include "thingProperties.h"
12097
#include <Arduino_LSM6DSOX.h>
12198
12299
void setup() {
123-
// Initialize serial and wait for port to open:
124-
pinMode(LEDR, OUTPUT);
125-
pinMode(LEDG, OUTPUT);
126-
pinMode(LEDB, OUTPUT);
127100
128101
Serial.begin(9600);
129-
130-
while(!Serial); // Prevents sketch from running until Serial Monitor opens.
102+
delay(1500);
131103
132-
if (!IMU.begin()) {
133-
Serial.println("Failed to initialize IMU!");
134-
while (1);
135-
}
136-
137-
delay(1500);
104+
//define RGB LED as outputs
105+
pinMode(LEDR, OUTPUT);
106+
pinMode(LEDG, OUTPUT);
107+
pinMode(LEDB, OUTPUT);
138108
139-
// Defined in thingProperties.h
140109
initProperties();
141110
142-
// Connect to Arduino IoT Cloud
143111
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
144-
145-
/*
146-
The following function allows you to obtain more information
147-
related to the state of network and IoT Cloud connection and errors
148-
the higher number the more granular information you’ll get.
149-
The default is 0 (only errors).
150-
Maximum is 4
151-
*/
112+
152113
setDebugMessageLevel(2);
153114
ArduinoCloud.printDebugInfo();
115+
116+
//init IMU library
117+
if (!IMU.begin()) {
118+
Serial.println("Failed to initialize IMU!");
119+
while (1);
120+
}
154121
}
155122
156123
void loop() {
157124
ArduinoCloud.update();
158-
//reads acceleration
159-
if (IMU.accelerationAvailable()) {
160-
IMU.readAcceleration(a_x, a_y, a_z);
161-
}
162-
163-
}
164-
165125
166-
void onRedChange() {
167-
if(red){
168-
digitalWrite(LEDR, HIGH); //turn on RED
169-
}
170-
else{
171-
digitalWrite(LEDR, LOW); //turn off RED
126+
//read acceleration and store in a_x, a_y, a_z variables
127+
if (IMU.accelerationAvailable()) {
128+
IMU.readAcceleration(a_x, a_y, a_z);
172129
}
173130
}
174131
132+
/*
133+
the onRgbLightChange() function is triggered
134+
when the rgb_light variable changes
135+
*/
175136
176-
void onGreenChange() {
177-
if(green){
178-
digitalWrite(LEDG, HIGH); //turn on GREEN
179-
}
180-
else{
181-
digitalWrite(LEDG, LOW); //turn off GREEN
182-
}
183-
}
137+
void onRgbLightChange() {
138+
//create r,g,b variables
139+
uint8_t r, g, b;
140+
141+
//retrieve values from the cloud
142+
rgb_light.getValue().getRGB(r, g, b);
184143
144+
//values on Nano RP2040 Connect are inverted
145+
//so let's remap them
146+
int red = map(r, 0, 255, 255, 0);
147+
int green = map(g, 0, 255, 255, 0);
148+
int blue = map(b, 0, 255, 255, 0);
185149
186-
void onBlueChange() {
187-
if(blue){
188-
digitalWrite(LEDB, HIGH); //turn on BLUE
150+
if (rgb_light.getSwitch()) {
151+
analogWrite(LEDR, red);
152+
analogWrite(LEDG, green);
153+
analogWrite(LEDB, blue);
189154
}
190-
else{
191-
digitalWrite(LEDB, LOW); //turn off BLUE
155+
else {
156+
analogWrite(LEDR, 255);
157+
analogWrite(LEDG, 255);
158+
analogWrite(LEDB, 255);
192159
}
193160
}
194161
```
195162

196-
### Step 5: Testing the Program
197-
198-
After we have successfully uploaded our sketch to our board, we need to initialize the code, by opening the Serial Monitor.
163+
Once the code has been uploaded to your board, it will attempt to connect to your network, and then with the Arduino Cloud. You can open the Serial Monitor to see if there are any errors.
199164

200-
![Open the Serial Monitor tab.](assets/rp2040-iot-cloud-13.png)
201-
202-
In this window, we should after a few seconds see information regarding our connection printed.
203-
204-
If the connection (to the network and cloud) is successful, it should print something like the following:
165+
If all went well, you will see a message like this:
205166

206167
```
207168
***** Arduino IoT Cloud - configuration info *****
@@ -214,47 +175,40 @@ Connected to "<your-network>"
214175
Connected to Arduino IoT Cloud
215176
```
216177

217-
This means everything is good, and we can move on the next step: creating a dashboard.
218-
219-
>**Troubleshooting tip:** If you're failing to connect, check that your credentials match in the network section, and that you are uploading the right sketch to the right board.
178+
If it went wrong, you may encounter errors such as:
220179

221-
### Step 6: Creating the Dashboard
222-
223-
Once our sketch is successfully uploaded and the Serial Monitor has given us the green light, we can finalize this project by creating a dashboard. To do this, we need to navigate to the **"Dashboards"** tab.
224-
225-
![Navigate to the Dashboards tab.](assets/rp2040-iot-cloud-14.png)
226-
227-
Then, we need to click on the **"Build dashboard"** button.
228-
229-
![Click on "Build Dashboard" button.](assets/rp2040-iot-cloud-15.png)
180+
```
181+
Connection to "<your-network>" failed. Retrying in 500 milliseconds.
182+
```
230183

231-
We will now see a blank dashboard. Now, click on the **pen symbol** in the top left corner. This will allow you to edit the dashboard.
184+
Which indicate that something might be wrong with your network credentials.
232185

233-
![Click on the "Edit button", the pen symbol.](assets/rp2040-iot-cloud-16.png)
186+
### Step 4: Creating a Dashboard
234187

235-
Once we are in edit mode, we can click on **"Add"**, then select the **"Things"** column, and select the Thing we created earlier. We will now be presented with a list of our variables, where we can click on the **"Add variables"** button. This will automatically create **widgets** that are linked to our variables.
188+
Once our sketch is successfully uploaded we can finalize this project by creating a dashboard. To do this, we need to navigate to the **"Dashboards"** tab, and click on the **"Build Dashboard"** tab.
236189

237-
![Adding variables to our dashboard.](assets/rp2040-iot-cloud-17.png)
190+
![Create a Dashboard.](assets/create-dashboard.png)
238191

239-
After we click on the button, we be presented with the widget settings window. Just click on the **"Done"** button at the bottom right.
192+
This will open an empty dashboard. At the top left corner, first click on the **Pen Symbol**. You are now in Edit Mode.
240193

241-
![Click on the done button.](assets/rp2040-iot-cloud-18.png)
194+
Now, click on the **"ADD"** button, then **"Things"**, search and click on your Thing. You will now see a list of variables with a checkmark. Leave all marked, and click on the **"Create Widgets** button.
242195

243-
Now, we have our widgets on the dashboard, but the dimensions etc. are not the best. If we click on the **multi-arrow** symbol, we can move around and re-size our widgets however we want to! When we are happy, we can just click on the same button.
196+
![Click on the "Edit button", the pen symbol.](assets/create-widgets.png)
197+
We should now have a pretty nice looking dashboard that displays the value of our accelerometer, and a **colored light widget** to control the built-in RGB on the Nano RP2040 Connect.
244198

245-
![Resizing and moving the widgets.](assets/rp2040-iot-cloud-19.png)
199+
These widgets can be re-sized and adjusted to your liking. You can also select and link other types of widgets, but this is by far the quickest option.
246200

247-
We should now have a pretty nice looking dashboard that displays the value of our accelerometer, and three switch widgets to control the built-in RGB on the Nano RP2040 Connect.
201+
![Final look of the dashboard.](assets/dashboard-final.png)
248202

249-
### Step 7: Testing It Out
203+
## Expected Outcome
250204

251-
Now that everything is set up, let's test it out. We can begin by checking the data from the IMU. If we move around our board, we can see that the widgets in the dashboard is changing as well.
205+
Congratulations. You have now configured your Nano RP2040 Connect board with the Arduino Cloud service.
252206

253-
![IMU data changing when board is moved.](assets/rp2040-iot-cloud-20.png)
207+
If your board successfully connects to the Arduino Cloud, we should be seeing values in the dashboard update continuously, and we can change the color of the RGB through the colored light widget.
254208

255-
Now, to control the built-in RGB on the board, we need to use the **switch widgets**. These switches are labeled `red`, `green` and `blue` and can simply be turned ON / OFF. In this example, we activated the red pixel, which can be seen in the image below.
209+
![Control and monitor your Nano RP2040 Connect.](assets/rp2040-cloud.gif)
256210

257-
![Red pixel activated on the Nano RP2040 Connect board.](assets/rp2040-iot-cloud-21.png)
211+
![Controlling the RGB on the Nano RP2040 Connect.](assets/nano-board.png)
258212

259213
## Conclusion
260214

0 commit comments

Comments
 (0)