Pages: [1]   Go Down
Author Topic: Arduino Uno - Serial Communication Problem  (Read 16101 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 :-( .

meru
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
#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.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
 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.

Code:
 // 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.

Code:
 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?
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Rome
Offline Offline
God Member
*****
Karma: 1
Posts: 987
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33992
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Rome
Offline Offline
God Member
*****
Karma: 1
Posts: 987
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33992
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Rome
Offline Offline
God Member
*****
Karma: 1
Posts: 987
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?!?  :-?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 620
Posts: 33992
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No I didn't say that.
You asked:-
Quote
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

3) Get a USB to serial TTL adaptor and wire that directly to the arduino.
« Last Edit: October 27, 2010, 08:54:08 am by Grumpy_Mike » Logged

Rome
Offline Offline
God Member
*****
Karma: 1
Posts: 987
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 
Quote
No I didn't say that.
You asked:-
 
Quote
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.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Rome
Offline Offline
God Member
*****
Karma: 1
Posts: 987
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: