ArduinoPro BoschRexroth HowTo Image.png

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

JulianWorld
Long-established Member
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 schemectrlX 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 scriptCreate 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 scriptSetup 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 functionArduino setup function

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

Constant sensor updateConstant 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 jsonStream serial json

The serial port output would look like this: 

Serial plotter outputSerial 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 plotterSerial 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.

geGet data from Nicla boardGet 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 objectString 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.

Logo-Arduino-Pro-complete-stacked-black.png

 

4 Comments
tszalkai
Member

Hello,

This demo works for me up until I connect the Nicla Sense to my core and try to configure the serial port under Node-Red. I am getting the following error:

"[serialconfig:f41e2238230bf685] serial port /dev/ttyUSB0 error: Error: Error: No such file or directory, cannot open /dev/ttyUSB0"

The sensor is connected to the core. The Json script is being displayed properly on my PC's IDE serial monitor. Please advise.

Sgilk
Contributor

@tszalkai ,

It looks like in this case, the device is detected as ACM. /dev/ttyACM0

tszalkai
Member

That one does not seem to work either.

tszalkai
Member

I had some cable isses, it works now!

Must Read
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist