How have you connected Serial2
? It's not a trivial task which involves some HW modifications.
AFAIK the Electron only really supports Serial1
, Serial4
and Serial5
(as stated in the tutorial above and the docs)
https://docs.particle.io/reference/firmware/electron/#serial
You may also try with Serial#.read()
first, to see whether you get any response at all.
Also bridging RX to TX on the same port is a basic way to test whether the desired ports work at all.
Are you getting any of your debug print statements back of the device?
Is the Electron breathing cyan?
With this code
#include "Serial4/Serial4.h"
#include "Serial5/Serial5.h"
const uint32_t SERIAL_RATE = 5000;
uint32_t lastCheck;
uint32_t lastSend;
void setup()
{
Serial.begin(57600);
Serial1.begin(57600);
Serial4.begin(57600);
Serial5.begin(57600);
}
void loop()
{
// Send our data
if (millis() - lastSend >= SERIAL_RATE)
{
lastSend = millis();
// Send data
Serial.println("Sending ATL");
Serial1.print("1:ATL\r\n");
Serial4.print("4:ATL\r\n");
Serial5.print("5:ATL\r\n");
Serial.println("ATL sent");
delay(100);
}
// Check if data has been recieved
if (millis() - lastCheck >= SERIAL_RATE)
{
lastCheck = millis();
Serial.println("Checking ports");
if (Serial1.available())
{
Serial.println("Received data on Serial1");
while (Serial1.available())
Serial.write((uint8_t)Serial1.read());
Serial.println();
}
if (Serial4.available())
{
Serial.println("Received data on Serial4");
while (Serial4.available())
Serial.write((uint8_t)Serial4.read());
Serial.println();
}
if (Serial5.available())
{
Serial.println("Received data on Serial5");
while (Serial5.available())
Serial.write((uint8_t)Serial5.read());
Serial.println();
}
Serial.println("Done checking ports");
Serial.println();
}
}
and a jumper chain TX1 -> RX4/TX4 -> RX5/TX5 -> RX1, I get this result
Sending ATL
ATL sent
Checking ports
Received data on Serial1
5:ATL
Received data on Serial4
1:ATL
Received data on Serial5
4:ATL
Done checking ports
Also note the datatypes and syntax for the millis()
timers - that's the official way how it should be done, to avoid troubles with value overrun and type conversions.