« Back to home

Using the Clixx.IO Docking Station

In this post I show how to wire the docking station to a Raspberry Pi. We'll then use the homebrew TwinTab board described in the previous post to test it.

Raspberry Pi Pin Numbering

It is very important to get the pin connections correct from the Pi to the docking station - wiring the pins incorrectly could permanently damage the device, something we want to avoid.

The main interface to the Raspberry Pi is a 26 pin GPIO interface on the edge of the board which consists of 2 rows of 13 pins each. A good source of information can be found here,

If you hold your Pi so that the expansion header is at the top right the pins on the GPIO header are number from left to right and top to bottom. The pin closest to the top right of the circuit board is P1-02. Refer to the image to the right to see a description of the pins and their numbering.

Connecting the Board

I'll use the sames pins used by the Clixx.IO Raspberry Pi Dock so any software I write will be compatible with that board. The mapping for the six ports are defined in the table below:

Slot |In |Out |Extra ---------|-----|-----|----- Digital 1|P1-18|P1-22|P1-16 Digital 2|P1-13|P1-15|P1-11 Digital 3|P1-12|P1-26|P1-24 Serial 1 |P1-08|P1-10|N/A SPI 1 |P1-19|P1-21|P1-23 I2C 1 |P1-03|P1-05|N/A

To start with I'll simply connect the board directly to the pins for the Digital 1 slot without using my docking station at all. This will allow for some quick testing to make sure I have everything right. The connections are as follows:

Tab Pin|Function|Pi Pin -------|--------|------ 1 |GND |P1-06 2 |VCC |P1-01 3 |Extra |P1-16 4 |In |P1-18 5 |Out |P1-22

You'll notice that I am driving the board directly from the 3.3V pin. In general this is not a good idea as it can only supply about 50 mA worth of current. For this example we only have a single LED that draws around 20 mA so we can get away with it. Do not use it for more complex circuits though, it simply won't work.

Testing the Board

To test the board we'll use a small Python program to talk to the board. The examples here assume you are using the Raspbian distribution on your Pi but should be compatible with most Linux distributions.

Python will already be installed on your system but there are a few extra libraries you need to install including the WiringPi bindings for Python. Here are the steps you need to follow to install the dependencies (you will need to be able to access the internet from your Pi for this to work).

 sudo apt-get install python-setuptools python-dev     sudo easy_install pip     sudo pip install wiringpi2

Here is the sample program we are going to use:

    #!/usr/bin/env python     import wiringpi2     from time import sleep

     wiringpi2.wiringPiSetupPhys()     wiringpi2.pinMode(18, 1) # Set as output     wiringpi2.pinMode(22, 0) # Set as input

     led = False     btn = 0

     while True:
      # See if the button state has changed       lastBtn = btn       if wiringpi2.digitalRead(22):         btn = max(btn - 1, 0)       else:         btn = min(btn + 1, 3)       if (lastBtn == 0) and (btn > 0):         print "Button pressed!"         led = not led       wiringpi2.digitalWrite(18, led)
      # Pause between cycles       sleep(0.01)

 You will need to save the code above in a file called *test.py* on your Pi and run it with the following command:
 sudo python test.py

The script needs to be run as the root user so it can access the GPIO ports. All the program does is toggle the state of the LED every time you push the button - the extra code around reading the button input is to correct for contact bounce. The end result looks like this ...