Level-Shifter for XBee & Raspberry Pi

Some projects have mixed supply voltages (e.g. 5 Volt and 3.3 Volt) and sometimes integrated circuits don't work with those unequal signal levels - or worse get damaged by the higher level supply signals.
Level shifter pcb

In case of the XBee which is driven by 3.3 Volt up to now I added a simple resistor divider to get the signals down to the lower supply level (see this older post ). But even if you feed the XBee without translating the different supply levels, I never got any problems (but I wouldn't recommend).

It might look slightly different with the Raspberry Pi, so to be on the safe side I built a simple 2-bit bidirectional voltage-level translator circuit for the alleged thin-skinned RasPi. You just need four 10k resistors, two BSS138 (N-Channel Logic Level Enhancement Mode Field Effect Transistor) and two four-pin headers.

I etched the board by myself but if you want to take the short way, there are already breakout boards and ICs available (e.g. Sparkfun Logic Level Converter, TXS0102 from Texas Instruments or ADuM1250/ ADuM1251 from Analog Devices).

Anyway I wanted to do some practice with my favourite pcb layout software Eagle and designed this simple pcb.

How does the level shifting work? If nothing happens on the bus (in this special case on the I2C-bus, thats what the pcb is labled for, but it also works with RX/ TX or any other 2-bit bidirectional digital purposes) all signals are pulled high by the 10k resistors. If either side goes low, the N-Channel MOSFET steps in and also pulls the signal line low, either because it turns on (low level side) or passes through the body diode (high level side).


Electronic compass

Just a note to a little project I'm building at the moment - an electronic/ digital compass:

There is no XBee involved - but a Nokia5110 lcd display, an Arduino Nano, a 2-axis compass module (HDMM01) and a HCF4050 for level-shifting. Of course you could add a XBee if you are using the compass for a robot or other mobile project.

And yes - the Halloween project is still to be posted. Just give me some more time.


Project XSkull

Halloween. Early darkness in fall. Pumpkins everywhere. Little kids in fancy costumes demanding candies.

XSkull with glowing eyes and moving jaw
So why not greeting them appropiate with an Arduino-based project combining a skull with red glowing and fading eyes and moving jaw which is servo operated and XBee-remote controlled. Haze in the dark from a fog machine which is radio controlled and triggered via XBee. Where the status of the heating-up process is reported back to the remote control where an illuminated switch is lit when the fog machine is ready? Where another switch can control a light or sound source?

That's what I will present in the next weeks until Halloween. Hardware, Arduino-Sketches and XBee configuration will be explained. For the beginning here are some photos. Have fun!

Remote control
 The remote control consists of an enclosure where an Arduino nano and a XBee are the main parts. With a sliding potentiometer you are remote controlling the moving of the skull-jaw. The red momentary switch shows the status of the heating-up process of the fog machine and signals it with the internal LED. If you push the switch fog will evaporate. Everything is driven by a 9 volt battery and the circuit can be activated by a rocker switch. One additional illuminated green switch can control another source like light or sound and signal an additional status to the remote control.

Fog machine

A servo which is connected to an Arduino Uno in the brain of the skull controls the momentary switch on the fog machine so that there is no need to work with high voltage. The light of the bulb which signalizes the heating process of the fog machine is analyzed by a light dependent resistor (LDR) which reports the resistance to the Arduino Uno which then sends the value via XBee to the remote control and lights the LED on the red fog switch when the fog machine is ready.


XBee Internet Gateway now for Windows, Linux and Macintosh

The XBee Internet Gateway - an open-source project written in Python - is now released to be run under Windows, Linux and Macintosh (XBee Internet Gateway Software).

Before you had to connect a Digi ConnectPort or any other form of XBee/ Ethernet combination to feed data through your XBee(s) into the internet. Now you just connect the XBee on a USB adaptor to your PC and run the XBee Internet Gateway software.

Carefully read the installation instructions, because your XBee firmware needs some special settings to connect to XIG. After this it should look like this:

XIG Windows software displayed in browser


Raspberry Pi and XBee

XBee perfboard hooked up to the Raspberry Pi
One nice gadget to play with is the quite new Raspberry Pi. I added a XBee (Coordinator AT) to the RasPi and sent some serial data to an Arduino UNO (and back) with a XBee attached (Router AT) via serial terminal (minicom) and Python.

The RasPi is running on Debian wheezy and the perfboard is connected via two row header sockets to the GPIO pins.

The 3.3V for the XBee is directly coming from Pin 1 of the GPIO-Header (GND from Pin 6), DOUT is connected to Pin 10 (GPIO RXD) and DIN to Pin 8 (GPIO TXD). I didn't test it with a XBee Pro attached, this will certainly draw too much current from the RasPi. The 3.3V supply only delivers 50mA as per this wiki . This is fine with the normal XBee which has 40mA max. current demand as per datasheet. If you need more current (XBee PRO needs 295mA@3.3V when transmitting with maximum output power) you could use the 5V power source with a subsequent voltage regulator as mentioned in the blog entries before. Be careful to use a voltage regulator with enough capabilities to deliver ample current.

Still enough legroom for the Raspberry Pi
One big advantage beside being wireless is that there is no level converter needed as the signals are 3.3V TTL to and from the Raspberry Pi.

To get the whole thing working you have to modify some settings in Debian wheezy. There is a nice walkthrough in this blog.

If you want to communicate via Python you have to get pyserial (sudo apt-get install python-serial or sudo apt-get install python3-serial for Python3). Example code for Python2 to send a value to the Arduino would look like this:

import serial

For Python3 you would have to change the last line to:


to send as a String.

On the Arduino side you could read the incoming data with Serial.read().

Connecting the whole thing together gives a huge amount of opportunities for future projects as one can use the combined cpu power/ linux system/ graphic abilities of the Raspberry Pi and the microcotroller skills and shields of the Arduinos - everything wirelessly connected in a mesh network.