ATMega168 + Xbee Explorer + GPS

Hello guys :) !

I have a little problem. I want to interface a GPS with my ATMega168 (this one : but I also want to use an Xbee with my ATMega168.

Both are communicating through serial port (using pins TX and RX, 2 and 3 on the 168).

How to interface both of them on the microcontroller ?

This may be a noobish question, I've looked on the forum but didn't find answers, so sorry in advance !

Thanks for your answers !

Best regards,


Hi Clément,

You use software serial. This immitates a hardware serial port (UART) with a software driven serial port. Check out the following for information and an example:

Basically you include the SoftwareSerial Reference and then declare the pins you want the Tx & Rx pins to be on with:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

And then you can use it the same as the normal serial port:

// set the data rate for the SoftwareSerial port
  mySerial.println("Hello, world?");

There are limitations but read the linked site and try it out.


Hi Glenn and Thanks for your answer :) !

I just found Software Serial. I even found an application with the GPS I'm using.

I was just afraid this might be too slow. My Atmega168 will do a lot : - analog humidity sensor - I2C pressure sensor - 3-axis analog gyro - GPS - microSD data log - Xbee transmit

So it might be hard for the AVR to process all these data (I need data every 0.1 second), what do you think ?

This is why I wonder whether a handier solution exists (multiplexing ?) or not.

Thanks for the tip anyway ;)

Yeah sorry I don't know how much it'l affect the speed.

I do know you can miss data on the software serial port if you don't scan the port frequently enough. You could use a timer interrupt to check for new data so you don't miss any?

Are you going to be Tx and Rx on both serial ports? Is one going to get used less frequent? If you are only using Tx on one serial use it on the SoftwareSerial port.

Any notes of the application? You have similar devices as my project :)

Thanks for your help ;) !

I'm working on a CANSAT project (for more info : )

The radio transmission using Xbee uses only TX I think. I'll see if I can switch this one to softwareserial.

But I'm afraid SoftwareSerial would be less reliable than regular Serial... The goal is to transmit sensor data and NMEA messages from GPS live, through the Xbee.