No data printing on serial monitor after sending data from xbee console to serial monitor through serial communication

I m trying to receive data from xbee console XCTU to serial monitor , i have connected xbee 1 to arduino uno and arduino uno to laptop and xbee 2 to different laptop

receive code :-
kinda working code

#include <SoftwareSerial.h>

// Define the XBee communication pins
const int xbeeRxPin = 6; // XBee Rx pin (Connect to Arduino Tx pin)
const int xbeeTxPin = 7; // XBee Tx pin (Connect to Arduino Rx pin)

SoftwareSerial xbeeSerial(xbeeRxPin, xbeeTxPin); // Create a SoftwareSerial object for XBee communication

void setup() {
Serial.begin(9600); // Start the serial communication for debugging
xbeeSerial.begin(9600); // Start the XBee serial communication

Serial.println("XBee Receiver is ready to receive data!");
}

void loop() {

// Check if data is available from XBee
if (xbeeSerial.available()) {
Serial.println("Data available from XBee...");
char val = "";
char receivedChar = char(xbeeSerial.read());

  // Print the received data from XBee 1's console (as ASCII value)
  Serial.print("receivedChar -->");
  Serial.println(receivedChar);
  val=val+receivedChar;
  Serial.print("val -->");
  Serial.println(val);

} else {
// Serial.println("No data available from XBee...");
}

// Add any other code you want to run continuously here

// delay(1000); // Add a short delay to prevent rapid looping
}

first i was getting the output but now it is showing no output
please help

I moved your topic to an appropriate forum category @rajatvishwa.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Are you following a tutorial from somewhere on the web?
If so post a link.

nope we aren't following any tutorial just using basic outline of code and using it for receiving code of data

Your best chance of success is to find a tutorial on the web that uses your specific model of Xbee (there are many different models).

1 Like

hey
thankyou for the advice
at the end my arduino uno was the issue and now i am getting the required output

code :-

#include <SoftwareSerial.h>
SoftwareSerial xbee (6, 7);
void setup() {
Serial.begin(9600);
xbee.begin(9600);
Serial.println("Xbee is ready to receive data!");
}

void loop() {
// Read data from Serial Monitor and send to XBee
while (Serial.available()) {
char t = Serial.read();
xbee.write(t);
}

// Process received data from XBee
static char receivedString[150];
int strIndex = 0;

while (xbee.available()) {
char c = xbee.read();

if (c == '$') { // End of packet delimiter
  receivedString[strIndex] = '\0'; // Null-terminate the string
  processReceivedData(receivedString);
  strIndex = 0; // Reset the index for the new packet
} else {
  if (strIndex < sizeof(receivedString) - 1) {
    receivedString[strIndex++] = c;
  }
}

}
}

void processReceivedData(const char* packet) {
char* token = strtok((char*)packet, ", ");

int receivedTeamID = atoi(token);
token = strtok(NULL, ", ");

char receivedTime[9]; // To store 'hh:mm:ss'
strncpy(receivedTime, token, sizeof(receivedTime));
receivedTime[sizeof(receivedTime) - 1] = '\0'; // Null-terminate the time string
token = strtok(NULL, ", ");

int receivedCount = atoi(token);
token = strtok(NULL, ", ");

char receivedMode = token[0];
token = strtok(NULL, ",");

char receivedState[20]; // Adjust the size as needed
strncpy(receivedState, token, sizeof(receivedState));
receivedState[sizeof(receivedState) - 1] = '\0'; // Null-terminate the state

// Perform any further processing or actions here

// Print the received data
Serial.print("TeamID: ");
Serial.println(receivedTeamID);
Serial.print("Time: ");
Serial.println(receivedTime);
Serial.print("Count: ");
Serial.println(receivedCount);
Serial.print("Mode: ");
Serial.println(receivedMode);
Serial.print("State: ");
Serial.println(receivedState);
Serial.println();
}

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