Have an Arduino mega 2560 and require the use of 4 software serial ports, I'm unable to use hardware serial without major refacoring of my hardware/software. the ports are not running at the same time, I am using one, destroying it then using the next.
I currently have two ports working at their respective times, but when I try to use the third it does not work. I have no comms between the device. I've confirmed that the device works when plugged into [10, 9].
My pins I am trying to use are [10, 9] working, [11, 8] working, [15, 16] non-working , [14, 17] non-working.
I destroy the software serial object once I am finished using it and create the new software serial object for the next IO I want to communicate with.
Is there something I'm missing? I'm adhering to the RX pin restrictions. Am I not disposing of this object properly? Should I be switching my TX? I've even tried using many different RX pins in the list found here to no avail.
Sample code provided for your pleasure
#include <SoftwareSerial.h>
SoftwareSerial *mySerial = NULL;
//Creates new softwareserial object
SoftwareSerial* getNextSoftwareSerial(int8_t currSerial)
{
SoftwareSerial* newSerial = NULL;
if (mySerial != NULL)
{
delete mySerial;
}
switch(currSerial){
case 0:
newSerial = new SoftwareSerial(10, 9);
break;
case 1:
newSerial = new SoftwareSerial(11, 8);
break;
case 2:
newSerial = new SoftwareSerial(15, 16);
break;
case 3:
newSerial = new SoftwareSerial(14, 17);
break;
}
newSerial->begin(9600);
delay(20);
return newSerial;
}
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Starting:"));
int8_t currSerial = 0;
while (currSerial != MAX_SERIAL)
{
mySerial = getNextSoftwareSerial(currSerial);
//My software that leverages the current serialport
currSerial++;
}
}
"Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)."
CrossRoads:
"Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)." https://www.arduino.cc/en/Reference/SoftwareSerial
Hi, on the Arduino MEGA 2560 pins 14 and 15 (UART Hardware Pins) the library does not work. The TX works, but these 2 pins cannot be used for the RX ...
why?
a little long to explain. In short, I have a device I built based on the ATMEGA 1284P where I use UART Serial1 at the Hardware level. I can't change anything regarding connections. Now I need to flip the logic of serial communication (the whole protocol, not just the transmitted data) and I don't want to do it with external hardware (it would be simple), and only with this library can I do it.
I must have the possibility of using serial communication both at the hardware level and via the software by reversing the protocol, which can be selected simply by software in the firmware.
P.S. I did the test on 1284P(pin 10-11) and MEGA 2560 (pin 14-15) ... and the softwareSerial Library doesn't just work on the pins where the UART Hardware is.
This is the sketch:
//Programma per Testare la softwareSerial su MEGA
#include <SoftwareSerial.h>
byte softwareRxPin = 15; //è il pin RX della Seriale Software
byte softwareTxPin = 11; //è il pin TX della Seriale Software
const int ledPin = LED_BUILTIN; // the number of the LED pin
int ledState = HIGH; // ledState used to set the LED
byte RX = 0; //valore utilizzato per trasmettere un valore fittizzio alle diagnosi che richiedono il valore
SoftwareSerial miaSeriale(softwareRxPin, softwareTxPin); // RX, TX
void setup() {
pinMode(ledPin, OUTPUT); //Setto il pin per il led come Output
digitalWrite(ledPin, HIGH); //Accendo il Led
delay(500); //Piccola attesa per vedere il led funzionare
miaSeriale.begin(9600); //imposta la velocita' della seriale software
}
void loop() {
if (miaSeriale.available( ) ) { //Se sulla seriale software ci sono dati in ricezione
digitalWrite(ledPin, HIGH); //Accende il Led
RX = miaSeriale.read(); //Legge il Byte ricevuto
miaSeriale.write(RX); //Ritrasmette il Byte ricevuto
}
else{ //Altrimenti
digitalWrite(ledPin, LOW); //Spengo il Led
}
}