Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Communication between Arduino through Xbee not working.

Status
Not open for further replies.

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Hi all,I am trying to design a mesh network using Xbee s2 and arduinos.In the first stage I am trying to create communication between two arduinos using Xbee s2,I am using the AT mode.I have programmed the arduino as follows

sender:

Code:
void setup() {
Serial.begin(9600);
}
void loop() {
 Serial.println("1"); //turn on the LED
delay(1000);
Serial.println("0");//turn off the LED
delay(1000);

  
}

Receiver
Code:
int ledPin = 13;  // use the built in LED on pin 13 of the Uno
int state = 0;
int flag = 0;        // make sure that you return the state only once

void setup() {
    // sets the pins as outputs:
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);

    Serial.begin(9600); // Default connection rate for my BT module
}

void loop() {
    //if some data is sent, read it and save it in the state variable
    if(Serial.available() > 0){
           state = Serial.read();
      flag=0;
    }
    // if the state is 0 the led will turn off
    if (state == '0') {
        digitalWrite(ledPin, LOW);
        if(flag == 0){
          Serial.println("LED: off");
          flag = 1;
        }
    }
    // if the state is 1 the led will turn on
    else if (state == '1') {
        digitalWrite(ledPin, HIGH);
        if(flag == 0){
          Serial.println("LED: on");
          flag = 1;
        }
    }
}
:

I am using Arduino UNO and MEGA,And configured Xbees using XCTU.I am connecting Xbees directly to the Arduions(without any shield,I have two boards with MAX232 to configure the Xbees and also I am powering Xbee through this board because there is some inbuilt 3.3V regulator) and connected TX of Xbee directly to Arduino RX and Arduino TX connected to Xbee RX through a voltage divider.

In the STEP-1 I connected arduinos using wires UNO TX to MEGA RX and UNO Rx to MEGA Tx and its
working fine.

In the STEP-2 I replaced the wired connection with Xbees but its not working

Then in STEP-3 I replaced the sender Arduino with my laptop( I used XCTU) and its working perfect without any problem.When I type 1 in terminal box the LED turned ON on and a 0 turned OFF the LED

I am attaching the YouTube video link of the 3 steps(something that I captured with my camera)

https://www.youtube.com/watch?v=4lz_BMZ3AY4&feature=youtu.be
https://www.youtube.com/watch?v=rLVNddzoLF0&feature=youtu.be
https://www.youtube.com/watch?v=6B_GzSBNvas&feature=youtu.be

Please help me solve this problem,I am working on this for the past couple of days,watched a lot of tutorial videos,read a lot and tried different methods but I couldn't solve this...
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Try the attached Sketch for receiver. It uses Serial receive interrupt. Also you have to use voltage level translator on UART lines and power XBee from 3.3V pin of Arduino. If you connect UART lines of XBee directly to Arduino UART lines then XBee will get damaged because XBee work at 3.3V and Arduino UART lines are 5V TTL lines. So, please use voltage level translator which converts 5V of Arduino to 3.3V for XBee UART lines.

You have to use these shields to connect XBee to Arduino.

https://www.banggood.com/buy/Arduino-XBee-Shield.html
https://www.cooking-hacks.com/documentation/tutorials/arduino-xbee-shield
https://www.arduino.cc/en/Main/ArduinoWirelessShield
https://www.jayconsystems.com/js-xbee-shield-for-arduino.html

Code:
int ledPin = 13;  // use the built in LED on pin 13 of the Uno
char state = 0;
bit received = 0;

void setup() {
    // sets the pins as outputs:
    pinMode(ledPin, OUTPUT);
    digitalWrite(ledPin, LOW);

    Serial.begin(9600); // Default connection rate for my BT module
}

void loop() {
    
  if(received) {
    // if the state is 0 the led will turn off
    if(state == '0') {
        digitalWrite(ledPin, LOW);
        Serial.println("LED: off");      
    }
    // if the state is 1 the led will turn on
    else if(state == '1') {
        digitalWrite(ledPin, HIGH);
        Serial.println("LED: on");       
    }
    
    received = 0;
  }
}


void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    state = (char)Serial.read();
    received = 1;    
  }
}

- - - Updated - - -

So you still doing the light controlling projects where there will be wireless repeaters running on Arduino ? You switched from nRF24L01 to XBee for communication ?

I have done nRF24L01 communication using Arduino and Mirf library. If you still want the nRF communication system then I can write a code for you using Arduino's Mirf library.
 

Attachments

  • XBee_Comm.rar
    533 bytes · Views: 5
Last edited:

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Thanks for your reply.I used voltage divider here for the RX pin of Xbee, andI connected TX or Xbee directly to RX of arduino.

Thank you for sharing the code,but actually what is the use of serial interrupt receiver?.And is the shield is mandatory?

No,I am not going to use NRF24L01 because I need at least 500m range between two repeaters and I don't think the NRF chips can give this range.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
If you have any other code in the
Code:
void loop()
then Serial interrupt is a must otherwise you will miss data. Try this nRF24L01. They are cheaper. They come with Power RF Amplifier and antenna. They have a range of 1 Km.

