Including SD card Library Causes Serial Monitor to Output Random Text

Hello, I have a problem with code and I cannot figure out what is wrong. I was working on a simple cycle testing software for motors (using relays) and it works pretty well. I can specify on/off time, with repeating cycles. I can stop the cycle while it is happening as well. I'm not very good at coding arduino, let alone anything so I appreciate the help in advance.

Now I plan to add a hall effect sensor to my setup so that I can get RPM data and datalog it. My issue here is that when I include the SD card library, my serial monitor goes nuts. If I use sample sketches from arduino, the sd card works fine and data is logged.

But once I try to use the library in my code is goes nuts. I haven't even entered any code that uses the SD card, only "#include <SD.h>" which is enough to make it go crazy. I have attached my code below.

If I include the sd library in my code, the serial monitor looks like this
"-----Motor CYCLE SUMMARY-----

110001000201

Total Motor Cycle Time(S) : 7.00

--------- MAIN MENU --------

1 - Add new Motor sequence
2 - Remove Motor sequence
3 - Modify Motor sequence
4 - Execute Motor Cycle


Enter Selection: 4

110001000201
7.00n: 4

110001000201
7.00n: 4
110001000201
7
4
110001000201
76
0201
7

Post continued below:

All those random numbers don't belong. While if I do not include the library my output is nice and clean:
"-----Motor CYCLE SUMMARY-----

SEQUENCE 1 ON TIME: 1000 | OFF TIME: 1000 | REPEAT: 2 | DELAY: 0 | Motor Selection(s): Motor(s) 1

Total Motor Cycle Time(S) : 7.00

--------- MAIN MENU --------

1 - Add new Motor sequence
2 - Remove Motor sequence
3 - Modify Motor sequence
4 - Execute Motor Cycle


Enter Selection: 4
Motor Sequencing Tool
Motor Cycle Sequence Execution:

SEQUENCE 1 ON TIME: 1000 | OFF TIME: 1000 | REPEAT: 2 | DELAY: 0 | Motor Selection(s): Motor(s) 1

(During Motor cycle, press any key to cancel)

Total Motor Test Cycle Time(S) : 7.00

PRESS ANY KEY TO EXECUTE:

Interval(ms):

Motor state:
1000|ON|1000|OFF|1000|ON|1000|OFF|1000|ON|1000|OFF|0|OFF|1000|OFF|Motor Sequencing Tool
"

My code seems to be too long to post ( it exceeds the character limit.)

If there is a way to do so please advise.

Thanks

PS: Here is a link to my code on pastebin

I don't see any code. The SD card uses more than half the RAM an UNO has for block buffering. So you have to take care for the rest of the memory. Probably you use too much of it for print() calls, where you can eliminate RAM usage by using the F() macro.

pylon:
I don't see any code. The SD card uses more than half the RAM an UNO has for block buffering. So you have to take care for the rest of the memory. Probably you use too much of it for print() calls, where you can eliminate RAM usage by using the F() macro.

That makes a lot of sense. My code is too long to post as a reply, so I uploaded it to paste bin.

Hmm I will revise my print() calls, I thought it could have been a memory issue.

Replace all print() and println() calls with constant strings, p.e.

Serial.print("This is the constant string");

with a call that uses the F() macro:

Serial.print(F("This is the constant string"));

This will save you a lot of memory but I don't know if that's enough.

You could use the attachment function of the forum to post code that is larger than the allowed character count of the text input field. Just click on "Additional Options..." below the text entry.

pylon:
Replace all print() and println() calls with constant strings, p.e.

Serial.print("This is the constant string");

with a call that uses the F() macro:

Serial.print(F("This is the constant string"));

This will save you a lot of memory but I don't know if that's enough.

You could use the attachment function of the forum to post code that is larger than the allowed character count of the text input field. Just click on "Additional Options..." below the text entry.

Thank you! I will try that shortly.

MenuBasedCycleTest.ino (12.9 KB)