Go Down

Topic: SoftwareSerialExample doesn't work well. (Read 1 time) previous topic - next topic

tkawa

Hi,
I tried to use "SoftwareSerialExample" in Example of Arduino IDE 1.0.3, but it didn't work well
I used 2 Arduino UNO (R3).
I connected one Arduino's pin 10 to TX of another Arduino, and pin11 to RX accroding to the example.

After pushing the reset buttons of the latter Arduino, I should see "Hello, world?" in the former's serial monitor.
But, I got only unreadable characters.
I fixed baud numbers, but it can't work well.
Could you help me find a solution to this problem?

PaulS

Did you connect the grounds, too? Show a picture! Show some code!

GoForSmoke

RX to TX and TX to RX and just as Paul says, GND to GND.
The minimum serial cable has long been 3 wires.

Also how long are your wires and what baud rate are you trying?


Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

tkawa

Hi all!
I puts a picture of the 2 Arduinos, and a screenshot of the serial monitor.
I used just "SoftwareSerialExample" code in Arduino Examples.
http://arduino.cc/en/Tutorial/SoftwareSerialExample

Baud rate I used is 57600.

When I pushed the reset button of the Arduino connects a USB cable,
"Goodnight moon!" appears in the serial monitor.
When I pushed it of another Arduino,
the unreadable characters appears there.

UKHeliBob

From the example :

* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

You seem to have RX of the left device connected to pin 11 of the right device (yellow wire) and TX of the left device connected to pin 10 of the right device (red wire)
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Nick Gammon

Quote
* CIMG1569.JPG (2223.92 KB, 2560x1920 - viewed 4 times.)


2.2 Mb attachment. How about sizing it down a bit?

Quote
I used just "SoftwareSerialExample" code in Arduino Examples.


And how about posting said code?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

tkawa


From the example :
You seem to have RX of the left device connected to pin 11 of the right device (yellow wire) and TX of the left device connected to pin 10 of the right device (red wire)


I think the connection is not wrong.
When I exchange the cables, I can't get anything from the Arduino which has no USB cable.



2.2 Mb attachment. How about sizing it down a bit?

I'm sorry! I'll size down it next time.


And how about posting said code?

It's just a code in Arduino Examples, but I put here.
Code: [Select]

/*
  Software serial multple serial test

Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.

The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)

Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

Not all pins on the Leonardo support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example

This example code is in the public domain.

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

Nick Gammon

You have posted one sketch. What's running on the other device?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

tkawa


You have posted one sketch. What's running on the other device?

I have used the same code in both the Aruduinos.

PeterH


I have used the same code in both the Aruduinos.


You have connected the hardware serial of one UNO to the software serial of the other UNO. That sketch sets the hardware and software serial ports to different speeds, so your arrangement won't work.

You need to connect the software serial of one board to the software serial of the other, remembering to cross the Rx and Tx connections over. When you do that you should see "Goodnight moon!" from your local UNO, then "Hello, world?" sent from the other Arduino.
I only provide help via the forum - please do not contact me for private consultancy.

GoForSmoke

So RX to TX, TX to RX, GND to Analog pin?

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

tkawa


You have connected the hardware serial of one UNO to the software serial of the other UNO. That sketch sets the hardware and software serial ports to different speeds, so your arrangement won't work.

You need to connect the software serial of one board to the software serial of the other, remembering to cross the Rx and Tx connections over. When you do that you should see "Goodnight moon!" from your local UNO, then "Hello, world?" sent from the other Arduino.

I tried your connection. I put a picture and screenshots of the connection.
When I took the screenshots, I pushed the reset button of the left Arduino first, and it of the right second in the picture.
But, still it can't work.


So RX to TX, TX to RX, GND to Analog pin?

I connect GND to GND.

UKHeliBob

This thread is getting more complicated as time goes by.

From the comments at the top of the code posted

" Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial."

So, hardware serial on one Arduino and software serial on the other.  Not software serial on both.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

GoForSmoke

Wiring looks fixed. 10 to 11, 11 to 10, GND to GND.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up