Arduino Uno - Serial Communication Problem

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

void loop() 
{
Serial.print("Temp ");
Serial.print("\n");             
delay(1000);
}

This simple code causes my Arduino Uno to continuously transmit data (TX led alway on) unless I open a serial monitor (it doesn't matter if I use the one in the Arduino IDE or a simple python program) right after upload (then everything works as wanted).
Once the Arduino is in this "stall" I am unable to make any serial connection nor am I able to upload any new program.
It is also somehow random if I am able to open the serial monitor, sometimes tabbing between windows in Ubuntu helps (which is really confusing).
Switching to a Duemilanove resolved all issues but this can't be the resolution :frowning: .

meru

It's your Arduino connected via USB to the computer? If this is true I think I have the same problem. I think Serial library work with TX and RX pins, the same pins than the USB port. I think we can use RX and TX if we are connected to the PC with the USB.

I change my code and work with pin 2 =RX and 3=TX and work with SoftwareSerial.h library. Something like:

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
#define ledPin 13

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() {
  // listen for new serial coming in:
  char someChar = mySerial.read();
  // print out the character:
  mySerial.print(someChar);
  // toggle an LED just so you see the thing's alive.  
  // this LED will go on with every OTHER character received:
  toggle(13);

}


void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState); 
  // if pinState = 0, set it to 1, and vice versa:
  pinState = !pinState;
}

The only way I see to load the same program on RX,TX pins is disconnect the RX,TX cable from the Arduino board, load the program and connect the RX,TX another time and finally reset the board to execute another time the setup.

SoftwareSerial is obsolete. You should be using NewSoftSerial, instead.

  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

Do you want the software serial instance to manage these pins, or do you want to? It shouldn't be both ways.

  // toggle an LED just so you see the thing's alive.
  // this LED will go on with every OTHER character received:
  toggle(13);

That comment is plain wrong. The LED will be toggled every pass through loop, regardless of whether there was serial data read, or not.

  char someChar = mySerial.read();
  // print out the character:
  mySerial.print(someChar);

If nothing was available to read, mySerial.read() returns a -1. How do you fit that into a char? Why do you want to print garbage if there was nothing to read?

meru: you should be able to upload new programs to the Arduino by holding down the reset button for a few seconds, or holding down the reset button while you connect the board to the computer. It's not such an elegant solution, but maybe it's a work-around while we look for a better solution?

guys, how do you physically connect tx/rx pins to your PC?

how do you physically connect tx/rx pins to your PC?

Through the USB port.
If you want to go direct then put the pins to an RS232 converter like a MAX202 and then connect the output of that either to a real serial port or a USB to RS232 lead.

Why should I connect RX/TX to a serial/USB converter connected to a serial port, if I can directly connect RX/TX to USB?

Has USB standard TTL levels?

if I can directly connect RX/TX to USB?

No you can't. The through the USB port is via the arduino's on board USB to serial adaptor.

Ok, I'm totally lost now: you just said you redefined pins 2 and 3 to use them as alternative TX/RX rather than 0 and 1, and that you connect them to PC USB.... and now you say it is not possibile?!? :-?

No I didn't say that.
You asked:-

guys, how do you physically connect tx/rx pins to your PC?

and I told you.
Now you are asking about alternative TX/RX . The answer to that one is simpler.

  1. Have you got a serial port on the PC - Yes use a MAX202 to connect it up - if no the go to 2:-
  2. Get a serial port on your PC by a USB to RS232 serial adaptor cable and go back to 1.

OR

  1. Get a USB to serial TTL adaptor and wire that directly to the arduino.

No I didn't say that.
You asked:-

guys, how do you physically connect tx/rx pins to your PC?

and I told you.
Now you are asking about alternative TX/RX . The answer to that one is simpler.

  1. Have you got a serial port on the PC - Yes use a MAX202 to connect it up - if no the go to 2:-
  2. Get a serial port on your PC by a USB to RS232 serial adaptor cable and go back to 1.

I was talking abut these TX/RX pins!!! Since the beginning!!

#define rxPin 2
#define txPin 3

And anyway I don't actually need to connect Arduino to PC again, besides USB: I'm interested on using TX/RX pins to connect Arduino to serial-controlled devices, and I can't find any MAX232 in electronic shops here around.

I was talking abut these TX/RX pins!!! Since the beginning!!

#define rxPin 2
#define txPin 3

And anyway I don't actually need to connect Arduino to PC again, besides USB: I'm interested on using TX/RX pins to connect Arduino to serial-controlled devices, and I can't find any MAX232 in electronic shops here around.

Pins 2 and 3 are NOT TX and RX pins. They are general purpose IO pins that some software is using to emulate serial data transmission via the TX/RX pins. So, don't go getting all snooty when you say one thing and mean another.

If you can't get a MAX232 chip, then you are pretty much SOL.

Pins 2 and 3 are NOT TX and RX pins. They are general purpose IO pins that some software is using to emulate serial data transmission via the TX/RX pins. So, don't go getting all snooty when you say one thing and mean another.

Do you THINK? (facepalm)

(You needed just a dozen of posts to understand what I am talking about.)

(You needed just a dozen of posts to understand what I am talking about.)

I guess I need at least one more, since I still don't understand what your problem is, or how it relates to the problem that started this thread in the first place.

Would it be an alternative to use "while" instead of "loop" and use a button (digital i/o) to end the while loop if you need to program the Arduino once again?

Karl-Heinz