Arduino UNO Serial Connection Goes in and Out

Hello,

The Situation: So I have been using the Uno for 6 months now and everything has been fine. However, a day ago I connected my Uno to my laptop and I got an error after I uploaded saying that the sync AVR dude was wrong and it could not talk to my Uno. After looking at the ports menu in the software I realized that the computer was not reconizing my uno. Com4 which is the port on my laptop the uno connects to was not showing up.

My Attempts to solve the solution: Firstly, I tried hooking up the uno to my desktop computer, which reconizes the Uno on COM3. Amazingly this worked, I could upload code ect. So thinking that there was nothing wrong with hardware, I went back to my laptop to trouble shoot what happened.

Next, I hook into my laptop and guess what, it reconizes COM4, the port on my laptop, and I can upload code again. So, I am trying to run a program that uses interrupts to count clicks comming from some digitial logic synchrnous flops and a XOR Gate. To test this, I wanted to read the number of counts on the serial ports. I do this and upload the code, using my laptop. Guess what, the variable I called "Count", displays on the serial ouput as constantly incrementing eventhough I haven't triggered the count via the digitial hardware (FLOPS and XOR Gate). So, I start thinking there is something wrong with the serial communcation. Guess what, I start jiggling around with the USB cable that connects directly into the UNO board and the number that was incrementing like crazy (OVERFLOWING on the serial port) stops when I pressed the USB connector (HARD) into the connector on the UNO. So now I'm thinking it is connectivity issue but I'm only 50% confident. By the way, guess what, I have do this entire test with out even hooking up the Uno to any digital hardware at all, the USB cable is the only cable hooked into the UNO.

Next, I went back to my desktop to see if the same problems occur when I press the USB cable in (HARD) into the USB Connector on the UNO board. The number on the serial port would overflow (behave wrongly) when the USB cable was lose and would stop (Behave correctly) when I shoved the cable in (HARD). It seems like the Serial connection is going "IN AND OUT".

In addition, I notice that when the USB Cable is not shoved in (HARD) the computer (MY Laptop) does not reconized the UNO in COM4 at all, but when the USB cable is shoved in (HARD) is does reconize the Uno at COM4. Also, I have noticed that certain USB ports on my Laptop work better than others when it comes to getting the lap top to work.

My main problem is that I can isolate the problem to my lap top because it occured on both my desktop and laptop. Additionaly, this entire thing is very strange because I was using the UNO with out anyissues about 1.5 -2 weeks ago and had not problems like this what so ever.

I'm almost sure this is not a software issue because I have written similar code before to read a rotary encoder.

Anways I think maybe there is loose cable? I need to know if this has happend to anyone else before, I hope its not a hardware issue. Any suggestions? Thank you

I was testing the arduino on my desktop computer. I don’t think it is a cable issue anymore. My code:

int count;
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  attachInterrupt(0,trigger,CHANGE);            //interupt for left wheel 
  attachInterrupt(1,trigger,CHANGE);           //interupt for right wheel
  count = 0; 

}

void loop()
{  
   interrupts();
    
  
   if (count < 100)
     digitalWrite(13,HIGH);
    Serial.print(count);
    Serial.println();
 
}



void trigger(){ 
  count = count +1;    
}

Now heres the problem, I turn the arduino on, and monitor the serial port. The arduino is sitting on a table with no hands touching it. The counter sits at zero because nothign has caused it to increment. NOW, if I grab the cable and shake it around nothign still happens, so I don’t think it is a loose connection.

So, guess what, if I grab the arduino or put my hands on the plastic headers for any of the i/o, A/d or power supply, the arduino goes haywire and the serial port monintor of the variable count starts incrementing like crazy. Something is triggering the interrupt when I bring my hand near to the Arduino.

I the issue is that there is noise on my pin 2 and pin 3 enough that every time I put my hand close to one of the pins (FLOATING) it triggers the interupt.

Sometimes when sending data over the serial port at a high rate, the Uno's 8u2 gets stuck.

Press and hold the RESET button, while connecting the USB cable. Keep RESET held until just after the "Binary Sketch Size" message of an upload. (It will take some practice to get the timing right.)