How-To: Raspberry Pi as a 3G/4G Router

Update: 15 April 2016 – Added information about which IP address to use and assigning static IP addresses for printers and servers

Recently I have needed to find an emergency alternative to my broadband due to the regional wide area network, Digital Region, being shut down, and the ISP Origin making a mess of getting all their cutomers onto ASDL. To get quickly back onto the internet, I have bought an ZTE MF823 4G Mobile Broadband Dongle as supplied by the badly named ‘three’ mobile phone company. As I have my own internal wired network, with multiple computers and ‘things’ there is a need to have something more sophisticated than just plugging the dongle into a single PC.

network diagram

Here is my recipe for setting up a Raspberry Pi as a router with an ZTE MF283 Dongle. In this setup all the computers are on a wired Ethernet connection using a switch for the network. The Pi has Raspbian Debian Wheezy installed (June 2014) with all the latest updates made. For testing, the dongle is plugged into the USB port via a powered hub, and the Pi connected to a switch with another PC running Linux Mint.

Which IP addresses to use?

In this How-To I am using the IP address range this is to avoid conflict with the cable router which uses the range (the DHCP server is switched off on the router). IPv4 addresses are split into three different ranges, the range – to gives a possible 65,536 addresses but for your home it is unlikely you’ll have more than 255 network devices, so we can simplify things by limiting the address range used to and avoid the troublesome world of subnet masking. is used as its been designated for use on private networks by the Internet Assigned Numbers Authority this is a well established convention and is best practice. Two other IPv4 address ranges are available for larger private networks: and with 1,048,576 and 16,777,216 available addresses respectively, the most suitable network class should be chosen for your network.

Setup the Dongle

This USB dongle has its own built in dialer so you do not need ppp or wvdial installed, it appears as a USB ethernet device on the Raspberry Pi. You will need a powered USB hub as the dongle can draw more power than the Pi can provide, the symptoms of too much of power being drawn will be the Pi behaving erratically or restarting unexpectedly.

With the dongle plugged in, check that it is recognised by the Pi with lsusb, it can be seen here as ‘ZTE WCDMA Technologies MSM’:

The device ID is 19d2. and 1405 is the mode, this should be 1405 – CDC ethernet. If it is not, try removing the micro-SD card and rebooting the Pi, the device modes available are:

  • 1225 – Default mode. USB Mass Storage Device + CD-ROM + card reader.
  • 1403 – Modem mode. RNDIS + Mass Storage Device.
  • 1405 – CDC ethernet
  • 0016 – Download mode

As the dongle also has a Mass Storage Device the Raspberry may not switch to CDC ethernet. If the mode does not change, try the following with usb-modeswitch:
$ sudo apt-get install usb-modeswitch
$ sudo usb_modeswitch -v 0x19d2 -p 0x1405 -d

I did not have to change the mode as it was correct already, and it didn’t change when I tried setting it as a Mass Storage device, I have not explored this any further.

When first plugged in the dongle was recognised as a ethernet device but it did not obtain an IP address:

if this is the case with you, add the following two lines to the end of sudo nano /etc/network/interfaces:
auto usb0
iface usb0 inet dhcp

the dongle provides its own address to the computer. Reboot, and you should see the obtained address:

The address is now the internet address of the computer the dongle always assigns this address, there is also a useful web status page on

Configuring the network

first of all enable ip4 forwarding, edit the file sudo nano /etc/sysctl.conf and uncomment the line:
this will enable forwarding on reboot, you can also enable IP forwarding immediately with:
$ sudo sysctl -w net.ipv4.ip_forward=1

We now need to give the Pi a static IP address on the internal network. Edit sudo nano /etc/network/interfaces so you end up with a file that looks like this:

this gives the Pi a static IP address of


The next stage is to give the other computers on your network an IP address, this is done with a dhcp server:
$ sudo apt-get install isc-dhcp-server
you will need to configure dhcp sudo nano /etc/dhcp/dhcpd.conf, here is mine:

