Edison, Getting Started, http://schemas.google.com/blogger/2008/kind#post, Intel Edison, Intel Galileo, IoT Linux image, mraa, python, Tutorial, upm

Python on Intel Galileo/Edison – Part 4: ADC

ADC is a peripheral that lets you input an analog signal and gives the digital representation of that analog signal.
The world in which we live in is surrounded by the analog signals. The temperature, sound that hear, the light that we see are all analog signals. If you want to interact or measure these signal in a digital system like Galileo/Edison, you’ll have to use ADC a.k.a Analog to Digital Converter.
What is analog signal?
The most common signal in nature is analog signal. These are also what is known as “continuous” signal. If you were to record an audio signal somehow and if you looked up for the signal in any point in time of the recording, you would find a sample there. That is why these kind of signals are known as continuous i.e., there is discontinuity in signal at any point in time. It is like the infinite numbers between 0 and 1 (or any other integer pair). There are infinite numbers between those two numbers. Similarly, there are infinite number of “samples” between two times t seconds and (t+1) seconds. In other words, there is no gap in the information that the signal presents within any two arbitrarily selected times.What is ADC?
ADC is the one way bridge from the analog to digital world. It takes the analog signal and makes it available to the digital systems like processors in a way in which it can be consumed by them. Like the GPIOs are ways to capture the digital events (button press, can be off or on), the ADCs are for capturing the analog events that are happening around.

How does ADCs work?
The ADCs work by mapping the analog voltage (or current) signal applied to certain numerical value that can be used by the digital system at hand. It achieves this by allocating certain number of bits for represent the analog signal (this defines the resolution of the ADC). It can be 8-bit, 11-bit, 16-bit etc..
The values of the continuous signals are infinite, the ADC rounds it off to the nearest numerical value which best represents applied voltage this process is known as quantization. Once an analog signal is applied, the signal is represented with a numerical value relative to what is known a “reference voltage”. Hence the maximum numerical value as output by ADC is same as the voltage applied at the ADC is input same as reference voltage. Also this implies that with a given reference voltage, the maximum voltage that you can measure is the reference voltage.

Let us consider an example of an ADC with 8-bit resolution and 5V as it’s reference voltage. With 8-bits, you can have bits represent 256 (0 through 255) different values. Now we divide 5V reference to 256 equal parts which comes to  0.01953125V or 19.531 mV (milli volt). This is what is resolution of the ADC meaning that the ADC at hand can only differentiate voltages which are 19.531 mVs apart. Now then next task is to represent these voltages in numbers ranging from 0 to 255. Most logical thing to do is the linear mapping. What this means is that is the voltage applied at the ADC input is 0, the numerical representation would be zero. The representation would be one if the voltage is (1/256)*5V (or 19.531 mv). If the voltage applied is in the range 19.51mV  to 2*19.531mV (remember the quantization?)  then the ADC would output 2 and so on. As a simplified view, ADC can be seen as linear function mapping the input voltage in following manner:

ADC_8bit_5Vref(inputVolatge) = floor(inputVoltage/19.51mv) 

In Galileo, the reference voltage is set 5V via the shield and the ADC is of 12 bit resolution and hence the maximum value output by the ADC is 1023.

Hardware connection:
The script below controls the intensity of the LED connected at port D5(using PWM), depending on the position of the “Rotary angle sensor” connected at analog input port pin 0.

The script:
The “Rotary angle sensor” modifies the voltage applied across it depending on the position of the rotor and this voltage is input to the analog input port 0.
We are going to change the intensity of the LED connected at D5 depending on the position of the rotor. Hence the PWM is pin is also setup. The maximum value output by the rotary angle sensor is 1023 and we use this in our calculations to control the intensity of the LED. The mraa module is used to create ADC object using “Aio” method which takes analog in pin as input. On the Aio object the “read” method is used to get the ADC value.


Other parts:
part0: Getting started on Galileo/Edison
part1: GPIO output
part2: GPIO input(button)
part3: pwm
part4: adc
part5: Temperature sensor
part6: Light sensor

Advertisements

12 thoughts on “Python on Intel Galileo/Edison – Part 4: ADC

  1. Hi man, I need your help,

    When I try to use mraa library for python, I have this error:

    import mraa
    Traceback (most recent call last):
    File “”, line 1, in
    File “/usr/lib/python2.7/site-packages/mraa.py”, line 32, in
    _mraa = swig_import_helper()
    File “/usr/lib/python2.7/site-packages/mraa.py”, line 28, in swig_import_helper
    _mod = imp.load_module(‘_mraa’, fp, pathname, description)
    ImportError: File not found

    I used the steps in this page: https://github.com/intel-iot-devkit/mraa/blob/master/README.md
    Installing on Intel 32bit Yocto based opkg image

    For true, I’ve Intel Galileo 1Gen, and this SDImage is this: https://software.intel.com/en-us/iot/hardware/galileo/downloads

    Latest Yocto* Poky Image (210 MB)

    Can you help me please?, Thanks!

    Like

  2. hi
    I have connected ADXL335 to DEV-13327 (ADC) and interfaced with sparkfun intel edison. I have used the pin AIN0,AIN1, and AIN2. For x,y and z axis. When i execute the code, the below mentioned error displayed.
    ValueError: Invalid AIO pin specified- do you have an ADC?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s