on IDE 1.56 with Arduino UNO, I bridged pin 1(TX) and pin 5. So on Serial Monitor I could got what sent from SoftwareSerial.
The result is: I could not get "Hello", cound not get "Hi"
If I remove the line "Serial.begin(9600);" , I could get "Hello" and "Hi"
Anybody could tell me what is wrong?
If I want use both HardwareSerial and SoftwareSerial, what should i do?
Thanks so much
I also did the following test
It is an example from Arduino IDE. I bridged the pin10 and pin11. Accroding to my understanding, I could get what I sent on the serial monitor. But all I get is "Goodnight moon!"
#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.print(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
swseansw:
I wrote the following code and found the weird problem.
on IDE 1.56 with Arduino UNO, I bridged pin 1(TX) and pin 5. So on Serial Monitor I could got what sent from SoftwareSerial.
The result is: I could not get "Hello", cound not get "Hi"
If I remove the line "Serial.begin(9600);" , I could get "Hello" and "Hi"
Anybody could tell me what is wrong?
If I want use both HardwareSerial and SoftwareSerial, what should i do?
Thanks so much
Yes, well once you have done a Serial.begin the hardware serial takes over that line. They are fighting each other.
on IDE 1.56 with Arduino UNO, I bridged pin 1(TX) and pin 5. So on Serial Monitor I could got what sent from SoftwareSerial.
Don't just bridge pins together for your amusement without knowing what you are doing. You have one pin (pin 1) trying to drive high and the other one (pin 5) trying to drive the line low. That will damage the output drivers.
Thanks so much for your prompt reply.
I bridge the two pins to make testing easier.
I also did testing on the official SoftwareSerial example, as I mentioned above. If the SoftwareSerial and HardwareSerial fight each other, how does the example work?
Any way to solve this?
Hi, Nick,
I use on Arduino UNO and bridged the pin 10 and pin 11. So the SoftwareSerial could read what it sent.
I have 2 Arduino boards.
Why we need to connect to other Arduino?
In more detail, SoftwareSerial cannot send and receive at the same time. It is running in software after all. Thus it cannot send to itself on the same device.
swseansw:
If the SoftwareSerial and HardwareSerial fight each other, how does the example work?
At the beginning of the function setup(), the hardware TX pin is not set as an output yet, so the string "Hello" can be transmitted on the output pin #5.
After the call to Serial.begin(), the hardware TX pin is set as an output. Its level is set to high when nothing is transmitted, and tends to force the output pin #5 level to high. When the pin #5 wants to output a low level (i.e. while sending a start bit or a data bit set to zero), the actual level is something between high and low levels. So finally, the string "Hi" that the pin #5 tries to send doesn't correspond to a sequence of correct logic levels.