Camera: iPhone5
zipTimer: an iPod/iPhone app for pacing piano practice, cooking, workouts, you name it.
Camera: iPhone5
zipTimer: an iPod/iPhone app for pacing piano practice, cooking, workouts, you name it.
This is a short report on how to connect Quick2Wire’s analogue board directly to a Raspberry Pi. The key is the pinout for for the six-pin boxed headers on the Q2W board. I ignored the 5V and Int lines, running lines only for 3.3V, GND, SCL, and SDA. I ran these to the corresponding pins on the Pi, then executed sudo python3 pcf8591read.py
as before. Result? Success! I could read the potentiometer connected as in my previous post on the Q2W analogue board. See that code for comments on the Python code used to read the potentiometer.
Below is an improved set-up for connecting the Quick2Wire analogue board to the Raspberry Pi. I mounted the Q2W board on one end of a full-size breadboard with double-sided tape and inserted a Pi Cobbler on the other end. The analogue headers of the Q2W board face the inside of the breadboard.
I didn’t have the right kind of jumpers to connect the Q2W board to the breadboard, so I cut one end off of each of four female-to-female jumpers, soldered on a length of wire, and sealed the exposed connection with heat-shrink tubing. We don’t want any short circuits! With the female-to-male jumpers in had, it ws easy to set up the circuit.
Edit: On the first try, the RPi could not read data from the Q2W board. I then remembered that the left and right halves of the board are electrically separate, so I installed the red and blue jumpers you see in the center, bottom of the photo below. I also added the little LED circuit you see in the lower left, so that there is an LED to indicate whether the full board is receiving power.
Last night I assembled the Quick2Wire analogue board. The software setup took a little bit of fiddling, after which I was able to make the simple tests described at Quick2Wire and a measurement with a potentiometer. The source I found most useful was the post at www.miraculum.ch.
1. Set up ictools as described at adafruit.
2. Install the quick2wire-python-api in a directory /home/git as Miraculum recommends. (Make this directory if need be).
$ cd git $ git clone https://github.com/quick2wire/quick2wire-python-api.git
3. Find the file pcf8591read:
$ find /home /usr -name pcf8591read
Make a copy of this file in ~/git and rename it as pcf8591read.py. Then add the line indicated below to the code so that the head of the file looks like this:
#! /usr/bin/env python3 import sys sys.path.append(r'/home/pi/git/quick2wire-python-api/') # add this from quick2wire.i2c import I2CMaster from quick2wire.parts.pcf8591 import *
As noted in Miraculum’s post, the added line ensures that the program finds the needed parts of the quick2wire-python-api.
4. On the Quick2Wire Analogue board, run a jumper from AIN0 to GND. Then say sudo python3 pcf8591read.py
. You should see this:
pi@raspberrypi ~/git $ sudo python3 pcf8591read.py read: 1 : 0.0 read: 2 : 0.0 read: 3 : 0.0
5. Now run the jumper from AIN0 to VREF. You should see this:
pi@raspberrypi ~/git $ sudo python3 pcf8591read.py read: 1 : 1.0 read: 2 : 1.0 read: 3 : 1.0
6. Attach a potentiometer as follows: one outside lead to GND, the other to VREF, the middle lead to AIN0. Then test. You will get something like this as you rotate the potentiometer:
pi@raspberrypi ~/git $ sudo python3 pcf8591read.py read: 1 : 0.0 read: 2 : 0.0 read: 3 : 0.0 read: 4 : 0.06274509803921569 read: 5 : 0.14901960784313725 read: 6 : 0.20392156862745098 read: 7 : 0.2627450980392157 read: 8 : 0.3254901960784314 read: 9 : 0.39215686274509803 read: 10 : 0.47058823529411764 read: 11 : 0.5686274509803921 read: 12 : 0.6705882352941176 read: 13 : 0.796078431372549 read: 14 : 0.9686274509803922 read: 15 : 1.0 read: 16 : 1.0