Data Logger will not log mv or percent

I am using a Mega 2560 with a micro SD card logger and a RTC. I have snipped two programs from the internet. One is for the RTC and the other is for the data logger. I have married these tow for my sketch to run my program.
These two programs seem to work well except the data logger will not record the "mv" or "percent" value. Only 0 0 is recorded after the date and time. See attached PDFs. I have attached my code.
I would appreciate and help in figuring out why I cannot data log the "mv" and "percent" values.
I am using an external +5 high on Pin 7 to request the the moment for the data logger to record the date, time, mv and percent.

I added a println command for mv and percent. As you can see on one of the PDFs img_4508 the mv and percent are indeed printed line by line, but no in the data logger line showing date, time and again 0 0 for mv and percent.

I would appreciate any help or suggestions to point me in the right direction for fix this issue.

Thank all of you.

IMG_4507.JPG

IMG_4508.JPG

IMG_4507.JPG

IMG_4508.JPG

RTC_W_DATA_Logger_Sketch3_ Mega.pdf (65.3 KB)

Can you post the INO file please - I'm NOT going to download a pdf, open it, make sure it's virus free and then copy the code to my IDE.

Here you go.

KnauerRTC_w_DATA_Logger_sketch3_Mega.ino (13 KB)

You have const variables at the top, you then create LOCAL variables with the same name in your code.

Don't make VARIABLEs const, this makes them read only. DONT create variables inside code with the same name as you may confise yourself as to what variable you are updating.

Put declared variables at top.
int mv = 0;
int percent = 0;
int Year, Month, Day, Hour, Minute;

Eliminated this in Setup.
//int year, month, day, hour, minute, second, mv, percent;
Still prints 0 0 in datalogger.

Try again

KnauerRTC_w_DATA_Logger_sketch3_Mega.ino (13 KB)

Same problem. You have multiple mv variables declared. The one that gets a value (the float) goes out of scope before you use it so you print the global one (int) which is always zero.

So how should I change my code? Please advise. Thank you.

JerryHawkins:
So how should I change my code? Please advise. Thank you.

Use the "find" search tool for each variable that you've defined that is giving problem output (like the zeros you are complaining about...). You will be able to see the duplicate definitions. Delete either the global one, if it's not used elsewhere, or edit the local ones to remove the declaration, e.g.

'int someInteger = 1;'

becomes

'someInteger = 1;'

Spend some time on it, don't just flounder for 5 minutes and come back here immediately. Go research, "C/C++ variable scope".

I have been working on this issue for a week with no clear fix.

You have clearly been told how to fix it multiple times.

READ the responses, UNDERSTAND the information given, APPLY the knowledge

Please see picture of Serial Monitor with #define ECHO_TO_FILE 1
#define ECHO_TO_SERIAL 0 and #define ECHO_TO_FILE 1
#define ECHO_TO_SERIAL 1.

So the serial monitor will print v and percent, but the Data Logger only shows 0 0 again.

Very frustrating. I have been on this for hours.

Any help would be appreciated.

IMG_4510.JPG

IMG_4511.JPG

IMG_4510.JPG

IMG_4511.JPG

KnauerRTC_w_DATA_Logger_sketch3_Mega.ino (12.9 KB)

I'll open the INO file but if I find you have not follower the explicit instruction given to you, this will be my last reply.

You have done NOTHING as shown - I'm out. GOODBYE

PS - only had to change 4 lines, and add 1 (and remove the LCD stuff for testing) and it worked.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.