Serial garble at beginning of output.

Hi all, I have a question regarding this wierd snippet of serial output from the arduino at the beginning, and how I can eliminate it… i’m using IR detection data, sending it via serial to a python program, which writes it to a .txt.

This is my code…

int emitter = 2;
int LED = 13;
int detector[] = {3,4};

void setup(){
  pinMode(LED, OUTPUT);
  pinMode(emitter, OUTPUT);
  for (int index = 0; index < 2; index++)
  {
    pinMode(detector[index], INPUT);
  }
  Serial.begin(9600);
  delay(500);
  Serial.println("start");
  delay(2000);
}

void loop(){
  digitalWrite(emitter, HIGH);
  digitalWrite(LED, HIGH);
  for (int x = 0; x < 2; x++) 
  {
    int y = digitalRead(detector[x]);
    Serial.print(detector[x]);
    Serial.print(y);
    Serial.print(":");
  }
    
//  int x = digitalRead(detector);
  Serial.println(millis());
}

…and it outputs this to serial monitor:

88
00:40:3723
30:40:3736
30:611
30:40:3623
30:40:3636
30:40:3648
30:40:3660
30:40:3674
30:40:3686
30:40:3698
30:40:3710
30:40:3723
30:40:3736
30:4start
31:40:510
30:40:522
30:40:533
30:40:545
30:40:557
30:40:568
30:40:579
30:40:590
30:40:602
30:40:614
30:40:625
30:40:636
30:40:648

Anything not underlined shouldn’t be there… is it a hardware issue, software coding issue? I’m new at this, any help would be awesome!

I'm guessing there's spillover from a previous run... but how can i rid myself of it?

This is my code...

No, this is garbage. Revise your initial post, and use the code button (with the # symbol), not the quote button.

thanks, i'm new :)

What OS are you using? Have you modified the Arduino to not reset when the Serial Monitor is opened?

I took your code bit and compiled it for a Uno under ide 021 and it worked fine. I realize you've been trying to find a problem and cutting and shaping code so I won't point out the little problems here and there, but it worked.

I saw what you're getting when I hit the reset button on the Arduino and also when I killed the serial window and restarted it. What you're probably seeing is stuff that was coming in already and just hadn't gotten there yet. If you want to see it like I did, upload it, then start the serial window so it starts off fresh. This is pretty common in my experience when you're sending data to the serial out and start up the serial window. It gets a burst of junk from the previous run. Put a couple of Serial.println(); lines in before you print start to show the separation and have fun.

What Arduino variant are you using?

It doesn't look garbled to me. It's just the output from an earlier test. Close the serial monitor and open it again and it should start afresh.

You could also do something like:

Serial.println ();
delay (5);
Serial.println ();
Serial.println ("start");
Serial.println ();

And get your Python program to look for the word "start". It is a bit of a characteristic of serial comms that the transition from random line noise to valid data may look like a character or two.

Hi, Arduino Uno, no disabled auto-reset.

Thank you PaulS, Nick, James, and draythomp!

You're right... if i unplug the usb cable from the arduino, replug it in... the junk data from the previous run doesn't transfer in... so I guess that extra data in the beginning is just due to the prior run.

I'll just accept it and sort it in python by looking for a "start" in the text string as suggested.

Thank you guys!

For what it is worth, the 8u2's RESET isn't connected to the ATmega328's RESET. Sounds like the data is stuck in a buffer on the 8u2.

Now, go edit the first post and add [Solved] to the subject line ]:D

tee hee.