Tuesday, February 23, 2016

Raspberry Pi Project: Starting with setting up an ADC chip

The Raspberry Pi is a small single board computer.  Pretty powerful and has hooks to the real world... expect that the ports are all  "digital"... solution:  get an Analog to Digital Conversion chip (ADC)

First attempt:  The MPC3008.  This is an eight channel - 10-bit device that supports the SPI Interface of the Raspberry Pi.

Lost already?

Einstein said that if you can't explain it in simple terms, maybe you really  don't  understand it that well yourself.

Digital:  the world of the computer only understands "off" and "on".

Analog:  the "real" world is much more complicated.  we see and hear things in many tones and textures, colors and frequencies, pallets and choruses.  The idea of Analog to Digital conversion is to convert the complexity into a series of "on"s and "off"s for the computer to understand and therefore process.

Eight Channels:   Simple enough!  We can read data from up to eight different sources at the same time.   In simple terms, this means that we can hang all kinds of sensors on this chip for conversion to digital form that the computer can use.  Sensors can be in any form:   light sensors, sound sensors, touch sensors, temperature sensors... etc.

10-Bit data:   This of course, refers to digital data... a set of "on" and "off" sequences... and 10 of them in the set.  A sensor, such as a temperature sensor, would send an analog voltage down the wire to the chip, and the chip would interpret the voltage  as a sequences of "on"s and "off"s to be passed on to the Raspberry Pi computer.  All "off"s would be the lowest value. (we would call this "zero") and all "of"s would be the highest value.  In 10-bits, there are 1024 combinations of "on" and "off".  (Did I say that "On" represents the number "1" and the "off" represents the number "0"? .. Now, I did.  Done!)  In 10-bits, we can have the lowest number represented as "0" and the highest number as "1023".

SPI:   This means "Serial blah blah blah".  (yeah, whatever!).  So, we took a single analog connection (one pin on the chip) and the chip converted it to 10-bits.  This would mean that we would need 10 pins on the Raspberry Pi to use it.  That's neither efficient nor convenient.  What SPI does is takes the 10-bits and sends them in single file (serial) like a tiny army  to one pin on the Raspberry Pi.  To keep the army in sync and in good marching order, there is another pin that acts like the drill instructor that sets the cadence.  OK, don't like the military style?  Then we'll just call this second pin a "clock", and it ticks and tocks the bits in single file to the Raspberry Pi, where it's clock pin is expecting it. .. and the digital data is received in good order and ready to be processes.

Thanks to Tony Dicola for his posting on the Adafruit Learn page... I got it all together and working without a glitch.  As they say... "It's as easy as pie"... or should I say "as easy as Raspberry Pi"?

Here's the link:  Raspberry Pi Analog to Digital Converters

I just did the page  on the MCP3008 chip .. I'm thinking of getting the other two breakout board on the next page to experiment with as  well.  These are both 4-channel converters:  one is 12-bit (4096 combinations) and the other is 16-bit (65536 combinations) .. more precision & accuracy!

Interestingly enough, there are two ways to connect the MCP3008 chip to the Raspberry Pi:  One method is to connect it to the pins designated for SPI on the Raspberry Pi, and the other method is to use the GPIO pins on the Raspberry Pi to grunt out the logic in your program of what SPI does for us "by magic".  They like to call this "bit bashing"... and that works for me.  The libraries for the example programs supports both methods of setup.  I set mine up for  "bit bashing", but I'll probably switch it over to SPI just for fun.  I like the example program "simpletest.py" because it just sends the data for all channels to the display.

Tony's instructions are complete quite "do-able" for someone that's new to this stuff.  While I've been in the computer programming circles for a long time, I'm a relative novice at Linux (Raspbian on the Raspberry Pi) and the Python programming language is new to me.  I walked through his "step-by-step" instructions pretty easily.  (Whoa, there!.. actually, I wrote then next paragraph BEFORE this one...so it might  look a bit twisted around.. yeah, because it is!)

.. and finally:   This is written in the programming language called Python.  While I'm new to Python, so far, it looks like any other programming language .. and it's strength lies in that it's easy to use and readable.  Yeah, I like that.

One note about Adafruit Industries, LLC :  I love this company!

OK, then there's ... I like the way the website works, the product selection and price structure, the "learn" pages and blogs.. and the YouTube videos that they post.   In simple terms:  their leaders (management) and people (staff) make a difference. .. and the big surprise:  They're located in New York City.  Have a look at their "about" and "privacy" page on their website, I think you'll be impressed too.

I recently placed my sixth order with them.  I'm expecting delivery in a couple days.  My first order was in December of 2015.  Everything has gone smoothly and as expected.

As for "shipping charges":  Yeah, who doesn't like "free shipping". .. I go for that with Amazon all the time. .. but isn't it better to have a cheaper "real price" for an item than a price that has been "bumped up" to cover that free shipping?  If nothing else, by charging actual shipping charger, it's a more "honest" way of doing business.  I feel that this is what I get from Adafruit.

Cheers!

// Brian

No comments:

Post a Comment