Hi,
New User here. I'm trying to use a Maker WiFi 1010, Grove Temp Sensor to connect to IoT Cloud and be able to read the output from a dashboard. I have tried combining a sketch for the Grove Temp Sensor (using Math.h) with the sketch for IoT using the Arduino Cloud and following their guidance setting up Device, Thing (Floating), Dashboard.
So Far, I am getting a good output reading when looking at the Serial Monitor when connected by USB cable. I'm not getting a reading on my Dashboard Widget (Value, or Gauge linked to float in code.
I can connect to Cloud over WiFi (at least shows connected).
I imagine I have something missing in coding.
Please see the attached code..
Thank you in advance, for any advice.
#include <math.h>
const int B = 4275; // B value of the thermistor
const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
#if defined(ARDUINO_ARCH_AVR)
#define debug Serial
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#define debug SerialUSB
#else
#define debug Serial
#endif
#include "thingProperties.h"
void setup() {
// Initialize ser
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();
{
int a = analogRead(pinTempSensor);
float R = 1023.0/a-1.0;
R = R0*R;
float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
Serial.print("temperature = ");
Serial.println(temperature);
delay(10000);
}
// Your code here
}
Thing Properties code Below (I intentionally left out wifi SSID and Password for security purposes)
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char SSID[] = ""; // Network SSID (name)
const char PASS[] = ""; // Network password (use for WPA, or use as key for WEP)
float temperatureReading;
void initProperties(){
ArduinoCloud.addProperty(temperatureReading, READ, ON_CHANGE, NULL);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
Okay, thank you for the suggestion. When I tried that...
I received the following error messages...
Start verifying
/tmp/593127569/Temperature_Thing_nov26a/Temperature_Thing_nov26a.ino: In function 'void loop()':
/tmp/593127569/Temperature_Thing_nov26a/Temperature_Thing_nov26a.ino:52:20: error: 'temperature' was not declared in this scope
Serial.println(temperature);
^~~~~~~~~~~
/tmp/593127569/Temperature_Thing_nov26a/Temperature_Thing_nov26a.ino:52:20: note: suggested alternative: 'operator+'
Serial.println(temperature);
^~~~~~~~~~~
operator+
Multiple libraries were found for "SPI.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/samd/1.8.13/libraries/SPI
Not used: /home/builder/opt/libraries/eventethernet_1_0_0
Multiple libraries were found for "WiFiNINA.h"
Used: /home/builder/opt/libraries/wifinina_1_8_14
Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1
Multiple libraries were found for "ArduinoECCX08.h"
Used: /home/builder/opt/libraries/arduinoeccx08_1_3_7
Not used: /home/builder/opt/libraries/rak5814_atecc608a_1_0_0
Error during build: exit status 1
/tmp/593127569/Temperature_Thing_nov26a/Temperature_Thing_nov26a.ino: In function 'void loop()':
/tmp/593127569/Temperature_Thing_nov26a/Temperature_Thing_nov26a.ino:52:20: error: 'temperature' was not declared in this scope
Serial.println(temperature);
^~~~~~~~~~~
/tmp/593127569/Temperature_Thing_nov26a/Temperature_Thing_nov26a.ino:52:20: note: suggested alternative: 'operator+'
Serial.println(temperature);
^~~~~~~~~~~
operator+
Multiple libraries were found for "SPI.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/samd/1.8.13/libraries/SPI
Not used: /home/builder/opt/libraries/eventethernet_1_0_0
Multiple libraries were found for "WiFiNINA.h"
Used: /home/builder/opt/libraries/wifinina_1_8_14
Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1
Multiple libraries were found for "ArduinoECCX08.h"
Used: /home/builder/opt/libraries/arduinoeccx08_1_3_7
Not used: /home/builder/opt/libraries/rak5814_atecc608a_1_0_0
Error during build: exit status 1
Okay, I have tried this now, (please see the attached code). I'm still not seeing the output on a dashboard.
The following variables are automatically generated and updated when changes are made to the Thing
float tMPSensor;
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 <math.h>
int tempPin=A0;
const int B = 4275; // B value of the thermistor
const int R0 = 100000;
#if defined(ARDUINO_ARCH_AVR)
#define debug Serial
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#define debug SerialUSB
#else
#define debug Serial
#endif
void setup() {
Serial.begin(9600);
pinMode(tempPin,OUTPUT);
// Initialize serial and wait for port to open:
// 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() {
int a = analogRead(tempPin);
float R = 1023.0/a-1.0;
R = R0*R;
float tMPSensor = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
ArduinoCloud.update();
Serial.println(tMPSensor);
// Your code here
}
Here are the contents of the thingproperties code...
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
float tMPSensor;
void initProperties(){
ArduinoCloud.addProperty(tMPSensor, READ, ON_CHANGE, NULL);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
Please can you provide more details of the Dashboard that you are using. For instance, what widgets have you put on it, which Thing is it associated with and which Cloud variable are you trying to display the value of ?
Thanks, @UKHeliBob, Widget is a Value, Thing is floating point named temperature, Variable is named temperature also. I have, since, deleted everything, reinstalled the core and libraries in the arduino, deleted everything including all previous versions of devices, things, and dashboards I am using the online sketch editor that comes up when you create the thing. In the auto-generated sketch that comes up, I am adding the variables, setup parameters and loop parameters from a known, working sketch for the Grove Temperature Sensor. I am removing the delays as recommended by Arduino, for IoT sketches. After uploading, I am checking the output at the Serial Monitor. It is giving a temperature reading, confirmation of connection to my existing WiFi connection, then confirming a connection to Arduino IoT Cloud. All looks good. When I go to create a dashboard, I name it, designate it as a value and link it to the thing value float temperature. I am getting a "0" as the value. That is what happens over and over, every time I have tried. I know I am missing something, some parameter or such.
By the way, here is the code. Forgot to include it.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/88391e99-40e4-4bec-8063-95a6d11ca7c7
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float temperature;
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 <math.h>
const int B = 4275; // B value of the thermistor
const int R0 = 100000; // R0 = 100k
const int pinTempSensor = A0; // Grove - Temperature Sensor connect to A0
#if defined(ARDUINO_ARCH_AVR)
#define debug Serial
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#define debug SerialUSB
#else
#define debug Serial
#endif
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// 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();
int a = analogRead(pinTempSensor);
float R = 1023.0/a-1.0;
R = R0*R;
float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet
Serial.print("temperature = ");
Serial.println(temperature);
// Your code here
}
properties folder below
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
float temperature;
void initProperties(){
ArduinoCloud.addProperty(temperature, READ, ON_CHANGE, NULL);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
The Arduino IoT is still largely a mystery to me but I will try to reproduce what you have done, or at least enough of it to display a float as a value on a dashboard
I do not have the same board as you but the principles should be the same
That was easier than I thought it would be. I suggest that you forget about reading the temperature for now and do what I did and create a random value at intervals. If that works then you can add the temperature code
What I did was as follows
Added the Uno R4 WiFi as a device named unoR4, noting the secret key that was created
Added a new "Thing" named thermometer and associated it with the unoR4 device
Added a Cloud float variable named temperature associated with the thermometer "Thing" with Read and Write permissions
Added a dashboard named Thermometer and added a value widget associated with the temperature Cloud variable
The sketch that the IoT system created then looked like this (apart from the loop() function)
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/14986760-0c6e-4fd7-9df8-abb3303b92c4
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float temperature;
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();
temperature = random(100);
delay(2000);
}
/*
Since Temperature is READ_WRITE variable, onTemperatureChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange() {
// Add your code here to act upon Temperature change
}
I added these 2 lines to the loop() function
temperature = random(100);
delay(2000);
The random number that the sketch generates changes every 2 seconds, as expected, and is displayed in the Value widget of the Thermometer dashboard. It could, of course, be a value read from a sensor
Give this process a try and let me know how you get on
Hi, @UKHeliBob, thank you for your response.
I'm a bit confused about the adding to loop bit, because the sketch you submitted already has it included in the loop. Can you clarify if it needs to be in there twice? Here is the sketch I created. And, by the way... it did not work.
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/b6524ba2-9081-4de1-96fd-c5d8e5dad7ce
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float temperature;
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();
temperature=random(100);
delay(2000);
// Your code here
}
/*
Since Temperature is READ_WRITE variable, onTemperatureChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange() {
// Add your code here to act upon Temperature change
}
in loop(). I added the other 2 lines of code to generate a number between 0 and 99 and to assign the value to the temperature variable to simulate reading a temperature every 2 seconds. In summary, the code that I am using is that posted in post #11 and yours is basically the same
I have very little experience in this area but let's try comparing our setups
The settings for the Value widget on my dashboard is as follows
I see where I made a mistake when associating the Widget. I have it working now.
I will see if I can add my code to continue this breakthrough!
If I come back with my head hanging low and tears in my eyes, it is because I, once again am having my posterior handed to me.
Thank you for your help!
Taking into account my lack of knowledge in this area I am glad that it worked. As a matter of interest, what had you done wrong ? I ask, not to embarrass you, but for the benefit of anyone reading this topic in the future who has the same problem.
Now that the basic sketch is working it should not be difficult for you to incorporate reading the actual temperature data into it, then you can experiment with fancy ways of displaying the data on the dashboard
The mistake I had made was when linking the Widget Variable to the temperature. I had no choice (and am seeing the same exact thing now!) to choose the thing rather than the device, in that edit window. I see that when I try my sketch, I don't see a choice other than the device (Arduino) itself. That's a new one to try and figure out.
It looks like you have named the widget Temperature and it is offering you the chance to select a Thing (previously associated with a device) and then a variable previously associated with that Thing. to be used as the value for the widget
One thing that I found confusing was that I was never sure whether I was dealing with a device, a Thing or a variable because I had given them similar names. Once I made notes of what each was called it became easier but I am still not entirely comfortable with the process
It does not help that the sketch refers to your Cloud variables by slightly different names under some circumstances. Something along the lines of naming a variable say ledState only to find out later that the sketch referred to it as LedState
I got it working with my code...
The only thing I did was to go into the loop... if you look at the loop, where had
float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15;
I changed that to ...
temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15;
Then, when I went back through the thing setup process, I had to switch back and forth, from the main editor to the full editor when downloading the code (don't ask me why, lol). after that, I saw the thing showing a live data feed in its setup menu, for the first time. At that point I know it was going to work. This time, when setting up the Widget, i had options t select the proper thing. After that it worked properly.
Yes indeed. One thing I learned is to use distinctive naming whenever possible.
I still have one issue with this Grove Temperature Sensor... I prefer Fahrenheit readings. From the looks of the code, that would be no easy task for a noob such as myself. It mentions a datasheet. ?