Raspberry Pi Analog Input Circuit
Here is a very basic input circuit which simply uses a potentiometer - or a variable resistor as it is called in some places - to provide a value to the analog input channel 0 (Pin 2). You could use almost any potentiometer of around 10KΩ value and it could be a panel mount one or just a small preset, - most people have these in their 'electronics component box'. If you don't then see if you could recycle one from a broken radio... As you can tell I hate spending money, I should get on well with Warren Buffett...
If you can't find any pots / pre-sets have a look on eBay, I saw some very affordable ones just recently - a bag of 5 for about £2.00. If you need large quantities then the cheapest ones I could find were "BOURNS - 3386W-1-103LF - TRIMMER, 10K" @ around 56p if you buy more than 50.
One of the basic principles of an Analog-to-Digital Converter chip is that the input signal must be within the same range as its power rails Vss and Vdd. This is not always the case with more complex ADC packages but generally smaller packages follow this rule because they use the power rail as a reference voltage for their internal ADC calculations.
Since this chip is powered from a 3.3 V supply at Pin 8, the analog input signal at pin 2 is expected to be no more than 3.3 V, hence an analog input is expected to be between 0 V and 3.3 V. A potentiometer creates a simple voltage divider circuit. One end is tied to the ground and another to the 3.3 V rail. By setting the potentiometer wiper to any position you can achieve any voltage in a range between 0 V and 3.3 V. which is accepted by the analog inputs CH0, or CH1.
This chip provides a 10-bit resolution to represent a value. When the wiper is set to the extreme ground end the input voltage (pin 2) will be at 0 V and therefore the data out observed at Pin 6 will be binary "0000000000". However if you were to set the wiper to the other extreme end thus feeding 3.3 V at the input (pin 2) then the value observed at data out (pin 6) will be the maximum value of binary "1111111111" which is 1023 in decimal. Roughly half way the digital value should read "011111111" which is 511 in decimal. Obviously all the values in-between can also be measured.
The chip used in this analog-to-digital converter circuit is the same as that used on the Gertboard, So if you need to test your circuit just follow the test procedure and software shown in the Gertboard manual. The Gertboard is of course a fantastic bit of hardware for the Raspberry Pi and if you haven't yet bought one then you should do so as it also contains a digital-to-analog converter chip as well.
Author: Peter J. Vis