Home/Support/Support Forum/help required for Xbee s2c connected to RasPi3 using USB explorer (ch340g)

help required for Xbee s2c connected to RasPi3 using USB explorer (ch340g)

0 votes
I'm new to Xbee, I have bought Zigbee (XBee S2C) (2 no.'s) and Uni4 XBee USB adapter (https://www.amazon.in/Uni4-ZigBee-Adapter-Board-Interface/dp/B01HL0TKVQ/ref=sr_1_6?ie=UTF8&qid=1531374014&sr=8-6&keywords=zigbee) for it from amazon.in . I have configured the XBee modules using XCTU in windows machine and tested message passing in it and it works perfectly.

Now I'm stuck in the writing program (preferably in C language) to make it work with Raspberry Pi 3. I have two Raspberry Pi 3 models, I want to connect XBee using Uni4 XBee USB adapter to the Raspberry Pi. I want to make program which will transmit the message from one Raspberry Pi to another using XBee. I tried to search a lot and couldn't get exactly what i wanted. Most of the guide explain the program to transmit the message when XBee is connected to Raspberry Pi GPIO pins but not as serial USB.

Please help me out either with a sample program or with a tutorial which explains according to my needs.

PS: Uni4 XBee USB adapter is same as sparkfun USB explorer (https://www.sparkfun.com/products/11697) and uses ch340g UART to USB interface.
asked Jul 12, 2018 in RF Solutions and XBee by VinayakaSp New to the Community (0 points)

Please log in or register to answer this question.

2 Answers

0 votes
I'm no expert here, but if you are sending serial data between two XBee's, the easiest way is just to use transparent mode (AT mode).
I have two S2C modules, one taking serial data from a GPS module, transmitting that data to a second S2C XBee, both configured as API disabled, and they operate like a cable link. I read the data at one end using an FTDI module (or CH340G) The GPS module has TX and RX pins - these connect to the RX and TX of the XBee, then at the other end, the second XBee's TX and RX connect to the RX and TX of the FTDI module. It's called a virtual cable and works really well. All you need to do is set the PAN ID on both to the same value like 1234. I know nothing about RPi, only Atmega
answered Jul 12, 2018 by Phil_S New to the Community (18 points)
Thank you for taking out your time to answer me.
Actually I didn't get your answer since I don't have any electronics background.

I have two Raspberry Pi (lets say 2 computers/laptops running debian OS). I'm connecting XBee S2C to laptop using USB explorer (CH340G). In python i can simply send data importing Serial library and assigning serial instance as /dev/ttyUSB0.
I want to know similar thing for C language.
If you don't have any electronics background, you are going to struggle. As I understand it, you want to send data (serial) from one device to another. Two XBees in transparent mode will do that. The S2C modules can be set up in XCTU - you do have that?- in transparent mode. I don't understand what you mean by similar thing in C. I think you need to get the basics right and get two XBees, one with a serial device attached as a transmitter like a GPS module and at the second XBee, connect an FTDI (USB to serial). You will see the data from the GPS unit being transferred into a terminal program like CoolTerm or better still into XCTU. It's very straightforward, but starting out with RPi is complicating things. Arduino uses C, so that might be a better place to start. Arduino has many serial libraries. Arduino can communicate with RPi using something like Processing language, but I find it too complicated. The advantage of using something like a GPS module is that it chucks out serial data just by powering it up. I'm assuming you have Digi's own software (XCTU). I would also recommend Faludi's book "Building Wireless Sensor Networks" for setting up Series 2 modules.
Good luck, it will work
Yeah I have XCTU and tested on it ny installing it into 2 machine plugged with XBee S2C using USB adapter.
It works perfectly.
I can't use Arduino since the requirement demands the Raspi.
Since python gives "serial" library to access USB serially using "/dev/ttyUSB0" I searched for any related "Serial" library for C. But I'm unable to get it.
The concept is two machines communicate with each other using XBee instead of LAN, so I really cant introduce the GPS module in between.
Obviously you don't need a GPS module, but I just used it at one end as a good source of serial data - it just saved the effort of generating data.
If you've got XCTU working at both ends and the data looks good, you have your link established.
I can't help you with RPi, but in Arduino it would be as simple as "while serial available" and doesn't need any other libraries unless you want to use pins other than the hardwired TX and RX - then you would use an Arduino library like SoftwareSerial, but it's never going to be as good as the hardware UART. There are articles and publications for combining Arduino and RPi - something like "Home automation with Arduino and Raspberry Pi" would give you some leads.
I'm sure you will get there, but this is as far as my knowledge goes. Have you tried the forums for RPi or Stack Exchange? I suspect that you won't get too far in this forum as your requirement isn't covered much and interest is limited.
Good luck and it would be nice to know if you succeed.
0 votes
With the XBee USB adapter connected to the USB port of the Raspberry pi, have you determined the path to the port? For example: Using the command
"ls /dev"
If you use that command you will find lots of stuff among which you will likely be something like
"/dev/ttyUSB0"

Let's say you know the path is "/dev/ttyUSB0" and you have the XBee setup for transparent mode, a baud of 9600 and the xbee escape character set to the hex equivalent of '\n'.

simple python code...

import serial

xbee = serial.Serial("/dev/ttyUSB0", 9600)

xbee.write("hello\n".encode("utf8"))

xbee.close()

I haven't tried this to verify its functionality. It is an example that could perhaps get you started.
answered Jul 19, 2018 by 6565827978 New to the Community (1 point)
...