element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Projects
  • Products
  • Arduino
  • Arduino Projects
  • More
  • Cancel
Arduino Projects
Blog Nano RP2040 Connect with Arduino IoT Cloud
  • Blog
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 2 Jun 2021 3:43 PM Date Created
  • Views 2103 views
  • Likes 8 likes
  • Comments 0 comments
  • arduino iot cloud
  • arduino nano rp2040 connect
  • imu
  • rp2040
  • arduino web ide
Related
Recommended

Nano RP2040 Connect with Arduino IoT Cloud

ralphjy
ralphjy
2 Jun 2021

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.

image

 

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.

 

image

 

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

image

 

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

image

 

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

 

image

image

image

 

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.

image

image

 

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.

image

 

 

image

 

 

image

 

 

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).

image

 

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

image

 

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

image

 

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.

  image

 

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

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

image

 

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

image

 

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.

image

 

And a quick demo of it working:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

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.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube