Go Down

Topic: trouble with Serial.print Arduino Mega (Read 454 times) previous topic - next topic

codicealpha

May 27, 2013, 10:57 pm Last Edit: May 27, 2013, 11:15 pm by Coding Badly Reason: 1
I have a problem with serial port of Arduino MEGA 2560 r3.
I am writing a program with Arduino to control a heater and boiler.
Inputs are a series of sensors and outputs are relay for control electrical-valves.
I have a buttons, LEDs and a display with 3 lines for the user.

The size of the project is 68kb. Arrived at a certain stage of development, I started to have problems.
The serial crashes without a reason, does not print anything.
Sometimes re-opening the serial monitor can solve, sometimes it freezes the Arduino completely.

Thinking it was a problem of program length, I have included only Serial.print and "harmless" code up to 135kb of total program without having problems.

I tried to remove and set the parameters pre-processor, without changes.

It appears, in particular, that it is this portion of code that cause problems:

Code: [Select]
#ifdef PRM
   if ((CaminoAcc) && (bitRead(StatoSrg,0) == 0))
      { Serial.print("Stato Sorgente ... =>"); Serial.print("Camino Acceso gr. "); Serial.println(Temp_Camino); bitSet
(StatoSrg,0); }
   if (CaminoAcc == false) bitClear(StatoSrg,0);
   if ((CaminoSpe) && (bitRead(StatoSrg,1) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Camino Spento gr. "); Serial.println(Temp_Camino); bitSet
(StatoSrg,1); }
   if (CaminoSpe == false) bitClear(StatoSrg,1);
   if ((CaminoInAcc) && (bitRead(StatoSrg,2) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Camino In Accens. gr. "); Serial.println(Temp_Camino);
bitSet(StatoSrg,2); }
   if (CaminoInAcc == false) bitClear(StatoSrg,2);
   if ((CaminoInSpe) && (bitRead(StatoSrg,3) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Camino In Spegnim. gr. "); Serial.println(Temp_Camino);
bitSet(StatoSrg,3); }
   if (CaminoInSpe == false) bitClear(StatoSrg,3);
 
 
   if ((StufaAcc) && (bitRead(StatoSrg,4) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Stufa Accesa gr. "); Serial.println(Temp_Stufa); bitSet
(StatoSrg,4); }
   if (StufaAcc == false) bitClear(StatoSrg,4);
   if ((StufaSpe) && (bitRead(StatoSrg,5) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Stufa Spenta  gr. "); Serial.println(Temp_Stufa); bitSet
(StatoSrg,5); }
   if (StufaSpe == false) bitClear(StatoSrg,5);
   if ((StufaInAcc) && (bitRead(StatoSrg,6) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Stufa In Accens.  gr. "); Serial.println(Temp_Stufa);
bitSet(StatoSrg,6); }
   if (StufaInAcc == false) bitClear(StatoSrg,6);
   if ((StufaInSpe) && (bitRead(StatoSrg,7) == 0))
       { Serial.print("Stato Sorgente ... =>"); Serial.print("Stufa In Spegnim.  gr. "); Serial.println(Temp_Stufa);
bitSet(StatoSrg,7); }
   if (StufaInSpe == false) bitClear(StatoSrg,7);
 
   if ((CaminoInAcc || CaminoInSpe)) { Serial.print("Temperatura Camino ..... "); Serial.println(Temp_Camino); }
   if ((StufaInAcc || StufaInSpe)) { Serial.print("Temperatura Stufa ..... "); Serial.println(Temp_Stufa); }
 #endif


Thanks to those who can help me!
Bye!


Moderator edit: [code] [/code] tags added.

Coding Badly


Add a call to the F-macro for all of your print calls.  In other words, change this...

[font=Courier New]  Serial.print("Stato Sorgente ... =>");[/font]

...to this...

[font=Courier New]  Serial.print( F( "Stato Sorgente ... =>" ) );[/font]

...and repeat for all of the calls to Serial.print with a string constant.

codicealpha

thank you so much for the answer!
I think you've solved the problem.. thanks!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy