Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!--Wmat (talk)
Please email User:Wmat if you experience any issues with the Request Account form.

Difference between revisions of "RPi ADC I2C Python"

From eLinux.org
Jump to: navigation, search
(Created page with "== Reading ADC values over I2C using Python == I (AndrewS) recently bought a [http://www.abelectronics.co.uk/products/3/Raspberry-Pi/7/ADC-Pi---Raspberry-Pi-Ana...")
 
m (Added links back to Tutorials page)
Line 1: Line 1:
 +
[[Category:RaspberryPi]]
 +
Back to the [[R-Pi Hub|Hub]], or the [[RPi Tutorials|Tutorials]] page.
 +
 
== Reading ADC values over I2C using Python ==
 
== Reading ADC values over I2C using Python ==
  
Line 34: Line 37:
 
printed repeatedly to the screen.
 
printed repeatedly to the screen.
 
You can test that the ADC is working by using e.g. a bent paperclip to connect the "5V" on the board to one of the eight ADC channels, and the corresponding reading on screen should then read approximately 5V (in fact, the voltage output by your PSU).
 
You can test that the ADC is working by using e.g. a bent paperclip to connect the "5V" on the board to one of the eight ADC channels, and the corresponding reading on screen should then read approximately 5V (in fact, the voltage output by your PSU).
 +
 +
Back to the [[R-Pi Hub|Hub]], or the [[RPi Tutorials|Tutorials]] page.

Revision as of 13:57, 24 September 2012

Back to the Hub, or the Tutorials page.

Reading ADC values over I2C using Python

I (AndrewS) recently bought a ADC Pi RaspberryPi addon board from http://www.abelectronics.co.uk/ - there were a few tricky points in getting it working, so I thought I'd write this step-by-step tutorial. The instructions below are all based on the 2012-09-18-wheezy-raspbian distro but should be equally applicable to other distros.

Instructions

Files in the /etc directory below need to be edited as root, so use sudo nano filename

  1. Enable I2C support
    • add i2c-dev to the end of /etc/modules
    • comment out (with a #) the line that says blacklist i2c-bcm2708 in /etc/modprobe.d/raspi-blacklist.conf
  2. Enable the pi user to access I2C hardware
    • install i2c-tools (includes i2cdetect and adds the i2c group) with: sudo apt-get update && sudo apt-get install i2c-tools
    • add the pi user to the i2c group with: sudo adduser $USER i2c
  3. Install the Quick2Wire Python API
  4. Reboot to enable all the above changes
    • sudo reboot
  5. Download and run the demo script

If everything went well you should now find that you get:
1: 0.000000
2: 0.000000
3: 0.000000
4: 0.000000
5: 0.000000
6: 0.000000
7: 0.000000
8: 0.000000
printed repeatedly to the screen. You can test that the ADC is working by using e.g. a bent paperclip to connect the "5V" on the board to one of the eight ADC channels, and the corresponding reading on screen should then read approximately 5V (in fact, the voltage output by your PSU).

Back to the Hub, or the Tutorials page.