S
S
slickstars2015-10-04 19:19:02
Arduino
slickstars, 2015-10-04 19:19:02

Why does Serial stop working in Arduino?

Hello everyone, I have such a problem - for some reason, after continuously sending messages using Serial.print, sending stops working after a while, I wrote a simple test program:

int time = 0;
int count = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("test");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(11);
  if(millis() > time) {
    count++;
    Serial.println(count);
    time = millis() + 1000;
  }
}

At 33 times always, the output stops (I look through the standard monitor), does anyone know what's the matter here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Gusev, 2015-10-04
@slickstars

Sorry, I lied to you a little, it's in the int, hike.
Make numbers the same size as millis() and everything will be fine)
unsigned long time = 0;
unsigned long count = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("test");
}
void loop() {
// put your main code here, to run repeatedly:
delay(11);
if(millis() > time) {
count++;
Serial println(count);
Serial println(millis());
Serial println(time);
time = millis() + 1000;
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question