I'm trying to run multiple software serial ports on Yún. My code looks like that so far:
#include <SoftwareSerial.h>
SoftwareSerial serial1(8, 9);
SoftwareSerial serial2(10, 11);
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
serial1.begin(9600);
serial2.begin(9600);
}
void loop() {
uint8_t buf1[1] = {0x01};
uint8_t buf2[3] = {0xC0, 0xFF, 0xEE};
uint8_t buf3[2] = {0xBA, 0xBE};
Serial1.write(buf1, 1);
serial1.write(buf2, 3);
serial2.write(buf3, 2);
while(Serial1.available()) {
Serial.print(Serial1.read(), HEX);
Serial.print(' ');
}
serial1.listen();
while(serial1.available()) {
Serial.print(serial1.read(), HEX);
Serial.print(' ');
}
serial2.listen();
while(serial2.available()) {
Serial.print(serial2.read(), HEX);
Serial.print(' ');
}
delay(1000);
}
For testing purposes, I connected every following pair of pins together with cable (to create loopback):
1 to 2 => Serial1 (sending 0x01)
8 to 9 => serial1 (software port, sending 0xC0, 0xFF, 0xEE)
10 to 11 => serial2 (software port, sending 0xBA, 0xBE)
Refering to documentation, these pins should work:
Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
Unfortunately, only Serial1 is working (you should se recieving 0x01 in serial console).
Anybody knows where the problem could be? Thank you.
Edit:
There is probably an bug in SoftwareSerial library.
AltSoftSerial works great, but I need two software serials.