Version 1.0.0 Released 2014-08-20
The Thumbstick Click board is connected to a Raspberry Pi using the MikroE Pi Click Shield. This shield connects to the Raspberry PI GPIO header pins and lets you attach MikroBus format Click boards.
If you don't have a Pi Click Shield, you can get one from the MikroElektronika Webstore, or from Digikey, or Farnell.
The Thumbstick Click board uses an SPI based MCP3204 module for reading the joystick axes. The ADC0 channel is used for the y-axis and the ADC1 channel is used for the x-axis. The board is powered on 3.3 Volts from the GPIO header on the Raspberry PI.
The joystick "center click" button is read using the GPIO input 17 on the Raspberry Pi and has an inverted logic state where the button clicked=0, and the button unclicked=1.
If you take the rubber joystick cap off the thumbstick you can see the mechanical push button that responds to the clicking motion.
Scripts that use the GPIO and SPI hardware interfaces need to be run with sudo since GPIO reading requires admin privileges on Linux.
That means you need to run the thumbstick.py demo python script using:
sudo python thumbstick.py
Step 1. Let's enable SPI on the Pi using the following terminal command: ( Tip from the projects.drogon.net blog)
sudo modprobe spi_bcm2708
sudo chown `id -u`.`id -g` /dev/spidev0.*
Then check the SPI module is active with:
lsmod
You should now see the following module listed:
spi_bcm2708
Step 2. Install webiopi so it is easy to use SPI inputs from python scripts.
You can download the free webiopi library from:
http://sourceforge.net/projects/webiopi/files
Then you need to Un-gzip the file "WebIOPi-0.7.0.tar.gz". You can do that by right clicking on the file and using the "Extract Here" tool on Raspbian.
Run the webiopi setup program with:
cd WebIOPi-0.7.0
sudo ./setup.sh
It is a good idea to setup a webiopi username and password for the integrated server module:
sudo webiopi-passwd
Note: The webiopi generated password file is stored in:/etc/webiopi/passwd
Step 3. Edit the webiopi config file with:
sudo gedit /etc/webiopi/config
Scroll down to line 96 in the webiopi "config" file and add the following code:
#MikroE Thumbstick IO on a Raspberry Pi Click Shield
adc = MCP3204
This tells the webiopi software that the Thumbstick Click board uses the MCP3204 SPI based chip for ADC input.
Step 4. Run the thumbstick.py demo script using:
sudo python thumbstick.py
If the script runs correctly you will be presented with the following output in the terminal:
You can quit the python script by pressing the Control+D hotkey.
As an optional step, you can start the webiopi server module for http based SPI and GPIO access.
Note: You need to set up the webiopi password in step 3 if you want to use the webserver module.
The webiopi server module creates an http hosted webgui page that updates on your pi. After you start the server module you can access it using either:
http://localhost:8000
orhttp://<write your raspberry pi ip address here>:8000
You can start webiopi's webserver module with ONE of the following options:
Start webiopi from a terminal session with:
webiopi -d -c /etc/webiopi/config
To start webiopi in the background:
sudo /etc/init.d/webiopi start
To start webiopi at boot:
sudo update-rc.d webiopi defaults
You can use the webGUI to read the current GPIO pin state from a web browser. This is interesting as you can see the input and output mapping and see the binary state of each of the GPIO pins.
You can also watch the live values on the Thumbstick's 2 ADC channels (Joystick X & Y Axis) using the webiopi "Device Monitor" webpage.
Email: andrew@andrewhazelden.com
Blog: http://www.andrewhazelden.com
Twitter: https://www.twitter.com/andrewhazelden