Really strange error - defies logic (for me anyway)

I have a really strange problem where this program does not work in so much as it does not print out to the serial monitor - just blank, no debug. I can not explain it and it is so simple.

#include <Average.h>
#include <SoftwareSerial.h>

#define NUMREADS 200
#define TESTREADS 100
#define DEVREADS 100

//average arrays
Average sensorvalues(DEVREADS);
Average distavg(NUMREADS);
Average testsample(TESTREADS);

void setup() {
Serial.begin(115200);
}

void loop() {
Serial.println(“test”);
delay(1000);
}

The really strange thing is, if I comment out the 3rd Average declaration, it works.

ie

Average sensorvalues(DEVREADS);
Average distavg(NUMREADS);
//Average testsample(TESTREADS);

alternatively if I comment out the line, #include <SoftwareSerial.h>, it also works. However I need this for defining other serial output devices.

I can see no logical reason for this.

Can someone please help and spot the error? :confused:

I am running Arduino 1.6.5-r5

I do not know the implementation of the Average class, however if it is creating storage for NUMREADS+DEVREADS+TESTREADS worth of floats, you will simply be chewing up all your memory.

Removing the include will also free up the memory otherwise used by the TX/RX buffers.

Of course this is just a guess, as I do not have all the code.

The error is probably your approach to use more memory than is availabe. You are creating array of 400 floats (1600 bytes), a lot of memory from your available 2k(?)...

You did not bother to tell us the type of your arduino, but from the symptoms it could be a 'heap meets stack' arrangement.

OP: Please read the two posts by Nick Gammon at the top of this Forum, especially the use of code tags when listing source code here.

Hi I do get TEST on the serial monitor if the NUMREADS define is reduced to 190 :

#define NUMREADS 190 
#define TESTREADS 100
#define DEVREADS 100

defining NUMREADS @ 195 causes no output on the serial monitor...

  • dan

You are simply trying to use more RAM memory than is available. When you do that, there is no predicting what types of errors you'll see.

I recommend you either reduce the RAM consumption considerably or consider moving to a processor with more RAM.