Pages: [1]   Go Down
Author Topic: Problems with serial.print  (Read 708 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I have this code.

Code:
int sum=0;
int b=20;

void setup() {
 Serial.begin(9600);
 
}


void loop() {
  sum = sum + b;
 
 
  if (sum==800) {
   sum=0;
  }
 

    Serial.println(sum);
    delay(1000);

 
}

So I upload the code, start the serial monitor and I can see 20, 40, 60 etc.
I disconnect the serial monitor and connect again a couple of seconds later. I expect 240, 260, 280. But I can see it starts from the beginning with 20, 40 .... When I'm online with the serial monitor it works as expected.
Maybe anyone can tell me why?

thx in adavance
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24370
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connection resets the Arduino.
You can disable this with a simple mod - check your board's documentation.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Chile
Offline Offline
Edison Member
*
Karma: 32
Posts: 1233
Arduino rocks?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I modded the serial dll used for the com port enumeration, so you can use http://arduino.cc/forum/index.php/topic,118440.0.html to avoid disconnections when opening the arduino.
Logged

My website: http://ried.cl

India
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Induino X is awesome!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the difference between serial.print and serial.printin ?
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Println adds a linefeed at the end of the printed text so the next print will be on a new line.

-br
Logged

Virginia
Offline Offline
Newbie
*
Karma: 1
Posts: 8
powerfully insane
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the difference between serial.print and serial.printin ?

Note that it is println (with a lower-case L) and not printin (with a lower-case I).
Logged

Pages: [1]   Go Up
Jump to: