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
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:
40
42
41
43
Follow the circuit below to connect the buttons and LEDs to your Arduino board.
42
44
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
-

45
+

46
46
47
47
## The Arduino IoT Cloud
48
48
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
-

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
-

58
-
59
-
**2.** Now, we need to configure our device, by clicking on the **"Select Device"** button.
60
-
61
-

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
-

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
-

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/).
72
50
73
-

51
+
### Step 1: Configure Your Device
74
52
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.
76
54
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.***
78
56
79
-

57
+

80
58
81
-
We will add variables to control the **RGB** and to read the **Accelerometer**.
82
59
60
+
### Step 2: Create a Thing
83
61
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".**
92
63
93
-
The final overview should look something like this:
64
+

94
65
95
-

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.
96
70
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
+

98
72
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:
100
74
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"**
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:
106
84
107
-

85
+

108
86
109
-
### Step 4: Creating the Program
87
+
### Step 3: The Sketch
110
88
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.
112
90
113
-

91
+

114
92
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.
116
94
117
95
```arduino
118
-
119
96
#include "thingProperties.h"
120
97
#include <Arduino_LSM6DSOX.h>
121
98
122
99
void setup() {
123
-
// Initialize serial and wait for port to open:
124
-
pinMode(LEDR, OUTPUT);
125
-
pinMode(LEDG, OUTPUT);
126
-
pinMode(LEDB, OUTPUT);
127
100
128
101
Serial.begin(9600);
129
-
130
-
while(!Serial); // Prevents sketch from running until Serial Monitor opens.
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
+
152
113
setDebugMessageLevel(2);
153
114
ArduinoCloud.printDebugInfo();
115
+
116
+
//init IMU library
117
+
if (!IMU.begin()) {
118
+
Serial.println("Failed to initialize IMU!");
119
+
while (1);
120
+
}
154
121
}
155
122
156
123
void loop() {
157
124
ArduinoCloud.update();
158
-
//reads acceleration
159
-
if (IMU.accelerationAvailable()) {
160
-
IMU.readAcceleration(a_x, a_y, a_z);
161
-
}
162
-
163
-
}
164
-
165
125
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);
172
129
}
173
130
}
174
131
132
+
/*
133
+
the onRgbLightChange() function is triggered
134
+
when the rgb_light variable changes
135
+
*/
175
136
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);
184
143
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);
185
149
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);
189
154
}
190
-
else{
191
-
digitalWrite(LEDB, LOW); //turn off BLUE
155
+
else {
156
+
analogWrite(LEDR, 255);
157
+
analogWrite(LEDG, 255);
158
+
analogWrite(LEDB, 255);
192
159
}
193
160
}
194
161
```
195
162
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.
199
164
200
-

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:
205
166
206
167
```
207
168
***** Arduino IoT Cloud - configuration info *****
@@ -214,47 +175,40 @@ Connected to "<your-network>"
214
175
Connected to Arduino IoT Cloud
215
176
```
216
177
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:
220
179
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
-

226
-
227
-
Then, we need to click on the **"Build dashboard"** button.
228
-
229
-

180
+
```
181
+
Connection to "<your-network>" failed. Retrying in 500 milliseconds.
182
+
```
230
183
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.
232
185
233
-

186
+
### Step 4: Creating a Dashboard
234
187
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.
236
189
237
-

190
+

238
191
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.
240
193
241
-

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.
242
195
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
+

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.
244
198
245
-

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.
246
200
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
+

248
202
249
-
### Step 7: Testing It Out
203
+
##Expected Outcome
250
204
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.
252
206
253
-

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.
254
208
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
+

256
210
257
-

211
+

0 commit comments