LK-Baseboard for Raspberry Pi B+ / Pi 2 Dear customer, thank you for your purchase of our product.
Copyright © LB-Link
Control the analog inputs through the MCP3008 1. Installation of the needed modules We recommend to use an actual Raspbian OS-Image (Debian Wheezy). In our first step we’ve to activate the SPI-Interface of the Raspberry Pi, to make the communication with the ADC of the LK- Base board possible.
Also the next two ones… Finally we go on „Finish“ to close the Configuration Tool… …and reboot the Raspberry Pi with the following command: sudo reboot After the Reboot, we’ve to load and install the needed Drivers and Modules. For this you have to put the following commands in the console of the Raspberry Pi and confirm each with a Press on [Enter]. In this procedure the Raspberry Pi have to be connected to the Internet: sudo apt-get update 4.
Python-Example for using the MCP3008 ADC Controller - testadc.py import spidev import time import sys spi = spidev.SpiDev() spi.open(0,0) def readadc(adcnum): if adcnum >7 or adcnum <0: return-1 r = spi.xfer2([1,8+adcnum <<4,0]) adcout = ((r[1] &3) <<8)+r[2] return adcout while True: if len(sys.argv) >1: for i in range(len(sys.argv)): if i == 0: print "_______________________________________\n" else: adc_channel = int(sys.
The file „testadc.py“ shows a way, how to measure analog voltage Level with a python script; with the function readadc() and a specified Channel (0-7) you can read out the actual value. Create a file with the name „testadc.py“ and copy the script shown above in this file (please make sure, that you don’t miss any spaces). The script can now be used in two different ways: Output the values of all ADC-Channels simultaneously: sudo python testadc.