Pico UART not working with XBee

Hello, i was trying to adapt a code i use on an arduino mega 2560 to recieve and parse serial data from an XBee, however it seems that the following code isn´t working:

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
char messageFromPC[numChars] = {0};
int integerFromPC = 0;
float floatFromPC = 0.00;
String Valuelist[15] = {"Paquetes rcv", "Tiempo instantaneo", "Numero de paquete", "Altitud BMP", "TAtmosferica BMP", "Presion", "Tension de la bateria", "Longitud", "Latitud", "Altitud GPS", "Satelites GPS", "Etapa de vuelo", "GPS Hora", "GPS Minutos", "GPS Segundos"};
boolean newData = false;
float Floatlist[15];
float RCV = -1;
float prev = 0;
float intervalo = 0;
void setup() {
  Serial1.setRX(1);
  Serial1.setTX(0);
  Serial.begin(115200);
  Serial1.begin(115200);
  while (!Serial);
  Serial.println("Listo");
}


void loop() {
  //Serial.println(Serial.readString());
  recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);

    parseData();
    //showParsedData();
    parX();
    newData = false;
  }

}
void parX() {
  int messageFromP = atoi(messageFromPC);
  if ((messageFromP >= 0) && (messageFromP <= 14)) { // no permite que se exceda
    String propiedad;
    propiedad = Valuelist[messageFromP] + ": ";
    Floatlist[messageFromP] = floatFromPC;
    //Serial.print(propiedad);
    //Serial.println(Floatlist[messageFromP]);
    if (messageFromP == 14) {
      RCV++;
      Floatlist[0] = RCV;
      handoff();
    }
  }
  else {
    (Serial.println("error de paquete"));
  }
}

void handoff() {
  float timer1 = millis();
  if (timer1 - prev >= intervalo) {
    prev = timer1;
    for (int n = 0; n < 15; n++)
    {
      //Serial.print(Valuelist[n]);
      //Serial.print(": ");
      Serial.print(Floatlist[n], 10);
      Serial.print(", ");
    }
    //Serial.println("pkg");
  }
  Serial.println();
}


void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (Serial1.available() > 0 && newData == false) {
    rc = Serial1.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0';
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

//============

void parseData() {

  char * strtokIndx;

  strtokIndx = strtok(tempChars, ",");
  strcpy(messageFromPC, strtokIndx);

  strtokIndx = strtok(NULL, ",");
  floatFromPC = atof(strtokIndx);


}

//============

void showParsedData() {
  Serial.print("Message ");
  Serial.println(messageFromPC);
  Serial.print("Integer ");
  Serial.println(floatFromPC, 4);

}

I managed to make it work some times after uncommenting and then commenting again the

Serial.println(Serial.readString());

line from the code.
The application i´m using it for sends a string with <data1,data2,....,data15> format.
For this i used the following code as a baseline Serial Input Basics - updated

I´m using the Earle Philhower core if it matters, and would appreciate any help, thanks!

I miss the wiring diagram in your post. XBees are 5V devices so you must not connect them directly to the Pico otherwise you might have already fried it.

Hello, as per their datasheet they are 3.3v capable devices,
Power requirements

As for the wiring diagram:


for which you can find the pinouts over hereProMicroRP2040 Graphical Datasheet

You didn't specify which XBee you're using, so I chose one I had the specification. I'm still missing the link to exactly the one you're using.

The specific datasheet states it should have an input between 2.7 and 3.6, with at least 120mAh available:
XBee®/XBee-PRO S2C Zigbee®

I´ve tested further and decided to bypass the XBees for a test and the same exact issue came up, i´m thinking its more of an UART problem on the pico core or how i initialized it.

What issue? You told in the first post that it works after commenting the line. As you most probably compiled the code again after the commenting a completely new version of code was uploaded and that has nothing to do with the code that was there before.

I don't see why you set the RX/TX pin as 1 and 0 are the defaults for Serial1.

You never described what "isn't working" exactly means. Does it freeze? Does it give you an unexpected output? Does it give no output at all?

It worked inconsistently meaning very rarely it printed out exactly what i needed but most of the time it did nothing, i have to define the pins as such because that´s a requirement of the core i´m using.

I´ve continued testing these few days and it appears that pulling up the RX pin on the pico with a 10k resistor fixes the issue, but i´m still wondering if i could pullup the pin internally.

"It did nothing" means it printed out no single character to the Serial Monitor? In that case you probably got a bad chip.

If "did nothing" means something else for you, you should precisely state what that means. If it just doesn't parse the data it might be because the XBee didn't receive it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.