warren631:
I have finally got it working. parseInt() DOES work with softwareserial. If I used the hardware serial it got confusing with other prints such as debugs on the same serial (USB) line. Here are my solutions for sending values from a Uno to a Nano using SoftwareSerial on any pins. I use pins 4 and 5. You could transmit more than two values using similar logic. Its pretty simple. I hope this helps someone else trying to do this:
//Uno transmitter
// Send two ints to a Nano (wheel speed setpoints)
// Connect pin5 Uno to pin 4 Nano
// Connect pin4 Uno to pin 5 Nano
// Receiver is Nano_reciever.ino
#include <SoftwareSerial.h>
int speedL, speedR;
SoftwareSerial mySerial(4, 5); // RX, TX
void setup()
{
Serial.begin(4800);
Serial.flush();
mySerial.begin(4800);
mySerial.flush();
speedL = 123; // for testing
speedR = -456;
}
void loop()
{
mySerial.print(speedL); //send the two speeds
mySerial.print(",");
mySerial.print(speedR);
mySerial.print('\n');
Serial.print(speedL); //just for debugging
Serial.print(",");
Serial.print(speedR);
Serial.print('\n');
delay(100);
}
//Nano reciever
// read two ints from a Uno
// see Uno_transmitter.ino
#include <SoftwareSerial.h>
int setL, setR;
SoftwareSerial mySerial(4, 5); // RX, TX
void setup()
{
Serial.begin(4800);
Serial.flush();
mySerial.begin(4800);
mySerial.flush();
}
void loop()
{
if (mySerial.available()) { //read the two speeds
int setL = mySerial.parseInt();
int setR = mySerial.parseInt();
if (mySerial.read() == '\n') {
Serial.print("setL = ");
Serial.print(setL);
Serial.print(", setR = ");
Serial.println(setR);
}
}
delay(100);
}
Very nice!! Should be included in official examples to test serial communications devices between Arduinos (I used this to test HC-12 communications between 2 Arduino Uno's)