Hello all,
I am encountering serious problems with SoftwareSerial.h
And when I say problems, I mean that nothing works at all!!!
Hello all,
I am encountering serious problems with SoftwareSerial.h
And when I say problems, I mean that nothing works at all!!!
If you want help you have to post your program.
Tell us what what your program is intended to do.
And please use the code button </>so your code looks like thisand is easy to copy to a text editor
...R
Okay, thanks. Finally... I solved it... ![]()
jsav2000:
Okay, thanks. Finally... I solved it...
Good news.
It would be helpful to other readers if you explain what the problem was and how you solved it.
...R
Of course...
I was trying to make an Arduino Mega to comunicate with an Arduino Nano, using SoftwareSerial.h.
The problem is that no message seemed to be sent...
My code was like this:
#include <SoftwareSerial.h>
SoftwareSerial serial(10, 11); // rx, tx
void setup() {
serial.begin(4800);
}
void loop() {
if (serial.available()) {
serial.read();
serial.print("Message received."); // send data to the other arduino
}
}
The only thing I changed is the print() command to write().
Like this:
#include <SoftwareSerial.h>
SoftwareSerial serial(10, 11); // rx, tx
void setup() {
serial.begin(4800);
}
void loop() {
if (serial.available()) {
serial.read();
serial.write("Message received."); // send data to the other arduino
}
}
...and now, all work fine!... ;D ![]()
jsav2000:
I was trying to make an Arduino Mega to comunicate with an Arduino Nano, using SoftwareSerial.h.
It seems strange to need SoftwareSerial on a Mega which has 3 spare HardwareSerial ports.
But you would almost certainly still need to use write() rather than print()
...R
I used SoftwareSerial.h because I am still testing the code, so it is very possible to upload it to an other Arduino, with only one serial port.
But, why should I use write()?
I saw in some other sketches that the print() was used.
jsav2000:
But, why should I use write()?
I confess I had not looked at your code - it was just the use of SoftwareSerial that caught my eye - and I had assumed you were using write() to send a number as a byte rather than converting it to charachters.
I did not even know that write() would send a string and I can't think what would be different between write() and print().
...R
Serial.write() does no conversion.
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.write(48);
Serial.println();
Serial.print(48);
}
void loop() {
// put your main code here, to run repeatedly:
}
Serial output:
0
48
SurferTim:
Serial.write() does no conversion.
Indeed. But that is not the way the OP is using it.
...R
I was only stating the difference I am aware of. The way the OP is using it shouldn't make a difference, but I haven't tested it.
edit: I lied. Actually, I tested the software serial println command with my Mega 2560 and Adafruit Ultimate GPS. It worked fine.
I can't think of any reason... just didn't work with print().
What is OP?
jsav2000:
What is OP?
Original Post(er). You.
I've used the software serial print and println before with no problems. Mine was Mega to GPS though.
Well, now it works fine... ![]()
If I have pronlems with it, I will post again...
But, anyway, thank you very much for your replies to my first post!
![]()
Guys there is a whole thread talking about the differences between Serial.print() and Serial.write()
Here it goes: serial.print or serial.write? - Syntax & Programs - Arduino Forum
I remember it as I came across it the same problem during the testing phase of my talking multimeter project.