How can we enable serial communication between an XBee S2C and a Raspi 3 through the USB port?

For this purpose, I use Sparkfun's XBee explorer dongle. I have several of this combination to create a ZigBee network and test a protocol coded in C. However, I am having problems at reading from /dev/ttyUSB0. BTW, the problem may be at the sender side.

The XBees are running with the serial interface configuration given below:

115200 baudrate
No parity
1 stop bit
3 character times for packetization timeout
CTS flow control is enabled
RTS flow control is disabled
API mode is enabled
API output mode is native

Therefore, I initialized the port in my code as given below:

int initport(int fd)
int portstatus = 0;

    struct termios options;
    // Get the current options for the port...
    tcgetattr(fd, &options);
    // Set the baud rates to 9600...'textB' un
    cfsetispeed(&options, B115200);
    cfsetospeed(&options, B115200);
    // Enable the receiver and setSTX local mode...
    options.c_cflag |= (CLOCAL | CREAD);

    //options.c_cflag &= ~PARENB;
    //options.c_cflag &= ~CSTOPB;   //When these are disabled the XBee receives data.
    options.c_cflag &= ~CSIZE;
    options.c_cflag |= CS8;
    //options.c_cflag |= SerialDataBitsInterp(8);           /* CS8 - Selects 8 data bits */
    options.c_cflag &= ~CRTSCTS;                            // disable hardware flow control
    options.c_iflag &= ~(IXON | IXOFF | IXANY);           // disable XON XOFF (for transmit and receive)
    //options.c_cflag |= CRTSCTS;                     /* enable hardware flow control */

    options.c_cc[VMIN] = 200;     //min carachters to be read
    options.c_cc[VTIME] = 5;    //Time to wait for data (tenths of seconds)

    // Set the new options for the port...
    //tcsetattr(fd, TCSANOW, &options);

    //Set the new options for the port...
    tcflush(fd, TCIFLUSH);
    if (tcsetattr(fd, TCSANOW, &options)==-1)
        perror("On tcsetattr:");
        portstatus = -1;
        portstatus = 1;

    return portstatus;

I wanted to ask this question here because I believe I need to make some modifications in some files such as /boot/config.txt and/or /boot/cmdline.txt. In my search in the web, this kind of modifications popped up but they didn't work in my case.

Finally, the Raspis are running the latest version of Raspbian Jessie and Linux kernel 4.9.35-v7+.

$uname -a
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

$cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION="8 (jessie)"

Please don't hesitate ask any other detail about my setup.

Thank you in advance.

2 Answers 2


It's been a while since I posted this question, so I even forgot I asked such a question. The problem was about activating the XBee S2C. The only thing that I had to do is to write a 'U' and 'B' to the serial bus. After that, the device is ready to listen the data you will write to it. I mentioned this problem and the solution in our journal paper which can be accessed at https://authors.elsevier.com/a/1XK7x3sf~xzj7o

Thanks, again!


The dongle you show here, uses the FTDI chip, so this is a basic USB to RS232 converter. In Ubuntu, you can make it to work easily by adding your user to the dialout and the tty groups. See this thread for more information: UDEV rules for FTDI not completely working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.