XBee node losing read speed after a few transmissions?

I have an XBEE S1 connection set up and running this code on my arduino:

#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
SoftwareSerial CO2(5,6);

void setup()
{
  // Set up both ports at 9600 baud. This value is most important
  // for the XBee. Make sure the baud rate matches the config
  // setting of your XBee.
  XBee.begin(9600);
  CO2.begin(9600); 
}

void loop()
{
CO2.println("%"); 
delay(50); 

  if (CO2.available())
  {
   char newChar = CO2.read();
  XBee.write(newChar);
  }
  
}

It runs great for the first few transmissions of the command % but then does this:

% 020.15
% 020.15
% 020.15
% 020.15
% 020.15
% 020.15
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[/code

If I remove the delay I just get junk characters, if I increase it I still get the same error of just getting %%%%%%.  How can I make it send a command, receive the answer and display it?

Check https://www.arduino.cc/en/Tutorial/TwoPortReceive

J-M-L:
Check https://www.arduino.cc/en/Tutorial/TwoPortReceive

I am not sure how this is helpful, I am not doing a 2 port receive, I am doing a 1 port receive, and 2 port send:

Send command from arduino to software serial port one

Read response from serial port one

Send Response to Serial port 2

Those are the steps no?

What is CO2 connected to?

J-M-L:
What is CO2 connected to?

What do you mean? It is a gas sensor, powered by the arduino 3.3V, with its Rx/Tx pins wired to the 5,6 pins on the zigbee shield atop the uno.

is it the MH-Z16 NDIR ?

J-M-L:
is it the MH-Z16 NDIR ?

No the sprintir

Is that from a Digital pin or the power pin?

if form a D Pin - your CO2 reader is spec-ed for 33mA, top max limit for a pin on your adruino is 40mA and you should try to never get too close... Would suggest to power separately your CO2 reader (also the doc mentions Startup inrush current 50 mS @ 60 mA peaks --> that's quite a draw as well for your arduino)

same for your Xbee by the way, if I remember they can draw 50mA @ 3.3v.. too much for an arduino D pin

Otherwise your CO2 reader has 2Hz measurement interval, so you should poll it only every 500ms max - may be that's the pb

J-M-L:
Is that from a Digital pin or the power pin?

if form a D Pin - your CO2 reader is spec-ed for 33mA, top max limit for a pin on your adruino is 40mA and you should try to never get too close... Would suggest to power separately your CO2 reader (also the doc mentions Startup inrush current 50 mS @ 60 mA peaks --> that's quite a draw as well for your arduino)

same for your Xbee by the way, if I remember they can draw 50mA @ 3.3v.. too much for an arduino D pin

Otherwise your CO2 reader has 2Hz measurement interval, so you should poll it only every 500ms max - may be that's the pb

The power pin, the one next to the 5v and grounds on the analog side of the arduino board.

It has a 20Hz measurement sorry I linked the wrong one:

OK so you might have a power pb probably

the 3V3 pin supplies 3.3V generated by the on-board regulator and maximum current draw is 50 mA.

your spec states

Average Current <15mA
Peak current only 100mA

and you also have the xbee drawing current - up to 50mA too

I’d be tempted to ask you to try to power the xBee and your sensor separately just for testing