I bought 3 xbee s2c modules (for the first time) for my personal hobby project.
I also bought 3 adapter boards from amazon https://www.amazon.in/dp/B00PU032DM/ thinking that I could setup the radios with XCTU and use the same modules with arduinos for tx rx communication as well.
Since its the first time I'm into the xbee world, I'm a bit struggling to make this work with the arduino.
The setup with XCTU all went fine and I can see the radios are talking to each other (on XCTU serial).
However I am not able to make this work with the arduino.
I plugged the adapter board with the arduino mega Serial1
XBEE TX to MEGA RX1
XBEE RX to MEGA TX1
xbee adapter plugged with external supply with this board
Both XBEE, Arduino baud rates are set to 9600
added code to the arduino to display the Serial1 input on Serial so that I can see it on the arduino serial viewer.
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
But I cannot see any communications from XBEE on the serial (tried all 3 radios).
I should be missing something here or doing something very silly.
Is it that the adapter boards cannot be used to plug it to the arduino?
or is it something like logic level shifter required?
A standard Arduino board usually runs at 5 volts and a logical high is above 3.3 volts. An Xbee board runs at 3.3 volts and a logical high higher than 3.3 can damage the input if not the radio. You can run the ATmega chip at 3.3 volts and the logic levels will be the same. Or, you can do some level shifting... In either case, you need pull-up (10K) to logic high resistors on the Rx side.
Perehama:
A standard Arduino board usually runs at 5 volts and a logical high is above 3.3 volts. An Xbee board runs at 3.3 volts and a logical high higher than 3.3 can damage the input if not the radio. You can run the ATmega chip at 3.3 volts and the logic levels will be the same. Or, you can do some level shifting... In either case, you need pull-up (10K) to logic high resistors on the Rx side.
Thanks for this, will take care of it. But my primary question remains, I'm not seeing any serial communications with the arduino still. Not sure what is wrong here. I'm behind that problem really.
mithunrockey:
Thanks for this, will take care of it. But my primary question remains, I'm not seeing any serial communications with the arduino still. Not sure what is wrong here. I'm behind that problem really.
Are you looking at the serial port pin with an oscilloscope? What is your setup? Where are you expecting to "see" serial communication?
The said solution dint work for me as I checked on a breadboard.
But I think it should be something related to this as I can see the flawless communication on XCTU between modules all time.
Please also let me know your all thoughts on this. Many thanks in advance.
I did a bit more digging today to make sure the tx/rx lines are actually passing data. For that I connected the adapter with the xbee to a usb-ttl converter and checked the serial at baud 9600 on my terminal (mac). The terminal screen did displayed the transmitted data from the coordinator correctly.
So it should be something between the arduino<->xbee, maybe arduino needs a 5v RX signal (arduino is capable of reading 3.3v signals in my knowledge).
It could be a problem with DIN / DOUT not being pulled high / low (sorry i'm not an expert to comment on this section).
I'm fairly new to the IOT world, all my experience is with the web development side. This is something I do for myself as a hobby project.
I have googled a lot to see anyone explaining and doing the s2c-arduino, but all are of just terminal communication display, that I got alright already.
Guys I appreciate any of your help on this. Please let me know.
@GrOnThOs
once again, the difficulty i'm facing is with Xbee S2C modules only. Tried an S1 version which was good with arduino. Only S2C modules have the issue.
@JohnRob
Both modules are plugged into the adapter and one connected via usb port with XCTU, which is the coordinator and sending looped serial data to the router (other module).
The other module is connected to the usb port with a usb to ttl converter and I view the output of that port on terminal.
This all works very fine and I can see the incoming payload also on terminal. But once the xbee is connected to the arduino (Serial1 on mega or software serial on UNO)
Xbee TX to Arduino RX
Xbee RX to Arduino TX
The serial is not displaying anything, also it do not send out any payloads to the coordinator.
I believe it should be something
between the arduino<->xbee, maybe arduino needs a 5v RX signal (arduino is capable of reading 3.3v signals in my knowledge).
It could be a problem with DIN / DOUT not being pulled high / low (sorry i'm not an expert to comment on this section).
Dear Perehama, sorry it does not help me much. I'm totally an electronics noob, I cannot even find the value of a resistor without google help with color codes.
I started as a web developer before 18 years, and I'm at my own firm for the past 12 years. I havnt really coded for the past 6 years. But these all are my interests and happiness that I spend all my free time with.
sorry thats my situation now.
The one I'm working on is a home automation project (for my home), with arduinos and xbees. I plan to add an arduino,xbee,relay for each switch boxes in the house.
The coordinator xbee/arduino/ethernet-shield will be talking to a web-server which runs on node.js/NoSQL. Communications are done through MQTT protocol and the exchanges between nodes are with JSON
These all was setup a couple of months before (with the ESP and mesh library) and was working fine. The only issue which I had was with the occasional crashing of ESP's. While I appreciate these small modules, things where little unstable.
Ok, so I know the basics of serial communications. And the following is what I have on my table now.
The xbees I can see are well communicating (looking on xctu serial)
To make sure the RX have signal, plugged the output from the shield with a usb-ttl adapter and checked through the terminal (of my mac)
But when it is plugged to my arduino, I cannot see any data that is received. I have tried with UNO (software serial) and MEGA (Serial1).
As I saw on sparkfun recommendation,
I have added a pullup resistor between 3.3 and DIN
Removed the RSSI led
After this, I noticed the TX led on the mega started to blink when a message is sent from the coordinator (I think its the acknowledgement back to the coordinator). But still the RX led does not blink, nor it have an output on serial.
in your pictures, I see wires going directly from the xbee to the mega. I see a resistor crudly fashioned to the side of the xbee. The mega operates at 5 volts. The xbee operates at 3.3 volts. The logic high output for the Xbee can be 2.3 volts at minimum (VCC of 2.8 and Voh of VCC-0.5) which is well outside the minimum (3 volts) of the Mega. You NEED level shifting between the two. You CANNOT directly wire one to the other with much success. In all cases, you should be operating in transparent mode. You can switch to API mode, once you have the two radios working in transparent mode AND you know the reasons and differences between the modes and why you want to be in API mode AND how to make that work.
Thanks Perehama, I had also thought about this in the first post. But also had read somewhere that the logic output of xbee is fine for Arduino to read but it requires a logic shifting for xbee since xbee is expecting only 3.3 volts.
But how come many others just manage to connect this directly without all this mess
The issue should be that as you said. Will try to make a level shifter myself very soon. Thanks for your input
Page 15 of the XBee S2C datasheet states Voh is .82xVcc minimum, which can be 2.7 volts if Vcc is 3.3 volts.
Page 355 of the ATmega2560 datasheet states Vih must be .6xVcc minimum, which is 3 volts if Vcc is 5 volts.
Yes, it can work sometimes, but it is out of spec. I have included an illustration for you.
Also, you have a less than ideal setup with the wire leads, pin connectors and other breadboard components that add ESR to drop Voh further out of spec.
I bought a couple of logic level converters like this one https://www.sparkfun.com/products/12009
checked the voltages, replaced some faulty jumper cables and and it finally worked!
Thank you once again for your input on this which helped me solving this problem.
mithunrockey:
But how come many others just manage to connect this directly without all this mess
I think this is a perpetuated myth because a lot of other 5 Volt logic things, ICs and other microcontrollers, will accept 2.7 as a logic high, but ATmega will not.
Glad to see it working for you.