06/14/2023
How-to | MauroRiboniMX | Nov 2, 2022

Use Arduino Nicla Sense ME together with ctrlX AUTOMATION for data harvesting

Disclaimer

This procedure is not addressed to the basic user, in order to fully understand what is happening and to debug the setup it is necessary to have a good knowledge about Arduino environment. Furthermore the document is not a complete setup to a production case.

Dealing with Arduino takes many advantages but also some challenges in an industrial setup:

  • It's not easy powering it
  • It's not easy to veiculate data
  • The user must be able to create (or buy) some "enclosure" to protect it

Coming to ctrlX AUTOMATION it could be the swiss pocket knife and could easily solve the first two problems in many common cases. How? ctrlX AUTOMATION can provide power using the USB port. The data can be easily obtained using the Arduino serial port over USB and managed with Node-Red.

Requirements 

Here we have the scheme of what we need:

ctrlX Arduino scheme

Equipment used:

The test has been done with:

 

Step-by-Step guide

Step 1 - Create your Arduino script

The first step is to create a suitable arduino script. The best way is to start from Nicla-Sense-Me: Getting-Started and follow all the main steps to setup the Arduino and Nicla's environment on the PC. We're going to use also the ArduinoJson library so this must be also installed inside the Arduino Environment: ArduinoJson. 

The easiest way is to start from the Arduino standalone example and modify it including the Json streaming functionality:

Create Arduino script

Let's review together the example shown here. 

In the first part of the script we have to:

  • Include the necessary libraries
  • Create a Json document reserving some space
  • Define an Arbitrary object ID
  • Define the sensor instances.

Setup json script

Initialization: we're using the standard Arduino setup function to start the serial interface with 115200 baud as speed and starting the sensors. 

Arduino setup function

Runtime: we're just running constantly the sensor update and calling every 100 milliseconds the streamerSerialJson function. 

Constant sensor update

streamerSerialJson: this function uses the Json Library to: 

  • Clean any time the document
  • Pack in his structure the measurements and the ObjectID
  • Serialize the json string over serial
  • Send the "/n" character to terminate the message

Stream serial json

The serial port output would look like this: 

Serial plotter output

The data are well organazied in a Json and there is the id of the object which is sending the measurements.

Opening the serial plotter it's possible to see an overview of what the board is sampling: 

Serial plotter

 

Step 2 - Retrieve data with node-red

To get the data from the Nicla board we need to setup a "serial in" block with the following setting: any time we receive a "\n" the input is splitted and provided as a string.

ge

Get data from Nicla board

Once the data are inside ctrlX CORE the trick is done! Using the json object we can easily convert the string into a json object and manipulate the data. 

String into json object


The Company 

Arduino is the leading open-source hardware and software company in the world. Born to provide an easy-to-use platform for anyone making interactive projects, Arduino has reached a growing community and adapted to new needs and challenges, branching out into products for IoT, wearables, 3D printing, and embedded environments. As of today, the Arduino community includes approximately 30 million active users.

With the Pro Business Unit, Arduino caters to companies that are interested in going beyond the concept and rapid prototyping phase, to start mass production with the support of a qualified industrial partner and high-performance technological solutions.

 

2

Latest published/updated articles

Types
How-to
Categories
IOT