我想要2個Arduinos Leonardo進行通信,例如發送一個字符串,所以我必須使用Serial1
通過引腳0(RX)和1(TX)上的RS232進行通信。如何在Arduino上傳輸字符串?
我需要在該引腳中寫入二進制數據,問題是如何使用Serial1.write
發送字符串。 Serial1.print
工作沒有錯誤,但我認爲它不會做我想要的。任何建議?
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
while (!Serial); // while not open, do nothing. Needed for Leonardo only
}
void loop() {
String outMessage = ""; // String to hold input
while (Serial.available() > 0) { // check if at least one char is available
char inChar = Serial.read();
outMessage.concat(inChar); // add Chars to outMessage (concatenate)
}
if (outMessage != "") {
Serial.println("Sent: " + outMessage); // see in Serial Monitor
Serial1.write(outMessage); // Send to the other Arduino
}
}
此行Serial1.write(outMessage);
是給我的錯誤
「
no matching function for call to 'HardwareSerial::write(String&)'
」
我tryed在示波器看'Serial1.print',似乎是發出正確的數據 – mafap 2013-05-01 15:37:41