https://www.ebay.com/itm/NRF24L01-P...ommunication-module-2-4G-1100m-/310651702557?

You can use voltage divider on UART lines of XBee but using a XBee Shield is better. With an XBee shield there will be no loose connections. The cheaper XBee Shields also use the voltage dividers to provide proper voltages to the XBee pins.

Arduino Nano and Arduino Uno are same just the board layout are different. What an Arduino UNO can do the same an Arduino Nano can do. You can buy this Arduino Nano IO Shield.

https://imall.iteadstudio.com/im120417016.html

It has an XBee and nRF24L01 socket and I have used both wireless devices with this IO Shield and they work fine. I have a few of those IO Shields. You need a credit card to buy them. If you don't have a credit card then I can buy them for you and send it to you. As you are in India it will not be a problem for me to send the IO Shield. They are of good quality. I have tested the Xbee and Mirf libraries with this IO Shield. They work fine.

With IO Shield your device will be neat.

https://wiki.iteadstudio.com/Arduino_Nano_IO_shield

On eBay they are selling for 11 USD but actual price is 5 USD.

https://www.ebay.com/itm/Wireless-S...RF24L01-for-Arduino-328p-7V-12V-/300929313707
 
Last edited:

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Okay,but my code is working fine and when I used to connect the two arduinos using two wires its working perfect,the problem is only when I use the Xbee module.And when I use XCTU on the transmitter side then also the system is working perfect,but when I try communicate between two arduins its not working,that is the problem,

I already know about the long range NRF chip,do you ever worked with this before?I mean in real hardware?
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Maybe the config of the XBees are not proper. Please read the XCTU configuration manual and do as mentioned in it. Yes, I have used XBee and also nRF24L01 with Arduino Nano IO Shield and Arduino UNO with Mirf and XBee libraries. They work fine. I have a system where 4 x Arduino Nano with nRF24L01 on each IO shield communicate with each other.
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Okay,I have a credit card so its not an issue to buy them.But if you have some of them with you I am ready to buy them from you,no problem with that if they are brand new and damage free,

Actually I followed each and every steps of XCTU based on different YouTube tutorial vdeos,but still that is not working.Do you think if I used this shield and NRF24L01 then I will be able to cover 3km with 6 of them?I mean do I get a minmum distance of 500m?
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
I think it is mostly a configuration problem. Yes, I have tested it and it works for 1 Km range. I have 10 IO Shields but they are being used in different applications and hence I cannot give you my IO Shields. As you have credit card (There should be VISA for doing international transaction) buy them from iTead. It will reach you within 15 days of ordering. Both links are Chinese.

The IO Shield has XBee Pro socket. Yours is XBee S2, right ? Before buying (If you are going to use XBees) then check the datasheet of XBee Pro and XBee S2 or whatever is yours and confirm that the pinouts are same. If the pinouts of power supply and UART doesn't match then you will not be able to use your XBee S2 in IO Shields Xbee Pro socket.
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Okay,thank you very much.I am planning to buy 3 of them for testing purpose and if they are working fine for my application then only I will buy more.So if you can give me 3 of them from your 10 then I greatly appreciate that.

If I get the shield then I will try the NRF24L01 first because as you know this one is cheaper than the Xbee.

Kindly let me know your thoughts on this
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
As I said earlier my Shields are used in working applications and hence I can't give you my Shields. Yes, nRF24L01 is cheaper. I will help you with the sketching.
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Oh okay,then the shields are already in use?..ok..do you know any similar shields available in India,because it will be better if I get this shield within a week and can test them,the 15 days is a long duration.
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Thank you fr sharing the links.But these seems really.Also I am looking for something available in India,as I mentioned you I can buy from Chinese seller for the final product,but I would like to test it first with 3 sets.So if you know some websites they are supplying these/similar sheets then kindly share the link

- - - Updated - - -

BTW is the code will be same for short range NRF24L01 and the long range one? I mean something similar to this

2 PCS NRF24L01+ 2.4GHz Wireless RF Transceiver Module + Free C Code for Arduino
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Yes,I know.I am looking for some adapter now to connect the NRF24L01 to Arduino,do you know any adapter that available in India?.BTW if you don't mind could you pls send me the code?
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
@milan.rajik ..I have already two short range NRF24L01 modules are with me,and also two arduinos Arduino UNO and MEGA2560.kindly let me know if you can provide code for this set up
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
The code examples are already there in the Mirf library. If you don't have Mirf library then istall it. Use the ping_client and ping_server sketches. The nRF's will communicate with each other.
 

pradeep_k_b

Full Member level 3
Joined
Dec 21, 2011
Messages
160
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,306
Location
Nilambur, India
Activity points
2,505
Okay,thank you very much.Let me check it

- - - Updated - - -

But I am using one arduino UNO and one MEGA,this example/library is based on UNO then is it possible to use it with MEGA2560?.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
SPI pin connections have to be changed in the code according Mega's SPI connections. Open the .cpp file in the Mirf library and see the pin connections. Better use two UNOs.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top