Hey community,
I have created a Thing via the Arduino IoT Cloud. The functionality is quite simple reading 4 digital inputs and 8 analog inputs via 2 ADS1115 shields. And I used the onboard LED as an indicator of the connection status.
/*
Sketch generated by the Arduino IoT Cloud Thing "WRS_02"
https://create.arduino.cc/cloud/things/d3ea9840-3359-4981-9ceb-ff7f3adb3457
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float analogIn_1;
float analogIn_2;
float analogIn_3;
float analogIn_4;
float analogIn_5;
float analogIn_6;
float analogIn_7;
float analogIn_8;
bool digitalIn_1;
bool digitalIn_2;
bool digitalIn_3;
bool digitalIn_4;
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"
// Nanoshield 4-20mA library (zip download)
#include <Wire.h>
#include <Nanoshield_ADC.h>
// definition for Nanoshield 4-20mA
Nanoshield_ADC adc0= {0x48}, adc1= {0x49};
int channel_1 = 0;
int channel_2 = 1;
int channel_3 = 2;
int channel_4 = 3;
// defintion for digital I/O
int DigitalInPin_1 = 0;
int DigitalInPin_2 = 1;
int DigitalInPin_3 = 2;
int DigitalInPin_4 = 3;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
//Initialize Nanoshields
adc0.begin();
adc1.begin();
// Adjust gain to two (2.048V range) to get maximum resolution for 4-20mA range
adc0.setGain(GAIN_TWO);
adc1.setGain(GAIN_TWO);
//Initialize LED on Board
pinMode(LED_BUILTIN, OUTPUT);
// define digitalIn
pinMode(DigitalInPin_1,INPUT_PULLUP);
pinMode(DigitalInPin_2,INPUT_PULLUP);
pinMode(DigitalInPin_3,INPUT_PULLUP);
pinMode(DigitalInPin_4,INPUT_PULLUP);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// 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();
// Your code here
AnalogRead();
DigitalRead();
statusLED();
}
void AnalogRead () {
// read analogIn Nanoshield #1
analogIn_1 = adc0.read4to20mA(channel_1);
analogIn_2 = adc0.read4to20mA(channel_2);
analogIn_3 = adc0.read4to20mA(channel_3);
analogIn_4 = adc0.read4to20mA(channel_4);
// read analogIn Nanoshield #2
analogIn_5 = adc1.read4to20mA(channel_1);
analogIn_6 = adc1.read4to20mA(channel_2);
analogIn_7 = adc1.read4to20mA(channel_3);
analogIn_8 = adc1.read4to20mA(channel_4);
}
void statusLED (){
if (ArduinoCloud.connected() == 1) {
digitalWrite(LED_BUILTIN,HIGH);
} else {
digitalWrite(LED_BUILTIN,LOW);
}
}
void DigitalRead () {
// read digitalIn_1
if (digitalRead(DigitalInPin_1) == LOW){
digitalIn_1 = true;
} else {
digitalIn_1 = false;
}
// read digitalIn_2
if (digitalRead(DigitalInPin_2) == LOW){
digitalIn_2 = true;
} else {
digitalIn_2 = false;
}
// read digitalIn_3
if (digitalRead(DigitalInPin_3) == LOW){
digitalIn_3 = true;
} else {
digitalIn_3 = false;
}
// read digitalIn_4
if (digitalRead(DigitalInPin_4) == LOW){
digitalIn_4 = true;
} else {
digitalIn_4 = false;
}
}
I configured all Variables as read only and periodically each 60s. (all done in the Arduino Cloud with the auto code generation)
The sketch is perfectly running on my Arduino MKR WIFI1010, connection is stable and Variables are updated as expected every 60s to the IoT cloud.
BUT as soon as I attach my Arduino MKR GSM1400 to this Thing and run the identical Sketch I do not get a stable connection to the IoT cloud (Device online for 2-3 sec on Arduino IoT cloud) and the variables are not getting synchronised.
The Arduino MKR GSM1400 is working in general. I tested this with a simpler version of the Sketch. With this Sketch the MKR GSM1400 is having a stable connection. So based on this I assume it is no basic power supply issue or hardware/SIM (also tried Arduino SIM and ThingsMobile SIM).
/*
Sketch generated by the Arduino IoT Cloud Thing "WRS_TEST"
https://create.arduino.cc/cloud/things/1b8525e5-1b86-4ca2-8d42-ae0bcee9a5f0
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
bool test;
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"
void setup() {
// 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);
// 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();
// Your code here
statusLED();
}
void statusLED (){
if (ArduinoCloud.connected() == 1) {
digitalWrite(LED_BUILTIN,HIGH);
} else {
digitalWrite(LED_BUILTIN,LOW);
}
}
My best guess at the moment is, that the Arduino MKR GSM1400 has a problem with the amount of variables. Since if I reduce the number of variables I get a stable connection.
It's my first post after I was searching a while in the forum but did not find a related topic. So I hope to get some constructive feedback to identify the root cause of my problem.
Many thanks in advance!