I have a Raspberry Pi 3 connected to the serial of my Arduino Uno (pins 0 and 1), but I also have another device connected to two other serial pins on the Arduino (pins 10 and 11, using the SoftwareSerial library).
What I want to do is send a string from the RPI, then the Arduino gets it and resends that information through the other serial port to my device.
Until now the Arduino can receive the information from the RPI, but I'm not sure how to send that same string through the other serial port, the one going to the device.
Here is the code I'm using:
#include <SoftwareSerial.h>
String b = "0";
SoftwareSerial portOne(2, 3); //RX= pin 2 TX= pin 3
void setup() {
Serial.begin(9600, SERIAL_8N1);
portOne.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
b = Serial.readString();
Serial.println("Data from RPI:");
}
portOne.listen();
while(portOne.available() > 0){
Serial.println("Data from port one:");
Serial.println(b);
}
}
I just get the data coming from the RPI, but nothing from portOne.
Any thoughts?
/dev/ttyUSB0
or/dev/tty ACM0
depending on the board. The main advantage of doing this is that you can WiFi int o your Pi with RDP and remotely reprogram the ASrduinos on the fly as necessary. Your strange readings may well be because of the way you are cabling to the module. Perhaps try software.serial and regular pins?