dotan
Posts: 4
Joined: Mon Apr 15, 2013 7:24 pm

GPIO = analog in?

Mon Apr 15, 2013 7:32 pm

hello friends.
i am not really familiar with Raspberry Pi .
i do familiar with devices such as arduino.
i am wondering if i could get any kind of analog in from the GPIO.

eventually, i just want to connect a potentiometer to one of the inputs so i could control some parameters in a software like puredata.

if any one here knows if that is possible or not, please share .

i

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO = analog in?

Mon Apr 15, 2013 7:39 pm

The Pi does not have analogue inputs.

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: GPIO = analog in?

Mon Apr 15, 2013 9:49 pm

Although there is no analogue input, it is possible to simulate a very crude form of analogue input by timing the charging of a capacitor. So if say the capacitor is discharged by the GPIO in output mode then switched to input and the capacitor charged up through the variable resistor then the time to reach the input threshold is shorter when the resistance is smaller. This can be detected by using an interrupt triggered by the pin changing state and you can then convert the time into an analogue value.

The minimum resistance should not be too small (e.g. 1K) to avoid loading the GPIO too much. It is also good to keep this in line during the discharge phase to avoid high pulses of current. The time to charge also depends on the input threshold voltage but this might not matter too much if you are just interested in relative control rather than absolute accuracy.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: GPIO = analog in?

Mon Apr 15, 2013 11:29 pm

Depending on what resolution you need they are many SPI and I2C ADC chips that can be added to give you the analog input you need.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

1HzCoder
Posts: 31
Joined: Thu Jul 12, 2012 1:15 am
Location: Lower Alabama

Re: GPIO = analog in?

Tue Apr 16, 2013 12:24 am

Dotan
I bought one of these http://nwazet.com/pi-keylime, just haven't had the time to use it yet.
TomJ
Einstein once said you don't really understand anything until you can explain it to your Grandmother

Erni
Posts: 8
Joined: Sun Oct 14, 2012 1:26 pm

Re: GPIO = analog in?

Tue Apr 16, 2013 6:37 pm

You say you are familiar with Arduino, so an easy and cheap solution.:
Connect an ATTiny85 to the rx port of the PI.

The Attiny will be happy with 3,3V from the PI, so no levelshifting needed, and has 3 (4) analog inputs

dotan
Posts: 4
Joined: Mon Apr 15, 2013 7:24 pm

Re: GPIO = analog in?

Tue May 14, 2013 6:55 pm

wow thanks for all of the replies.
i probably forgot to mark the "notify me when someone replay" and almost completely forgot about this post.

well, i think that the idea of improvising an adc or dac with capacitrors and resistors is too much macgyver for me.

the Lime key looks preety cool and also the ATTiny85.
i will read more about this two and may the best win!

once again thank you for your support and sharing. i might also try to use an arduino.

cheers
D

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: GPIO = analog in?

Wed May 15, 2013 11:33 am

I just mentioned this method on another post here and thought I'd link it here too:

http://learn.adafruit.com/basic-resisto ... ll-reading

It's really quite easy to read the setting of a resistor using this method, not as Mcgyver as it might sound - just the resistor and one capacitor. It's probably not super accurate though. I've used it for reading some photocells, not a variable resistor/potentiometer - so the output might vary a bit with temperature, depending on the capacitor, but it's very cheap to test it. Only real problem is the read loop might hold things up for a fraction of a second, and the response might not be quick enough for dynamic pedal effects like wah, volume pedal etc. if that's what you're using Puredata for.

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: GPIO = analog in?

Wed May 15, 2013 12:52 pm

I think a decent ADS on i2c like the MCP3008 and a potentiometer are the cheapest/most logical option. I really don't see why you would use an extra processor like the ATiny for a simple task like this ...
http://www.pieter-jan.com/

User avatar
meltwater
Posts: 1015
Joined: Tue Oct 18, 2011 11:38 am

Re: GPIO = analog in?

Wed May 15, 2013 1:00 pm

If you want something easy and 8bit is enough, this module is very good:
http://dx.com/p/pcf8591-8-bit-a-d-d-a-c ... ule-150190
______________
http://www.themagpi.com/
A Magazine for Raspberry Pi Users
Read Online or Download for Free.

My new book: goo.gl/dmVtsc

Meltwater's Pi Hardware - pihardware.com

Like the MagPi? @TheMagP1 @TheMagPiTeam

Return to “Automation, sensing and robotics”