Continuing my journey with the Nano RP2040 Connect, I'll try connecting with and displaying data on the Arduino IoT Cloud.  I'll admit that I don't use the Arduino IoT Cloud much.  I prefer local data processing and storage.  I have an RPi4 dedicated as an always on Home Controller and MQTT server.  The last time I used the Arduino IoT Cloud was with a MKR1010 back in March 2019.  The User Interface is a lot more polished now, but the limits of the Free Plan are still extremely restrictive.  That plan only allows for 5 variables total, so I couldn't even run the example that displayed the accelerometer X,Y,Z axes and controlled the Red,Green,Blue LEDs.  The Entry Level Plan only gets you to 10 variables, so I think to get practical use from this interface you need to subscribe to the Maker Plan ($6.99/month) which gets you unlimited variables.  Another reason I don't use it much.

 

The Arduino IoT Cloud does have some nice features that can help getting an Arduino board online quickly with a nice dashboard.  I have found that the auto generated code feature which generates code templates can actually be somewhat confusing.

 

 

The first step is to add a device.  You can add an Arduino device or a 3rd Party (ESP8266,ESP32,LoRaWan) device.

 

If you add a 3rd Party device, you need to specify the device type.

 

If you add an Arduino device:

  1. You need to have the device connected to your host computer
  2. You need to have the Arduino Create Agent running (it will prompt if the Agent is not found - I start mine manually)
  3. The Arduino devices will be found automatically and you can select the device to configure it

 

 

Configuring the device will allow you to associate a unique name (I named the Nano RP2040 Connect  - "Ralph").  And it will assign the device a unique ID.

 

You can then create a "Thing" which is an IoT Cloud entity that allows you to configure how the device will be used (which sensors, services, etc).  I created a Thing called "Test" that uses the 3-axis Accelerometer data and the Green LED.

The Thing Menu allows you to add Variables via the Setup, add a program via the Sketch, or monitor the Device output on the Serial Monitor.

 

 

 

 

 

 

A Sketch template is autogenerated from the setup and all of the variables are declared, but you need to add specifics to how your program uses the device.  In this case I included the sensor library, the sensor initialization code, and the code to read the sensor data.

 

#include <Arduino_LSM6DSOX.h>

 

// add sensor initialization to setup()

  if (!IMU.begin()) {

    Serial.println("Failed to initialize IMU!");

    while (1);

  }

 

// add read sensor to loop()

  //reads acceleration

    if (IMU.accelerationAvailable()) {

    IMU.readAcceleration(a_x, a_y, a_z);

    }

 

 

Here's the full code listing:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Test"
  https://create.arduino.cc/cloud/things/75942719-181e-4c1e-895d-1419213c9e42 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float a_y;
  float a_z;
  float a_x;
  bool green;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/


#include "thingProperties.h"
#include <Arduino_LSM6DSOX.h>


void setup() {
  pinMode(LEDG, OUTPUT);  
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  //reads acceleration
    if (IMU.accelerationAvailable()) {
    IMU.readAcceleration(a_x, a_y, a_z);
    }
}

void onAXChange() {
  // Do something
  Serial.print("AX: ");
  Serial.println(a_x);
}

void onAYChange() {
  // Do something
  Serial.print("AY: ");
  Serial.println(a_y);  
}

void onAZChange() {
  // Do something
  Serial.print("AZ: ");
  Serial.println(a_z);  
}

void onGreenChange() {
  if(green){
    digitalWrite(LEDG, HIGH); //turn on GREEN
  }
  else{
    digitalWrite(LEDG, LOW); //turn off GREEN
  }
}

 

 

One thing to note is that unless you open the full editor, you won't be able to see the other files that the Sketch is using - most importantly "thingProperties.h" in case something in the setup is incorrect (I have had the automation get stuff screwed up).

 

You can then upload and use the Serial Monitor the same as with the Desktop IDE.  Here is the Serial Monitor Output:

 

The final step is to create a Dashboard to interact with the device.

 

When you build the dashboard you have the choice of selecting a Thing which auto-populates with the specified variables or by selecting your own set of Widgets.

 

 

Here is a Dashboard that was created from my "Test" Thing:

I have it in layout mode which allows you to reposition the widgets.

 

I also wanted to try using other widgets.  Here are the choices in Widget mode:

 

And here is a dashboard that I created to add charts for the acceleration data and a separate display and pushbutton for the green LED.

 

And a quick demo of it working:

 

 

 

There are other useful features of the Arduino IoT Clouds like the ability to synchronize devices and to use other services like IFTTT, but unless I opt to get a more full featured subscription service I probably won't use those.