23

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.

John La Rooy
  • 11,847
  • 9
  • 46
  • 74

6 Answers6

15

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.

Steve Robillard
  • 34,158
  • 17
  • 102
  • 108
  • 1
    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
10

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

John La Rooy
  • 11,847
  • 9
  • 46
  • 74
  • 1
    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 07:53
  • Thanks for this, precisely what I was looking for. Haven't done byte order conversion in 25+ years though! Gonna have to shake some rust off. – Saeven Apr 19 '20 at 23:24
  • @JohnLaRooy quick question for you. If I had wanted to do a single ended conversion on A1, Would I have written 0b010, A2, 0b110 and A3 0b001 ? – Saeven Apr 19 '20 at 23:38
  • 1
    @Saeven, look at "Table 8. Config Register Field Descriptions" in the datasheet. Single ended A1 is `0b101` – John La Rooy Apr 20 '20 at 06:10
  • 1
    @SteveRobillard, Adafruit has a breakout :) https://www.adafruit.com/product/1085 – John La Rooy Apr 20 '20 at 07:28
  • @JohnLaRooy one last Q for ya. When you got the result from i2cget, would you not move the first bit to the end, and then reverse the string? e.g. a30b, becomes 30ba, becomes ab03? (In the same manner that 0x8385 became 3858, and then 8583, which was converted to 0b1000010110000011). – Saeven Apr 20 '20 at 19:54
1

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.

Dan B
  • 2,897
  • 2
  • 19
  • 20
0

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.

Guy
  • 1,607
  • 1
  • 15
  • 18
0

In a month or two, (due to shipping to Africa) I'll be getting a I2C PCF8591 board that has wiringpi support WiringPi site and the board uses 3.3v (typically) I got the WaveShare version on amazon Amazon link From what I've read, the PCF8591 is pretty nice but until I actually have the board in front of me, I can't say if it's good or not

linuxgnuru
  • 605
  • 8
  • 19
0

An interesting solution here: http://www.theremino.com/en/blog/standalone-applications/#raspberry

Not only ADC but any type of configurable Input Output for the Raspberry Pi.

Livio
  • 1