This half works. The sender is sending and the receiver is receiving but the message gets messed up.
Something is probably staring me in the face but I can't see it.
SENDER
// Pro Mini 8MHz, 3.3V
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup() {
mySerial.begin(4800);
delay(1000);
}
void loop() {
mySerial.println("Hello, world!");
delay(1000);
}
RECEIVER
// Pro Mini 8MHz, 3.3V
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup() {
mySerial.begin(4800);
delay(1000);
Serial.begin(4800);
while (!Serial) {}
Serial.println("Goodnight moon!");
}
void loop() {
if (mySerial.available()) {
Serial.write(mySerial.read());
}
}
Robin2
June 26, 2018, 9:58am
2
Image from Original Post so we don't have to download it. See this Simple Image Guide
...R
Robin2
June 26, 2018, 9:59am
3
Try Serial.print() rather than Serial.write()
...R
Serial Input Basics - simple reliable ways to receive data.
Thanks Robin2.
I already read your "SimpleImageGuide" and was about to use it when I saw you'd beaten me to it! I still have to wait 5 minutes before I can show images.
Using Serial.print I get ascii numbers instead of characters. My bit of code is based on an example so I wasn't expecting any trouble with it.
I'll go and read SerialInputBasics.
Thanks again.
I've reduced my ambitions to a single character. Still no luck.
SENDER
// Pro Mini 8MHz, 3.3V
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup() {
mySerial.begin(4800);
delay(1000);
}
void loop() {
mySerial.print('A');
delay(1000);
}
RECEIVER
// Pro Mini 8MHz, 3.3V
#include <SoftwareSerial.h>
char receivedChar;
boolean newData = false;
SoftwareSerial mySerial(2, 3); // RX, TX
void setup() {
mySerial.begin(4800);
delay(1000);
Serial.begin(4800);
while (!Serial) {}
Serial.println("Goodnight moon!");
}
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (mySerial.available() > 0) {
receivedChar = mySerial.read();
newData = true;
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChar);
newData = false;
}
}
OUTPUT
Goodnight moon!
This just in ... ⸮
This just in ... ⸮
This just in ... w
This just in ... ⸮
This just in ... W
This just in ... ⸮
This just in ... ⸮
This just in ...
This just in ... ⸮
This just in ... ⸮
This just in ... ⸮
This just in ... ⸮
This just in ... ⸮
The above code supposes I can use serial functions with software serial. Is that right?
Same output at 9600 and 19200 baud.
Robin2
June 26, 2018, 2:45pm
8
Have you a GND connection between the two Arduinos? For Serial to work there needs to be 3 wires - Rx Tx and GND.
Until you get it working stick to 9600 baud.
...R
Robin2:
Have you a GND connection between the two Arduinos? For Serial to work there needs to be 3 wires - Rx Tx and GND.
I thought I had.
Find the error.
Lucky I got it wrong twice.
Thanks Robin2.
Apparently, my photo failed a security check. It was just to show you I'd connected the two RAW pins together instead of the GND pins.
It works now, of course.
Robin2
June 26, 2018, 5:39pm
10
kayel:
Apparently, my photo failed a security check.
That can happen with JPG images from cameras that include EXIF data. A simple solution is to use some photo software to convert the image to PNG.
...R