Pages: [1]   Go Down
Author Topic: trouble with Serial.print Arduino Mega  (Read 336 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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.
« Last Edit: May 27, 2013, 04:15:22 pm by Coding Badly » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12744
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

 Serial.print("Stato Sorgente ... =>");

...to this...

 Serial.print( F( "Stato Sorgente ... =>" ) );

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

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: