Hi.
Goal: Send a constant from one arduino board to another.
Connections: Uno Rx 0 pin to Mega Tx3 14 pin, Uno Tx 1 pin to Mega Rx 15 pin, Both boards powered by USB to computer.
Code:
Uno Board Sending the Constant :
int desiredRPM=1000;
int Norm_desiredRPM;
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(0,1);
void setup() {
Serial.begin(38400);
mySerial1.begin(38400);
}
void loop() {
//mySerial1.listen();
Norm_desiredRPM=desiredRPM*.02125;//Sets value to 255 for 12000rpm and 0 for 0 rpm.
mySerial1.write(Norm_desiredRPM);
delay(1000);
}
Mega Board Receiving the Constant:
#include <SoftwareSerial.h>
int Norm_desiredRPM;
int desiredRPM;
SoftwareSerial portOne(15,14);
void setup() {
Serial.begin(38400);
portOne.begin(38400);
}
void loop() {
portOne.listen();
Norm_desiredRPM = portOne.read();
desiredRPM=Norm_desiredRPM/.02125;
Serial.print("value received: ");
Serial.println(Norm_desiredRPM);
Serial.print("Processed: ");
Serial.println(desiredRPM);
delay(1000);
}
Output:
On the Serial monitor for the Mega, I am getting a value of 0. If I switch the boards so the Mega is sending the value to the Uno (I change the Rx Tx pin numbers, of course) I get what seems to be random values on the serial monitor for the Uno. I've looked at a bunch of examples and this seems like it should be really simple - just a read write situation, but nothing is working. I have my suspicions that since the 0,1 pins on the Uno are used to communicate with the computer via the USB that things are getting all messed up. Thoughts?
--Ian