The Serial1.available() will only return true (not zero) if there are bytes in the Serial1 buffer. In this case, you are then writing if true. The following is from the reference documentation for Serial.available();
Get the number of bytes (characters) available for reading from the serial port. This is data that's already arrived and stored in the serial receive buffer.
The receive buffer size for hardware serial channels (Serial1, Serial2) is 128 bytes and cannot be changed.
Did you mean to use Serial.availableForWrite()? Alternatively, are you typing a character on the serial monitor to have the LED on for 2 seconds?
I have had them connected to a Raspberry Pi, but with nothing coming across, I have disconnected them to have the bare Xenon, and am trying to debug through the CLI particle serial monitor
To simplify the script, I've trimmed it down to the following.
My understanding of println is that it should print the lines out in the CLI under particle serial monitor. Correct? Since println has never fired under Serial1, I figured that is a symptom of why Serial1.write does not seem to work.
I can get Serial.println to print in the terminal, however Serial1.println does not.
As we work through this, I must be missing something about Serial1. I'm not sure what, but I have tried to strip away as any possible places for an issue to pop up, and it still is not working as I expected.
Do you have Serial1.RX connected to RPi.TX, and Serial1.TX connected to RPi.RX? it’s a simple mistake I make time and again…
Second thing, I’ve had trouble with Serial1.println on the Boron and I fixed it by using Serial1.write()
Last thing, I like of vectors because they have some easy array handling methods, so my example uses vectors. Hopefully it makes sense, heres and example I pulled from one of my programs:
#include <vector>
void sendSomeDataToSerial1(std::vector<int> message) {
bool debugLogging = true;
//prints bytes to console if global debug logging flag is true.
if (debugLogging) {
Serial.print("Sending Serial1Data: [");
}
int serialDataSize = message.size();
byte serialByteMessage[serialDataSize];
int i = 0;
// Make buffered array of the message
for(int data : message) {
serialByteMessage[i]=data;
if (debugLogging) {
Serial.print(data, HEX);
Serial.print(", ");
}
i++;
}
if (debugLogging) {
Serial.println("]");
}
if(debugLogging){
Serial.print("writing serial data");
}
Serial1.write(serialByteMessage, serialDataSize);
messageSent = true;
delay(100);
return messageSent;
}
You could connect Tx to Rx on the Xenon and then in the loop check Serial1.available() and if bytes available then read them and write to Serial. That way you will be able to see what is being written to Serial1 (Tx pin).
ultimately if you really want to get to the bottom of it and oscilloscope is the way to go.
But you could loopback like @armor suggested. Connect serial1 RX to TX on your Xenon. Then make a program that sends what you type in the console to Serial1 and echos what’s received back on the console… You can type in a terminal and see if it get’s echoed back. here’s an arduino example:
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
glad you got it fixed. I know what the difference is between those, but I wonder why it mattered in this case. Something should have still come through…