This will assign IP addresses in the range to to any computer connected to your network. I have used Open DNS for the Domain name Servers, if you wish to use google’s use:
option domain-name-servers,;instead.

I have also given my network printer a static IP address, it is still assigned by the DHCP server but never changes, the same would apply to any file servers and the like, I would assign static devices addresses that are outside your dynamically assigned range. Reboot the Pi and then your test computer.

Your test computer should now have an IP address (, and the gateway point to the Pi (

Accessing The Internet

The final part is to have the incoming traffic on the the Ethernet port eth0, go out on the dongle usb0. This is achieved with iptables, a firewall and traffic router. Install with:
$ sudo apt-get install iptables
and you need to setup Network Address Translation, NAT and forwarding. This short bash script clears any old settings before applying the new rules:

Where LAN is your internal network, and WAN is the internet. The final line allows you access to the Dongle’s built in web status page from any browser on your internal network, just use:

Save the file in your home directory as ~/, make it executable and run the script.

$ chmod +x ~/
$ sudo ~/

From your test computer, you will now be able to access the internet.

Finally, you now need to have iptables reload when you start the Pi. Export the iptables settings to a file with:

$ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

and create a file sudo nano /etc/network/if-up.d/iptables with the following contents:

and make it executable sudo chmod +x /etc/network/if-up.d/iptables

after a reboot you can see your iptables with sudo iptables -L and sudo iptables -t nat -L and you can see web traffic passing through the router with sudo tcpdump -i any -nn port 80.

Adding a Proxy Server

This is optional, but a transparent proxy server and cache may reduce the amount of traffic on your 3G/4G connection, mileage varies and the amount of data cached was less than I thought it would be, I also found that my Humax Freesat box really didn’t like the proxy server and wouldn’t update its TV schedules while it was on. I have used squid3 for this.
sudo apt-get install squid3
Update the squid3 configuration /etc/squid3/squid.conf so it has the following. The original is rather large, so you may want to make a copy and create a new one:

then restart squid3
sudo /etc/init.d squid3 restart
add the following iptables rule to redirect all traffic on port 80 to squid3:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
you should now be able to watch the web traffic being processed through squid3 with:
sudo tail /var/log/squid3/access.log -f
finish off by exporting your iptables again, so they are reloaded on reboot:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Raspberry Pi - 4G Router

References and sources:

Rotary Encoders on the i2c bus

I have been getting to grips with rotary encoders on the Arduino, and to add a little drama I have gotten this working on the i2c bus. Here I will be showing how to set up the necessary hardware and demonstrate a program for the Arduino. I have used a similar setup to control an LED RGB light strip, with three rotary encoders to control the Red, Green and Blue and a fourth for special effects.

The i2c bus

The i2c bus allows connection of multiple devices to the Arduino on just two wires, these can be just about anything from temperature sensors to motor controllers with each device having its own address, up to eight of these can be used using just two wires from the Arduino.

For this project I’ll be using a single MCP23017 port expander, with which I can add sixteen digital I/O pins to the Arduino

MCP23017 pinout

The address for the expander is set on pins 15, 16 and 17 (A0, A1 and A2), for a single encoder set all of these to ground. Should you require more expanders the addresses can be set as in the table below, the MCP address is for the Arduino program.

hardwired address i2c
A2 A1 A0
000 GND GND GND 0x20 0
001 GND GND 3v3 0x21 1
010 GND 3v3 GND 0x22 2
011 GND 3v3 3v3 0x23 3
100 3v3 GND GND 0x24 4
101 3v3 GND 3v3 0x25 5
110 3v3 3v3 GND 0x26 6
111 3v3 3v3 3v3 0x27 7

Rotary Encoders

The  encoders I’m using are the SparkFun 12-step rotary encoder with integrated push-button

rotary encoder

Inside they have mechanical contacts that output two square waves when rotated, A and B these are 90o out of phase with each other so when rotated clockwise output A is ahead of B, and counter-clockwise output B takes the lead, this is a two bit Grey code.

rotary encoder square wave
rotary switch outputs (source: datasheet)

So by comparing the two outputs we can determine the direction of rotation.

A Test Circuit

My test setup comprises of two rotary encoders, one Arduino Uno, one MCP23017 port expander, and a couple of resistors. External pull-up resistors are not required on the GPx input ports as the MCP23017 has these internally. Encoder A uses GPA0, GPA1 and GPA2 for the push button. Encoder B is on GPA4, GPA5, and GPA6.

MCP23017 rotary encoder test circuit


My program uses the Adafruit MCP23017 and standard wire libraries. The Adafriut library addresses the GPx ports from 0-15, so GPA2 is 2, and GPB2 is 9. I have written this to output the state of rotation to the serial port at 9600 baud.



The Case of OpenCV and the Missing SURF

I have been wanting to have a play with the OpenCV computer vision framework on Python for a while and finally got some time to some experimenting, I am looking to have the computer recognise LEGO parts, after much research and mucking about it seems I should be using cv2.SURF and/or cv2.SIFT for what I want to do. However on Fedora 19 these are not included in the distribution RPM as they are nonfree in that they are not open source. Attempts to use SIFT or SURF result in the following error:

$ python
Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print cv2.__version__
>>> i = cv2.SURF()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SURF'
This is annoying as OpenCV will now need to be re-installed the old fashioned way, but there are instructions on the OpenCV site and I will be using them here with additional information I have discovered while following them.

Change to root and add the free and nonfree repositories as ffmpeg and libv41 are unavailble from Fedoras, followed by an update (it seems that Fedora 19 always has something to update):

& sudo su
# yum localinstall --nogpgcheck$(rpm -E %fedora).noarch.rpm$(rpm -E %fedora).noarch.rpm
# yum update

Remove the existing OpenCV packages:

# yum erase opencv*

There are a few packages to install in preparation to compiling the code, you may have some of all of these already but yum will skip those. Install the mandatory packages, these are for compiling the source and using GTK for the GUI:

# yum install cmake python-devel numpy gcc gcc-c++ gtk2-devel libdc1394-devel libv4l-devel ffmpeg-devel gstreamer-plugins-base-devel git wget

Install the optional dependencies, I have gone for the install everything approach, they may be useful later:

# yum install libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel tbb-devel eigen3-devel python-sphinx texlive

Now, we are ready to get the latest source, here there are two ways to do this, install the latest development version using GIT, or download the latest stable version. My preference is to use the latest stable version.

With GIT, exit back to yourself from root, change to your home directory and download OpenCV:

# exit
$ cd ~
$ git clone
Cloning into 'opencv'...
$ cd opencv
$ mkdir build
$ cd build

Or using the latest build, at time of writing this is v2.4.7. Get this via the downloads page and save it to your home directory:

# exit
$ cd ~
$ tar -zxvf opencv-2.4.7.tar.gz
$ cd opencv-2.4.7
$ mkdir build
$ cd build

Now configure:


When complete you should check that your options agree with those displayed. There are many others available. Support for other programming languages may be missed out if they are not already installed. In my case those for Java, if I were to try OpenCV in Java I would need to install the appropriate Java packages using yum, then recompile OpenCV.

Now build and install, this can take a while:

$ make
$ sudo make install

You now need to move the module to anywhere on the Python Path, to find this:

$ python
Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg', '/usr/lib64/', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/PIL', '/usr/lib64/python2.7/site-packages/gst-0.10', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

The directory /usr/lib/python2.7/site-packages looks suitable:

$ sudo mv /usr/local/lib/python2.7/site-packages/ /usr/lib/python2.7/site-packages

And add your new installation to the PYTHONPATH, and add the export to the end of your .bashrc so it survives a reboot:

$ export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
$ echo export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages >> ~/.bashrc

Now to test:

$ python
Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print cv2.__version__
>>> i = cv2.SURF()

Sorted. Now, perhaps, I can get on with what I actually want to do….


Converting the Canon GPS log

Having been out and about with the Canon 6D, for once I had remembered to turn on the GPS logging built into the camera. Upon returning home after the seven mile walk I saved the GPS data in the cameras memory to the SD card. Now this LOG file found in the GPS directory of the SD card can be read directly into Google Earth but not into Memory Map for viewing on the far superior OS 1:25,000 Ordnance Survey map, also Memory Map does not read Google Earth’s KML or KMZ files.

So, the LOG file needs converting, but what format is it in? Canon are, it seems, rather unhelpful in revealing the secret but a little googeling found a reference to them using the NMEA-0183 format.

For conversion I found the free, excellent and very comprehensive gpsbabel to do the job (the PDF manual is over 200 pages), for me I convert the GPS files on a linux computer, but they do a Windows version and I assume the method and outcome will be the same. On Debian, install gpsbabel with:
$ sudo apt-get install gpsbabel

The basic use of gpsbabel for converting is as follows:
gpsbabel -i <input format> -f <input file> -o <output format> -F <output file>

As I know Memory Map reads the Garmin GPX format, I chose that as the output:
$ gpsbabel -i nmea -f 13120100.LOG -o gpx -F 13120100.gpx

And the rest is, as they say, Topographic.


Infra-Red Coin Detector for Arduino

For something I’m building I need have the Arduino detect a coin being dropped trough a slot, for this I have built an IR detector, it comprises of an IR LED, IR Photo-Diode, Op-amp and ATtiny85 micro-controller.

IR Coin Detector (Mk3)

The circuit works by having the IR LED flood the Photo-diode so that when an object passes between them the Photo-diode stops letting current through, this is fed into the op-amp to provide a consistent output for the ATtiny85 micro-controller to detect the change in signal to then flash a couple of LED’s and provide a signal to an Arduino.

IR Coin Detector (Mk3)

Here is a program that flashes a couple of LED’s and makes output pin 4 high:


  1. DIY Science: Measuring Light with a Photodiode II
  2. Pin Change Interrupt on the ATtiny
  3. Programming an ATtiny85 with an Arduino

Recording Sound on the Raspberry Pi

The Raspberry Pi does not have a microphone socket, which is inconvenient when you wish to record sound. To fix this you will need a USB Sound Card, for which I bought a Creative Sound Blaster Play! for about £20 and a short USB extension lead as the sound card is slightly too large and blocks the other USB port.

With the latest Raspbian “wheezy” installed on a Pi Model B with 512Mb of RAM and the overclocking set to High in raspi-config, here is a recipe for getting your Raspberry Pi to record sound from the command line. For the test setup I connected my iPod to the microphone port of the sound card, plugged everything in and powered up.

Raspberry Pi Records

After logging into the Pi, check that the computer can see the card, use lsusb to find it, here the card is highlighted in blue:
$ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 046d:c52e Logitech, Inc.
Bus 001 Device 005: ID 041e:30d3 Creative Technology, Ltd Sound Blaster Play!
remember that different makes of card will have different names and ID’s

Your user will need to be in the audio group, check this with groups <username>:

$ groups pi
pi : pi adm dialout cdrom sudo audio video plugdev games users netdev input
if not, then add them with:$ sudo usermod -a -G audio <username>

There is/was an issue with the Pi’s USB port that meant it can/could become overwhelmed1 with data which causes popping and bubbling noises to be included in your recordings, this can be fixed with an update of the Pi’s firmware:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install rpi-update
$ sudo rpi-update

The Raspbian image already has the alsa-utils for sound already installed, the programs I am using for recording and playback are:

  • alsamixer – GUI for setting the recording and playback levels
  • amixer – Command Line for setting the recording and playback levels
  • alsactl – for saving the settings set in alsamixer or amixer to use again after a reboot
  • arecord – For recording the sound
  • aplay – For playing back your recording

All of these programs have a –help option.

There are two methods for setting up the the microphone port on the card, the first is alsamixer:

alsa mixer

$ alsamixerPress F6: Select Sound Card, and choose yours from the list, the bcm2835 ALSA is the on-board sound, for me the one to pick was: USB Device 0x41e:0x30d3 and take a note of the card number, in my case: 1. Now select the Mic and increase the volume to 52, or the first white blob, you’ll need to change it later, but its a good place to start. The Auto Gain Control wants to be off, select the gain control and press M to toggle so it displays [MM] for mute. Press Esc to exit and save the settings with:$ sudo alsactl store 1 where 1 is the card number.

Alternatively, you can use amixer. First find your sound card, in amixer there does not appear to be a method of listing the available cards, but on a Raspberry Pi I guess it will always be card 1, you can list the cards current status with:

$ amixer --card 1 contents
numid=1,iface=MIXER,name='Mic Playback Switch'
; type=BOOLEAN,access=rw------,values=1
: values=off
numid=2,iface=MIXER,name='Mic Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=32,step=0
: values=21
| dBminmax-min=0.00dB,max=47.81dB
numid=5,iface=MIXER,name='Mic Capture Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=6,iface=MIXER,name='Mic Capture Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=16,step=0
: values=7
| dBminmax-min=0.00dB,max=23.81dB
numid=7,iface=MIXER,name='Auto Gain Control'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=3,iface=MIXER,name='Speaker Playback Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=4,iface=MIXER,name='Speaker Playback Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=151,step=0
: values=52,52
| dBminmax-min=-28.37dB,max=0.06dB

So I want to turn the Auto Gain Control off, and the recording volume to 14:
$ amixer -c 1 cset numid=7,iface=MIXER,name='Auto Gain Control' 0
numid=7,iface=MIXER,name='Auto Gain Control'
; type=BOOLEAN,access=rw------,values=1
: values=off
$ amixer -c 1 cset numid=6,iface=MIXER,name='Mic Capture Volume' 14
numid=6,iface=MIXER,name='Mic Capture Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=16,step=0
: values=14
| dBminmax-min=0.00dB,max=23.81dB

again, store the settings so that they will be used again on a reboot:$ sudo alsactl store 1

Now we are ready to do a test recording, first check that arecord will see your card:

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: U0x41e0x30d3 [USB Device 0x41e:0x30d3], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

and now for a ten second test recording, this will create a file called rectest.vav in your home directory. Remember to set the Device (-D plughw:1) number to the right card (card 1):

arecord -D plughw:1 --duration=10 -f cd -vv ~/rectest.wav the vv option displays extra information on the screen as well as a volume meter, this should be peaking at around 95% on the loudest sounds, if it is at 100% all a lot of the time then you are probably recording distortion. Playback the recording with aplay:

aplay ~/rectest.wav

the default settings will play the wav fie through the TV if it is connected by HDMI, To playback through the USB sound card set the device to the card number, like in arecord:

aplay -D plughw:1 ~/rectest.wav

Congratulations, you now have a fully working Pi Recording Device. Remember to experiment with the volume levels, too high and your recording will sound distorted.


  1.  Raspberry Pi Usb Audio fix (10 May 2013)

Python and the Oracle Client

Update 24 Nov 2015: Also, see my post Upgrading the Python Oracle Client for updating from version 11 to 12.

Installing the python cx_Oracle extension module for connecting to Oracle databases on this Fedora 18 workstation turned out to be a bit of a faff by giving an assortment of unhelpful error messages, if you are having the same pain maybe this will help.

You will need two files from the Oracle Database Instant Client download site, the basic client package and the SDK (devel): For Linux choose the correct flavour for your installed operating system: x86 or x86-64 for 64bit operating systems, you will need to register on the site to access the files. For my purposes I got the 11.2 version for x64 RPM files, install them using:
$ sudo rpm -i oracle-instantclient11.2-basic-
$ sudo rpm -i oracle-instantclient11.2-devel-

You will now need to tell the system where the libraries are:
$ sudo su
# echo /usr/lib/oracle/11.2/client64/lib/ > /etc/
# ldconfig
# exit

To install cx_Oracle you will need to set some environment variables otherwise you will get an “error: cannot locate an Oracle software installation” message. The easy_install program is found in python-setuptools I have included it in the recipe as a reminder if you have not installed it already.
$ sudo yum install python-setuptools
$ export ORACLE_HOME=/usr/lib/oracle/11.2/client64
$ export PATH=$ORACLE_HOME/bin:$PATH
$ sudo -E easy_install cx_Oracle

or by downloading the version from and installing it manually, you will still need to set the exports, as above, and do the following for installation:
$ sudo -E python build
$ sudo -E python install

The -E on the sudo takes your environment variables, including the three you just set, into your sudo session.

$ python
Python 2.7.3 (default, Aug 9 2012, 17:23:57)
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> exit()

When the the library cannot be seen, you get this error:
$ python
Python 2.7.3 (default, Aug 9 2012, 17:23:57)
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot open shared object file: No such file or directory
>>> exit()

Taking Photos on the Canon EOS with an Arduino

For my Spangaly Stick project, more of which later, I have been wanting to add a remote control function for the camera for a while now and with the extended winter I found I had the time. I am using an Arduino micro-controller fitted with an XBee wireless shield to respond to a keyword sent by another Arduino with a similar setup, or from a computer with an XBee on a USB port.

take a picture - board

This board had been built to work with the Canon EOS DSLR range of cameras, but should work with other makes of camera fitted with an electronic remote socket. For basic use the camera should be set in Aperture Priority (Av) mode with the lens set to manual focus and if your using a tripod switch off any image stabilization.

For this project you will need:

  • A Windows (XP and above) Computer
  • An Arduino Uno R3
  • Two XBee’s
  • An XBee USB adapter
  • An XBee Shield for the Arduino
  • A battery to power the Arduino, I use a 12v 1.3Ah Sealed Lead Acid.
  • A remote lead for your camera
  • Ability to solder, read circuit diagrams, etc..

For this remote to work, you will need to configure two XBees to talk to each other. The easy way to do this is using the X-CTU tool (unfortunately it is Windows only) and a XBee USB Adapter. The XBees come in two main types, the Series One (S1) and Series Two (S2) they will need to be of both the same series to talk to each other, I have used Series One bees here, but not the ones without the sticking out antenna as I suspect they may be a bit delicate.

While the XbeeSheid configuration is documented on the arduino site, I shall summarise here. With the XBee plugged into the USB adapter and the adapter plugged into the computer wait for it to be detected by Windows then you can configure it. In X-CTU, on the PC Settings Tab, select the USB Serial Port. By default the XBee is set to baud: 9600, flow: None, data: 8, parity: None, stop: 1. Click the Test/Query button you should see some basic XBee settings, if it says it cannot communicate, try a different baud rate. Higher baud rates are available, but whats the rush?

Now click the Modem Configuration tab, under Modem Parameter and Firmware, click Read, after a pause at the top of the list The modem indicated will be whatever model you have, in my case XB24, select the function set we will be using: XBEE 802.5.4 RS485 ADAPTER and the firmware version: 13E8. You will need to set the Networking & Security Channel (CH) and the PAN ID (ID) to the same on both, as well as check the Serial Interfacing are set correctly, Interface Data Rate (BD): 3 – 9600, Parity (NB): 0 – NONE. Click Write to save the settings to the XBee.

For testing the XBee’s, I had one plugged into the USB adapter and the other placed into the the XBee Shield, an LED fitted across Digital Output 12 and Ground, and sent the following program to the Arduino, remembering to flick the little switch on the shield to USB for programming, and Micro for XBee emissions.

The circuit I made for taking photos includes the focus, this is optional but I have included it so the camera can be woken up before the picture is taken. An ILD74 opto-isolater is used to electrically separate the camera from the Arduino, it also simplified the circuit not having to use transistors. The LED’s are useful additions but are optional.

The diagram also shows the Canon Remote connections. Most use a 2.5mm stereo jack plug, but the more expensive cameras have a proprietary Canon N3 connector, to get the lead you will need to sacrifice a wired remote, one of these can be gotten of ebay very cheaply, about £3.00. The colours for the wires can be anything, so you will need check with a continuity tester.

The program on the Arduino listens for a keyword, in this case ‘PHOTO’ which then triggers the picture taking sequence first by setting the focus to wake the camera up then taking the picture. The Indicator LED is used to show activity on the serial port.