Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I'm looking at options for ADC on the Rasbperry Pi. I'm wondering what is possible so far. Of course easy and cheap is good.

share|improve this question
    
What do you need it for? –  Jivings Jul 26 '12 at 11:03
    
@Jivings, I'm thinking of a couple of projects that can make do with relatively low sample rates. –  John La Rooy Jul 27 '12 at 4:46
add comment

5 Answers 5

up vote 10 down vote accepted

Adafruit has a nice tutorial on using the MCP3008($3.75) - 8-Channel 10-Bit ADC With SPI Interface to control the volume of a mp3 file, but it should give you a good starting point for any analog to digital project.

share|improve this answer
    
Both Arduino and PICAXE are the wrong solutions here. –  Alex Chamberlain Jul 26 '12 at 19:40
    
I disagree that the Arduino is the wrong solution here. The Arduino uses USB while the MCP3008 uses SPI. The Arduino is all ready mounted and ready to use out of the box while the MCP3008 will need some accessories and work to get going. The MCP3008 is cheaper, but by the time you add in all the stuff you need (GPIO break out, mounting breadboard..) the cost gap is not as large as it seems. All in all if you want to experiment and have rapid turn around the Arduino is the superior option, but if you're looking for a permanent installation I would agree that the MCP3008 works best. –  Dan B Jul 27 '12 at 14:58
add comment

ADS1115

The ADS1113, ADS1114, and ADS1115 are precision analog-to-digital converters (ADCs) with 16 bits of resolution offered in an ultra-small, leadless QFN-10 package or an MSOP-10 package. The ADS1113/4/5 are designed with precision, power, and ease of implementation in mind. The ADS1113/4/5 feature an onboard reference and oscillator. Data are transferred via an I²C-compatible serial interface; four I²C slave addresses can be selected. The ADS1113/4/5 operate from a single power supply ranging from 2.0V to 5.5V.

First you need to make sure the I²C modules are loaded. Next connect the ADS1115 as shown below. There are 4 different addresses possible depending which pin ADDR is connected to. This means you can connect a total of 16 channels to a single I²C bus.

GND=0x48, VDD=0x49, SDA=0x4A, SCL=0X4B

enter image description here

You can see the result of the last conversion like this

# i2cget -y 0 0x49 0 w
0x0000

The default of 0x0000 is returned here since no conversions have been performed yet. Now lets take a look at the config register

# i2cget -y 0 0x49 1 w
0x8385

The LSB is first, so this is equivalent to 0b1000010110000011

I'd like to do a single-ended conversion on AIN0, so I need to write bits[14:12] as 0b100. ie 0b1100010110000011

# i2cset -y 0 0x49 1 0xC385 w
# i2cget -y 0 0x49 0 w
0xa30b

The LSB is first, so this is equal to 2979 decimal

share|improve this answer
    
aren't these package types a little harder to work with because of the pin size/spacing? Especially for those like me with arthritis (which limits my manual dexterity. –  Steve Robillard Jul 28 '12 at 21:47
    
@SteveRobillard, yes they are harder to work with, but definitely easier than they appear to be. For MSOP it helps to have magnification, flux, solder wick and a good soldering station. You can have quite a few goes to tack one corner of the MSOP with some solder until you are happy with the positioning. The small size does help to reduce the noise in the circuit so it's worth a try, you may be surprised. –  John La Rooy Jul 29 '12 at 7:53
add comment

Well as long as your desired use doesn't demand super high bitrates or resolution you could probably just use an Arduino. Arduinos are nice because they have a huge community for support, they've been around for a while, and communication over USB no GPIO!

Here's a link for to Simon Monk's blog post with instructions on how he communicates to the Arduino from a Raspberry Pi with python.

Also just in case you've never heard of an Arduino before (perhaps you've been living under a rock) here's a link to their Introduction page and a beginner level example of analog inputs.

share|improve this answer
add comment

Similar to using an Arduino but how about a PICAXE device, connected to the RPi UART? This would be smaller and much cheaper. To me, Arduino seems over the top depending on your actual needs.

share|improve this answer
add comment

Found this thread trying to figure out how to use the ADS1115 ADC with my RPi - using the examples above, I'm getting inconsistent readings. There seems to be a pattern - so I assume I am doing something wrong in terms of setting up the conversion and/or reading the results. Channel 0 of the ADS1115 is connected to a 10kohm thermistor with a 10k resistor pulled up to 3.3v. The ADS1115 is running off the 3.3 volts from the Rpi.

Here's my bash code (I tried averaging the readings):

#! /bin/bash
s=0
n=10
for ((i=1; i<=n; i++))
do
  i2cset -y 1 0x48 1 0xC385 w  # convert ADC input 0
  x=`i2cget -y 1 0x48 0 w` # read ADC input 0
  x=$((((((0xff00 & x)) / 256)) + $((((0x00ff &x)) * 256)))) # reverse words 0 and 1
  echo reading $i  $x
  s=$((s + x)) # sum
done

echo $((s / n)) # print average'

/* typical results - note that every second reading is about 500 off */

pi@raspberrypi ~/adc $ sudo ./conv0.sh 
reading 1 6992
reading 2 7513
reading 3 7042
reading 4 7494
reading 5 7050
reading 6 7468
reading 7 7059
reading 8 7438
reading 9 7123
reading 10 7421
7260

Anyone have any ideas as to what I am doing wrong?

I am an old-school C programmer and would prefer to write C code rather than bash scripts (presumably it would be more efficient) so if anyone has any C examples I'd be grateful. Most of the references I've found are for the Arduino in Python...

thx Don

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.