johnny78
Full Member level 5
hi Guys
this code should read serial data coming to serial 1 on arduino mega & display it on serial monitor using serial 0
would you check it please ?
thanks
Johnny
this code should read serial data coming to serial 1 on arduino mega & display it on serial monitor using serial 0
would you check it please ?
thanks
Johnny
Code:
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(1200, SERIAL_7N1);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
while (Serial1.available()) {
// get the new byte:
char inChar = (char)Serial1.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}