Setting up Nano RP2040 Connect with Arduino Cloud

Learn how to access the IMU data and control the built-in RGB via the Arduino Cloud.

Nano RP2040 Connect.
Nano RP2040 Connect.

Introduction

In this tutorial, we will go through the steps needed to connect the Nano RP2040 Connect to the Arduino Cloud.

We will test the connection out, by viewing real time data of the IMU (Inertial Measurement Unit), and remotely controlling the RGB on the board.

Goals

The goals of this project are:

  • Set up the Arduino Cloud.
  • Read IMU sensor data.
  • Control the built-in RGB.

Hardware & Software Needed

Circuit

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

This tutorial requires no additional circuit.
This tutorial requires no additional circuit.

The Arduino Cloud

To start, we will need to head over to the Arduino Cloud.

Step 1: Configure Your Device

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.

Make sure your device is connected to your computer via USB at this point.

Configure a device.
Configure a device.

Step 2: Create a Thing

The next step is to create a new Thing. Navigate to the "Things" tab, and click on "Create Thing".

Create a Thing.
Create a Thing.

When you create a Thing, you will see a number of options:

  • Select Device - the device you configured can be selected here.
  • Select Network - enter your network credentials (Wi-Fi name and password).
  • Add Variables - here we add variables that we will synchronize with our sketch.
Thing overview.
Thing overview.

The variables we will add are for controlling the RGB and to reading the Accelerometer. You can create them based on the table below:

Variable NameData TypePermission
a_xfloatread only
a_yfloatread only
a_zfloatread only
rgb_lightColored Lightread & write

Once the variables are created, your Thing overview should look similar to the image below:

The final view.
The final view.

Step 3: The Sketch

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

Nano RP2040 Connect from board list.
Nano RP2040 Connect from board list.

The code can be found in the snippet below. Upload the code to your board.

1#include "thingProperties.h"
2#include <Arduino_LSM6DSOX.h>
3
4void setup() {
5
6 Serial.begin(9600);
7 delay(1500);
8
9 //define RGB LED as outputs
10 pinMode(LEDR, OUTPUT);
11 pinMode(LEDG, OUTPUT);
12 pinMode(LEDB, OUTPUT);
13
14 initProperties();
15
16 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
17
18 setDebugMessageLevel(2);
19 ArduinoCloud.printDebugInfo();
20
21 //init IMU library
22 if (!IMU.begin()) {
23 Serial.println("Failed to initialize IMU!");
24 while (1);
25 }
26}
27
28void loop() {
29 ArduinoCloud.update();
30
31 //read acceleration and store in a_x, a_y, a_z variables
32 if (IMU.accelerationAvailable()) {
33 IMU.readAcceleration(a_x, a_y, a_z);
34 }
35}
36
37/*
38 the onRgbLightChange() function is triggered
39 when the rgb_light variable changes
40*/
41
42void onRgbLightChange() {
43 //create r,g,b variables
44 uint8_t r, g, b;
45
46 //retrieve values from the Cloud
47 rgb_light.getValue().getRGB(r, g, b);
48
49 //values on Nano RP2040 Connect are inverted
50 //so let's remap them
51 int red = map(r, 0, 255, 255, 0);
52 int green = map(g, 0, 255, 255, 0);
53 int blue = map(b, 0, 255, 255, 0);
54
55 if (rgb_light.getSwitch()) {
56 analogWrite(LEDR, red);
57 analogWrite(LEDG, green);
58 analogWrite(LEDB, blue);
59 }
60 else {
61 analogWrite(LEDR, 255);
62 analogWrite(LEDG, 255);
63 analogWrite(LEDB, 255);
64 }
65}

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.

If all went well, you will see a message like this:

1***** Arduino Cloud - configuration info *****
2Device ID: <your-device-id>
3Thing ID: <your-thing-id>
4MQTT Broker: mqtts-sa.iot.arduino.cc:8883
5WiFi.status(): 0
6Current WiFi Firmware: 1.4.4
7Connected to "<your-network>"
8Connected to Arduino Cloud

If it went wrong, you may encounter errors such as:

1Connection to "<your-network>" failed. Retrying in 500 milliseconds.

Which indicate that something might be wrong with your network credentials.

Step 4: Creating a Dashboard

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.

Create a Dashboard.
Create a Dashboard.

This will open an empty dashboard. At the top left corner, first click on the Pen Symbol. You are now in Edit Mode.

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.

Click on the "Edit button", the pen symbol.
Click on the "Edit button", the pen symbol.
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.

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.

Final look of the dashboard.
Final look of the dashboard.

Expected Outcome

Congratulations. You have now configured your Nano RP2040 Connect board with the Arduino Cloud service.

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.

Control and monitor your Nano RP2040 Connect.
Controlling the RGB on the Nano RP2040 Connect.
Controlling the RGB on the Nano RP2040 Connect.

Conclusion

In this tutorial, we connected a Nano RP2040 Connect board to the Arduino Cloud. We created a simple sketch that allows us to display IMU sensor data directly in the Arduino Cloud dashboard, and how to control the built-in RGB on the board.

More Tutorials

For more interesting tutorials around the IoT Cloud, check out the Arduino Cloud documentation page.

To learn more about the Nano RP2040 Connect board, you can check out the Arduino Nano RP2040 Connect documentation page.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.