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,795
  • 3
  • 12
  • 24
user1505631
  • 121
  • 4

1 Answers1

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.

Chris
  • 144
  • 3