Serial.print() Boolean Variable displays 52,51,54,...

I have a code that is functional but with low memory warning on a UNO :

Global variables use 1636 bytes (79%) of dynamic memory, leaving 412 bytes for local variables. Maximum is 2048 bytes. Low memory available, stability problems may occur.

These are libraries I use :
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <phi_interfaces.h>
#include <Wire.h>
#include <SdFat.h>
#include “RunningAverage.h”

And these are the global variables :

byte prevSecond, second, minute, hour, dayOfWeek, dayOfMonth, month, year;
char clockStringNow[17];
char tempchar[5];
char Yr_Array[5];
char Mo_Array[5];
char Dt_Array[5];
char Hr_Array[5];
char Mi_Array[5];
char CurLoc, NCurLoc;
boolean RTC_Set_Gate, RTC_Set_Gate01 = 1, RTC_Set_Gate02 = 0, homeDispGate = 1, setClockBit ;
boolean beginLogGate = 1, fileChooseGate, newFileGate, oldFileGate, dumpDataGate ;
boolean eraseConfGate, doLoggingGate, logSwitchGate, waitOnSerGate, sendDataGate;

const byte logOnSw = 5;
const byte scan_LED = 6;
const byte logging_LED = 7;
const byte lowBatt_LED = 8;
const byte SDCselect = 10;
const byte cardDetect = 9;
const int lm35Pin = 0; // Analog pin to use.

char LCDmsg[17];
char dataToLog[20];
unsigned long scanMs = millis();
unsigned int loopInterval = 100;
unsigned long logMs = millis();
unsigned int loggingInterval = 5; // Enter the interval in second
int setClockCount ;

char validDIN = ‘0’;
char userRequest;

int RA_SampleSize = 20;
long Val_00 = 0; // Variable to hold raw AI data
float analog_Ch0Val, tempDegC;
int battVolts ;
char tem;
char buffer[10];

I have made sure to store all lcd messages in Flash area with the lcd.print(F());

Though the code is executing ( its a single channel datalogger that writes to the SD card once every five seconds one channel value) I have a problem with a boolean variable " dumpDataGate " that seems to be loaded with a value like 52, 53, 56, 57 54 when i check with Serial.print(dumpDataGate);

How it this ( boolean holding a value other than 0 or 1 ) possible and can low memory lead to these kind of issues ?

( I can post the whole code but it will exceed the forum limit)

If you want help with problematic code, don't you think we need to see the problematic code?

You can post the whole code as an attachment.
Without seeing this, however, I could imagine that the output you are seeing is something like the ascii value of the boolean "TRUE" in hex.
54 52 55 45

But true is spelled in lower-case, as any fule kno

I thought it was too good to be TRUE (true) but it's all wild speculation until we see that code.

6v6gt:
I thought it was too good to be TRUE (true) but it's all wild speculation until we see that code.

:smiley:

AWOL:
If you want help with problematic code, don’t you think we need to see the problematic code?

Sure. For a person like me for whom Arduino is a interesting hobby, the code was looking long … so was a bit shy of posting it full !! You will see the RTC update routine really a torturous one… now i wonder how i wrote that !! For you experts this code will be a small one i guess.

Anyway no better way to learn than by being subject to comments. So i have attached the full code herewith as a Zip file. Incidentally this is functionally checked out to be OK … except for the Boolean issue. I had originally used the Boolean like this …

if(dumpDataGate)
{
…do something…
}

And i found the code was entering the above segment when for sure dumpDataGate was low. So if you see the code i have over come the problem by bringing in one variable to negate this …
if ( dumpDataGate && dispHomeGate == 0 )

{
…do something …
}

And since the whole code is posted, would be happy to know if there is way to a avoid the low memory warning. This is going to be a fun week end !!

TempLogger.zip (7.13 KB)

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easy to read.

Please attach .ino or jpg, png, or .zip files,

Have you got any code running on the UNO?

Thanks... Tom.. :slight_smile:

I can't look at your code now; using a cell phone.

How it this ( boolean holding a value other than 0 or 1 ) possible and can low memory lead to these kind of issues ?

A boolean is stored in a byte. When you overwrite that byte, printing it will print that value.

Possible reasons for overwriting are
1)
writing outside the boundaries of an array
2)
stack corruption due to low memory

TomGeorge:
Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easy to read.

Please attach .ino or jpg, png, or .zip files,

Have you got any code running on the UNO?

Thanks… Tom… :slight_smile:

No harm in brushing the basics… Thanks.

My code as a zip attachment was in response to a friend who suggested to post so.

Any code running on UNO…hmmm… well that ZIP file has one of those.

Now that I had posted the full code as a zip file could anyone go through it ... of course time permitting!
I do understand that forum responses are purely on a sharing basis and it’s difficult to run through lengthy codes in “ mental debug “ mode.

One of the reasons why I fight shy of postinglong codes as they are. Better would be shorten and remove the bells and whistles and post the problem area. But for that it needs time .... and also at times the removed portion may be the culprit.

Would be happy to get some feedback on the code and of any blooper is lurking.

Thanks.

I would check very carefully all your array statments and make sure that you are not overwriting any boundaries.

For example its hard to know how many blank spaces you have here. If there are three, and sprintf is adding a null you are going out of bounds.

char LCDmsg[17];
sprintf ( LCDmsg, "%c%c:%c%c:%c%c:%c%c:%c%c   ", Yr_Array[2], Yr_Array[3], Mo_Array[2], Mo_Array[3], Dt_Array[2], Dt_Array[3], Hr_Array[2], Hr_Array[3], Mi_Array[2], Mi_Array[3]);

@cattledog

Yes that’s a good pointer. This array assignment for char has really given sleepless nights when bound is exceeded and the worst is the warning is not flagged.

Will sure look into all the char arrays to make sure there is enough space.

Thanks

For example its hard to know how many blank spaces you have here. If there are three, and sprintf is adding a null you are going out of bounds.

I highlighted the middle one. There ARE three. With the 10 %c’s and 4 colons, that’s 17 characters, plus the terminating NULL, trying to be shoe-horned into a 17 element array.

Thanks Paul. Let me work on this once I lay my hands on the hardware - right now my friend is using it for set up trials. So far its holding up and i am not really sure when the bug will rear its ugly head !! ( He has been warned though !)