Setting up Nano RP2040 Connect with Arduino IoT Cloud

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

Introduction

In this tutorial, we will go through the steps needed to connect the Nano RP2040 Connect to the Arduino IoT 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 IoT 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.

Note: Remember that the pinouts are different on a Nano 33 IoT board. This circuit works for the MKR WiFi 1000/1010 boards.

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

The Arduino IoT Cloud

To start, we will need to head over to the Arduino IoT Cloud. This is also accessible through the menu at the top right.

Navigate to the cloud.
Navigate to the cloud.

Step 1: Setting up the device

1. Once we are in the IoT Cloud, we need to first create a Thing, by clicking on the "Create a Thing" button.

Creating a Thing.
Creating a Thing.

2. Now, we need to configure our device, by clicking on the "Select Device" button.

Select the device.
Select the device.

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.

Click on configure.
Click on configure.

4. Name the board, and click on "Next" which will start a configuration process. Do not disconnect the board during this process.

Choose the name of the board.
Choose the name of the board.

5. After some time, the installation will complete, and your Nano RP2040 is ready for the IoT Cloud.

Installation is successful.
Installation is successful.

Step 2: Creating variables

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.

Click on the "Add Variable" button.
Click on the "Add Variable" button.

We will add variables to control the RGB and to read the Accelerometer.

Variable NameData TypePermission
a_xfloatread only
a_yfloatread only
a_zfloatread only
redbooleanread & write
greenbooleanread & write
bluebooleanread & write

The final overview should look something like this:

The final view.
The final view.

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.

Step 3: Network details

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"

The network section.
The network section.

Then, enter your credentials (network and password). Remember that it is case-sensitive.

Enter the credentials to your network.
Enter the credentials to your network.

Step 4: Creating the program

Now, we need to create the program for our Thing. First, let's head over to the "Sketch" tab in the Arduino IoT Cloud.

Click on the "Sketch" tab to edit the sketch.
Click on the "Sketch" tab to edit the sketch.

The code that is needed can be found in the snippet below. Upload the sketch to the first board.

1
2#include "thingProperties.h"3#include <Arduino_LSM6DSOX.h>4
5void setup() {6  // Initialize serial and wait for port to open:7  pinMode(LEDR, OUTPUT);8  pinMode(LEDG, OUTPUT);9  pinMode(LEDB, OUTPUT);10
11  Serial.begin(9600);12  13  while(!Serial); // Prevents sketch from running until Serial Monitor opens.14
15  if (!IMU.begin()) {16    Serial.println("Failed to initialize IMU!");17    while (1);18  }19  20  delay(1500); 21
22  // Defined in thingProperties.h23  initProperties();24
25  // Connect to Arduino IoT Cloud26  ArduinoCloud.begin(ArduinoIoTPreferredConnection);27  28  /*29     The following function allows you to obtain more information30     related to the state of network and IoT Cloud connection and errors31     the higher number the more granular information you’ll get.32     The default is 0 (only errors).33     Maximum is 434 */35  setDebugMessageLevel(2);36  ArduinoCloud.printDebugInfo();37}38
39void loop() {40  ArduinoCloud.update();41  //reads acceleration42    if (IMU.accelerationAvailable()) {43    IMU.readAcceleration(a_x, a_y, a_z);44    }45    46}47
48
49void onRedChange() {50  if(red){51    digitalWrite(LEDR, HIGH); //turn on RED52  }53  else{54    digitalWrite(LEDR, LOW); //turn off RED55  }56}57
58
59void onGreenChange() {60  if(green){61    digitalWrite(LEDG, HIGH); //turn on GREEN62  }63  else{64    digitalWrite(LEDG, LOW); //turn off GREEN65  }66}67
68
69void onBlueChange() {70  if(blue){71    digitalWrite(LEDB, HIGH); //turn on BLUE72  }73  else{74    digitalWrite(LEDB, LOW); //turn off BLUE75  }76}77

Step 5: Testing the program

After we have successfully uploaded our sketch to our board, we need to initialize the code, by opening the Serial Monitor.

Open the Serial Monitor tab.
Open the Serial Monitor tab.

In this window, we should after a few seconds see information regarding our connection printed.

If the connection (to the network and cloud) is successful, it should print something like the following:

1***** Arduino IoT Cloud - configuration info *****2Device ID: <your-device-id>3Thing ID: <your-thing-id>4MQTT Broker: mqtts-sa.iot.arduino.cc:88835WiFi.status(): 06Current WiFi Firmware: 1.4.47Connected to "<your-network>"8Connected to Arduino IoT Cloud9

This means everything is good, and we can move on the next step: creating a dashboard.

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.

Step 6: Creating the dashboard

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.

Navigate to the Dashboards tab.
Navigate to the Dashboards tab.

Then, we need to click on the "Build dashboard" button.

Click on "Build Dashboard" button.
Click on "Build Dashboard" button.

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.

Click on the "Edit button", the pen symbol.
Click on the "Edit button", the pen symbol.

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.

Adding variables to our dashboard.
Adding variables to our dashboard.

After we click on the button, we be presented with the widget settings window. Just click on the "Done" button at the bottom right.

Click on the done button.
Click on the done button.

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.

Resizing and moving the widgets.
Resizing and moving the widgets.

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.

Step 7: Testing it out

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.

IMU data changing when board is moved.
IMU data changing when board is moved.

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.

Red pixel activated on the Nano RP2040 Connect board.
Red pixel activated on the Nano RP2040 Connect board.

Conclusion

In this tutorial, we connected a Nano RP2040 Connect board to the Arduino IoT Cloud. We created a simple sketch that allows us to display IMU sensor data directly in the Arduino IoT 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 IoT Cloud documentation page.

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

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.