I’m having trouble getting my Particle Argon Serial1 port to transmit data. The RX pin seems to be working fine as I can read from another device, but nothing at all seems to happen on the TX pin when I write. Here’s my sample program
void setup() {
// put your setup code here, to run once:
Serial1.begin(9600);
delay(100);
}
void loop() {
Serial1.println("Hello World!");
delay(1000);
}
Unfortunately I don’t have any other devices to compare against if it’s a hardware problem. Has anyone else experienced this issue and found a workaround? The only thing I could think to try was setting the TX pin (D9) to an output first but that made no difference (as I’d expect).
Thanks for the fast reply! Great followup test; sadly it didn’t work out. Here’s my code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(100);
Serial1.begin(9600);
delay(100);
Serial.println("Ready!"); //Write to USB
}
void loop() {
if (millis() % 1000 == 0) {
Serial1.println("Hello"); //Write to Serial1
Serial.println("Wrote to Serial1"); //Write to USB
}
if (Serial1.available()) {
byte i = Serial1.read(); //Read from Serial1
Serial.print(i); //Write to USB
}
}
And my USB Serial output:
Serial monitor opened successfully:
Ready!
Wrote to Serial1
Wrote to Serial1
Wrote to Serial1
Wrote to Serial1
...
Pinky swear I have TX (D9) and RX (D10) connected together.
Update:
This is what my Argon produces (with a slightly altered code)
.
Hello
.
Hello
.
Hello
That’s my code since you should always try to flush the entire buffer when there is data available
void setup() {
Serial.begin();
Serial1.begin(9600);
}
void loop() {
static uint32_t msLastTime = 0;
if (millis() - msLastTime > 1000) {
msLastTime = millis();
Serial.println("."); // Write to USB
Serial1.println("Hello"); // Write to Serial1
}
while(Serial1.available()) {
Serial.write(Serial1.read()); // Write to USB
}
}
When you double checked that you really got the TX pin correct (between RX and NC) and my altered code doesn’t work either, chances are high that your pin is dead.
You can try that with a jumper from TX to D7 and this code
Thanks again for the fast and thorough responses (not just here but in nearly all the forum threads I’ve used!). It definitely looks as though the D9 pin is dead as I only get the period showing in the serial monitor and no blinky light off D7 when tied to D9.
I know it’s off topic, but I’m curious about your note about flushing the Serial buffer. I totally understand the need to do so, but I would have thought my code would achieve the same result by checking the buffer in the main loop (versus a second embedded while loop). Does something happen with the serial buffer between cycles of the loop function?
Yup, a whole lot of stuff happens between iterations of loop() the most time consuming is probably the system task that does the background cloud and mesh stuff. But there are also other functions that might interfere if not done correctly (e.g. serialEvent()).
On a Photon for example you only get about 1000 iterations of loop() when connected to the cloud and on the Electron it's about 100. In that time with higher baudrates you may loose a tonne of data if you only read one byte per iteration.