# XBee + Arduino

**URL:** <https://forums.digi.com/t/xbee-arduino/17997>\
**Category:** XBee Programamble (S2C & 900 HP)\
**Tags:** arduino-xbee, xbee-900hp, arduino, xbee-pro, xbee\
**Created:** [February 6, 2017, 11:29am UTC](https://forums.digi.com/t/xbee-arduino/17997 "2017-02-06T11:29:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwanito](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@rwanito](https://forums.digi.com/u/rwanito)\
**Post date:** [February 6, 2017, 11:29am UTC](https://forums.digi.com/t/xbee-arduino/17997/1 "2017-02-06T11:29:46Z")

</div>

Hi !  
I have 2 XBee Pro with one a shield ( Wireless shield for Arduino ) and a ftdi with a Xbee connected on it.

So, I have created a datalogger which saved some data on a sd card. When I receive 5 char from my XBee server ( on the ftdi, remote by XCTU ), normally i receive the sd card data on the XCTU software.  
But ! It doesn’t work…

however, i’ve set all my XBee with XCTU the 9600 baud and it works…  
When i changed it with 115200 It doesn’t work… But, one day it was working… not today…

My code : ( Commentaries are in french but it’s not important )

// Première version du programme ///  
////////////////////////////////////

// Librairies //////////////////////  
#include // SD  
#include // SD

#include // RTC  
#include “RTClib.h” // RTC

#include // XBee

////////////////////////////////////  
// Declaration des variables ///////  
////////////////////////////////////  
int DHAB\_val=0; // Permet de sotcker la valeur qui sera lue dans le DHAB  
int DHAB\_val\_count=0; // Permet de compter le nombre de fois que la valeur est lue dans le DHAB  
String XBee\_val=“”; // Permet de stocker la valeur qui sera lue dans XBee ( Reception )  
int Total\_DHAB\_val=0; // Permet de stocker les valeurs du DHAB lues qui seront ensuite traitées pour en faire une moyenne  
int DHABpin=0; // Ici un potentiomètre  
File myFile; // Fichier créé dans la microSD  
String filename;  
RTC\_DS1307 RTC; // Declaration du module RTC  
SoftwareSerial XBee(0, 1);// RX, TX pour le XBee

// Variables “Debug” ///////////////  
int DELpinRouge=7;  
int DELpinVerte=6;

void setup() {  
initialiser\_rtc();  
initialiser\_fichier();  
initialiser\_xbee();  
pinMode(DELpinRouge, OUTPUT);  
pinMode(DELpinVerte, OUTPUT);  
}

void loop() {  
digitalWrite(DELpinVerte, LOW);  
if(XBee.available()==5){ // Si XBee reçu  
digitalWrite(DELpinVerte, HIGH); // Pour l’instant on allume juste une led

```
//On va envoyer le fichier
XBee.println("Debut de l'envoie...");
myFile = SD.open(filename, FILE_READ);
while(myFile.available()){
  XBee.write(myFile.read());
}
myFile.close();
XBee.println("");
XBee.println("Fin de l'envoie...");

while(XBee.available()){
  XBee.read(); // Vide le buffer
}

```

}  
else{ // Sinon, on enregistre les données

```
  if(DHAB_val_count&lt;=1000){
    DHAB_val_count=DHAB_val_count+1; // Le but étant de faire une moyenne toutes les 1000 valeurs ( soit une moyenne toutes les secondes )
    DHAB_val=float(analogRead(DHABpin))*400.0/1023.0-200.0; // On converti la valeur en A
    Total_DHAB_val=Total_DHAB_val+DHAB_val; // On additionne avec les valeurs lues précedemment
    DHAB_val=0; // On reset
    
  }
  else{
    DHAB_val_count=0; // La boucle étant dépassée, on reset
    Total_DHAB_val=Total_DHAB_val/1000.0; // On fait la moyenne
    sauvegarder_dans_fichier(Total_DHAB_val); // On sauvegarde dans le fichier
    Total_DHAB_val=0; // On reset
  }    

```

}  
}

void initialiser\_fichier(){  
SD.begin(4);  
DateTime now = RTC.now();

```
int jour=now.day();
int mois=now.month();
int annee=now.year();
int heure=now.hour();
int minute=now.minute();
filename=String(heure)+String(mois)+String(jour)+".CSV"; //BUG je n'arrive a donner le nom que je veux... Donc format HHMMAA.csv

if(!SD.exists(filename)){
  myFile = SD.open(filename, FILE_WRITE);
  myFile.println("Reception depuis XBee");
  myFile.println("Date (JJ/MM/AA);Heure (HH/MM/SS);Donnees (A);"); // Donc 3 informations par ligne : Date/Heure/Donnee
  myFile.close();      
}

```

}

void initialiser\_rtc(){  
Wire.begin();  
RTC.begin();  
RTC.adjust(DateTime( **DATE** , **TIME** )); //Met à jour l’heure directement depuis le PC  
}

void initialiser\_xbee(){  
XBee.begin(115200);  
}

void sauvegarder\_dans\_fichier(int Total\_DHAB\_val){  
myFile = SD.open(filename, FILE\_WRITE);  
DateTime now = RTC.now();

myFile.print(now.day(), DEC);  
myFile.print(“/”);  
myFile.print(now.month(), DEC);  
myFile.print(“/”);  
myFile.print(now.year(), DEC);  
myFile.print(“;”);

myFile.print(now.hour(), DEC);  
myFile.print(“:”);  
myFile.print(now.minute(), DEC);  
myFile.print(“:”);  
myFile.print(now.second(), DEC);  
myFile.print(“;”);

myFile.print(String(Total\_DHAB\_val)+“;”);

myFile.println(“”);  
myFile.close();  
}

Some idea ?  
How Can i configure my XBee ? Coordinator, end devices it’s important ?  
Thanks !

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [February 6, 2017, 2:06pm UTC](https://forums.digi.com/t/xbee-arduino/17997/2 "2017-02-06T14:06:42Z")

</div>

which xbee modules and firmware versions are you working with?

---

<div class="post-metadata">

**Author:** ![rwanito](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@rwanito](https://forums.digi.com/u/rwanito)\
**Post date:** [February 8, 2017, 9:08am UTC](https://forums.digi.com/t/xbee-arduino/17997/3 "2017-02-08T09:08:39Z")

</div>

Hi !  
XCTU says :  
product family XBP24  
Frimware version 10ef

Both are like it  
any idea ?  
thanks

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [February 8, 2017, 9:44am UTC](https://forums.digi.com/t/xbee-arduino/17997/4 "2017-02-08T09:44:13Z")

</div>

The radio in question is defaulted at a baud rate of 9600. If you want it to communicate at a different rate, you must not only change the baud rate on your processor but you also need to enter command mode and change the baud rate (BD) on the radio.

---

<div class="post-metadata">

**Author:** ![rwanito](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@rwanito](https://forums.digi.com/u/rwanito)\
**Post date:** [February 9, 2017, 11:41am UTC](https://forums.digi.com/t/xbee-arduino/17997/5 "2017-02-09T11:41:12Z")

</div>

How? By XCTU?  
When all is set on 9600, it’s work.  
But when i change it by 115200 on XCTU for the 2 XBee, sending works but not receiving ( By XCTU )

I must configure it on Windows?  
Thanks!

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [February 9, 2017, 11:46am UTC](https://forums.digi.com/t/xbee-arduino/17997/6 "2017-02-09T11:46:59Z")

</div>

XCTU is not for sale. It is downloadable from Digi’s support site. [https://www.digi.com/support/productdetail?pid=3352&amp;type=documentation](https://www.digi.com/support/productdetail?pid=3352&amp;type=documentation)

Yes, you would also need to configure your Windows com port to also be at that rate for it to work.
