1

I uploaded the following to my UNO with WiFi:

#include <SPI.h>
#include <Wire.h>
#include "Adafruit_CCS811.h"
 
Adafruit_CCS811 ccs; // The air quality sensor
 
String Dataline = ""; 
void setup() {
 Wire.begin();
 Serial.begin(115200); 
 Serial.println("SET UP");
}
void loop() {
 // wait a second between measurements.
 delay(1000);
 Dataline = "";
 Dataline = Dataline + getTime();
 Dataline = Dataline + AIRSensor();
 Dataline = Dataline + "...";
 Serial.println(Dataline); 
}
String getTime() {
 String OUT = "Tim::";
 OUT += String(millis());
 return OUT;
}
String AIRSensor() {
 if (ccs.available()) {
 if (!ccs.readData()) {
 float temp = ccs.calculateTemperature();
 String CO2 = (String)ccs.geteCO2();
 return "CO2::" + CO2 +"TAQ::" + (String)temp;
 }
 } else {
 return "CO2::-999,TAQ::-999";
 }
}

The output is simply "SET UP" repeated:

SET UP
SET UP
SET UP
...

It never enters the loop or prints anything else out. Does this mean the UNO is resetting? How do I troubleshoot?

ocrdu
1,7953 gold badges12 silver badges24 bronze badges
asked Jul 21, 2022 at 23:13
1
  • 1
    how do you know that it does not enter loop()? ... you have no code that confirms that Commented Jul 22, 2022 at 0:53

1 Answer 1

3

You can tell that something is going wrong between your println. Some advice in this case: eliminate the String entirely and replace the println with a series of print. This would let you narrow down which function is causing the problem. It also can save some memory, which is a nice bonus in embedded programming.

I suspect in this case the problem is your use of C-style casts to String in AIRSensor(). (String)whatever and String(whatever) do very different things, and the former is not something you want here, or something you should be using very often in C++ code.

The code in loop is running, but it is crashing and causing the hardware to reset. Since it is crashing before it reaches the first visible behavior in loop, it just looks like setup is running over and over.

answered Jul 21, 2022 at 23:36
2
  • Thanks! Changing from '(String)' to 'String()' made a massive difference. It now runs for about 6 loops, and then stops for a while. In the IDE, I get a 'Error while setting serial port parameters: 115,200 N 8 1' message. It then restarts again. Is there any way to stop that? Commented Jul 21, 2022 at 23:42
  • 'twas an issue with me not using 'ccs.begin()'. Thank you for your help!! Commented Jul 22, 2022 at 1:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.