Issues communicating between Zigbee modules

Hi. I am doing a project about transmiting information between two computers, in this case 2 Arduino UNO R3, using Xbee modules. Before anyone asks, the modules are well configured and communicate with one another in XCTU. this to be a code issue. The informations are supposed to be temperature and humidity. The sensor works just fine but it does not seem to show my information on the serial monitor. I would love some help in correcting my code to make this work. I am not that experienced when it comes to Arduino and even less when it comes to Zigbee.

Transmitter code

#include <Wire.h>
#include <XBee.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h> 

#define DHTPIN 2          
#define DHTTYPE DHT11     

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); 

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();

void setup() {
  Serial.begin(9600);
  dht.begin();
  lcd.init();  
  lcd.backlight(); 
  xbee.begin(Serial);
}

void loop() {
  // Introduce o întârziere de 3 secunde pentru polarizarea senzorului
  delay(3000);

  // Citirea umidității și temperaturii de la senzor
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // Verifică dacă citirea senzorului este validă
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Eroare la citirea senzorului DHT");
  } else {
    // Curăță ecranul LCD și setează cursorul la începutul ecranului
    lcd.clear();
    lcd.setCursor(0, 0);
  
    // Afișează temperatura actuală pe primul rând
    lcd.print("Temp: ");
    lcd.print(temperature);
    lcd.print(" C");

    // Afișează umiditatea pe al doilea rând
    lcd.setCursor(0, 1);
    lcd.print("Umiditate: ");
    lcd.print(humidity);
    lcd.print("%");

    // Construiește pachetul de date pentru trimiterea prin XBee
    char data[50];
    sprintf(data, "Temperatura: %.2f C, Umiditate: %.2f%%", temperature, humidity);

    // Creează un pachet XBee pentru transmiterea datelor
    ZBTxRequest zbTx = ZBTxRequest(0x0013A200, 0x00000000, data);
  
    // Trimite pachetul de date prin modulul XBee
    xbee.send(zbTx);
  }
  
  // Așteaptă 5 secunde înainte de a actualiza din nou temperatura
  delay(5000);
}

Receiver code

#include <Wire.h>
#include <XBee.h>
#include <LiquidCrystal_I2C.h>

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();

// Adaptează adresa I2C a ecranului LCD la adresa corectă în funcție de modulul tău
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adresa I2C și dimensiunile ecranului LCD

unsigned long lastMessageTime = 0;
const unsigned long displayDuration = 5000; // Durata de afișare a mesajului în milisecunde

void setup() {
  Serial.begin(9600);
  xbee.begin(Serial);
  
  // Inițializează ecranul LCD cu adresa I2C și dimensiunile specificate
  lcd.init();
  lcd.backlight(); // Activează iluminarea ecranului LCD
  
  // Afisează mesajul de început
  lcd.setCursor(0, 0);
  lcd.print("Licenta");
  lcd.setCursor(0, 1);
  lcd.print("Probe");
}

void loop() {
  xbee.readPacket(); // Citește pachetul primit prin XBee
  
  if (xbee.getResponse().isAvailable()) { // Verifică disponibilitatea pachetului
    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { // Verifică tipul de pachet (ZB_RX_RESPONSE)
      // Obține datele primite
      xbee.getResponse().getZBRxResponse(rx);
      uint8_t* data = rx.getData();
      
      // Afisează mesajul primit pe ecranul LCD
      lcd.clear();
      lcd.print((char*)data); // Afisează datele primite ca șir de caractere
      lastMessageTime = millis(); // Actualizează timpul ultimului mesaj primit
    }
  } else {
    // Verifică dacă a trecut perioada de afișare a mesajului de început
    if (millis() - lastMessageTime >= displayDuration) {
      // Șterge mesajul de început
      lcd.clear();
    }
  }
}

Where in either sketch are you printing the values to the Serial monitor ?

I use an LCD 2x16 to shoe the information. the temperature appears on the LCD for the transmitter but not on the receiver code. I do know there is an issue, but I do not know where exactly and how to correct

No wonder I am confused

I am sorry for the confusion. I am using both the serial monitor and the LCD to see the information. The main objective is to see the information on the LCD but it does not work, neither on LCD nor on serial monitor. For the last few tests I even removed the LCD and used only the serial monitor. I am sorry for the confusion again. I am trying to print the values directly in the serial monitor. On the transmiter side everything seemed ok, but nothing from the transmiter shows up on the receiver. I am sorry if you are still confused by what I said. I may have not understood your question either. And I am a bit of a noob too. Thank you for your time, btw!

How is the Zigbee module connected to the Arduino ?

With an Xbee Shield V03

Which pins of the Uno does the shield use ?

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