Pages: [1]   Go Down
Author Topic: A to D converter onboard  (Read 956 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all. I understand the arduino has a A to D converter on it so there is a line of analogue inputs to the arduino. If i have an external A to D converter can i somehow put that information into the digital pins. I understand digital pins can either be high or low but is that reading as well or just writing. Just dont understand how the arduino reads the digital side once its gone through the converter.
Any help much appreciated
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read the datasheet for the part you want to use.
Most use I2C or SPI for interfacing.
The chip does the conversion, then sends the results as 2 bytes to the arduino.
See mcp3201 as an example.
http://ww1.microchip.com/downloads/en/DeviceDoc/21290F.pdf
See section 6.1
Basically you do this:
Code:
digitalWrite (SSpin, LOW);
upperbyte = SPI.transfer(0);  // dummy transfer of 0 out, while reading  data in at the same time
lowerbyte = SPI.transfer(0); // with other chips, these might be real data out, to select a channel for instance
digitalWrite(SSpin, HIGH);
then do a little manipulation to grab the 12 bits from the 2 bytes: put the 2 bytes together to make an int, and shift right 2 bits to drop the duplicate B0/B1 bits.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I sort of underatnd that but i thought the digital pins on the arduino could only read high or low. I could put a A to D converter before the arduino but does it still have to communicate through the analogue ports. I dont understand how the digital pins can read 2 bytes.
Thanks
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try reading CrossRoad's post again. If necessary, Google for I2C and SPI.
Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10442
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

They are both serial data protocols that transfer more than one bit - a succession of bits is sent and reassembled at the receiving end.  They are both command/response protocols where the microcontroller starts a transaction and generates the timing/clocking.  They both deal in bytes (octets).  Most sensors and devices than connect to a microcontroller use these or similar protocols rather than the parallel interfaces common in microprocessors.
Logged

[ I won't respond to messages, use the forum please ]

Santa Fe
Offline Offline
Full Member
***
Karma: 1
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I sort of underatnd that but i thought the digital pins on the arduino could only read high or low. I could put a A to D converter before the arduino but does it still have to communicate through the analogue ports. I dont understand how the digital pins can read 2 bytes.
Thanks

If you already have an A/D converter, you do not hook it up to the analog pins. It will already have converted the analog signal to a digital output. the output come into the Arduino through a digital pin one bit at a time. That means basically, that if it is a 12 bit A/D then you send out a pulse (clock signal) from another pin on the Arduino 12 times to read all of the 12 bits in. There are lots of scripts that show how to do this. You need to know the sequence of clock pulses that are needed to obtain the total reading sent from the A/D. If you are a complete novice programmer, developing your own script may be pretty frustrating. If the chip you are using already has a script or library written for it, then the task becomes much easier.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No worries. I do understand now so rather than just reading the input it would get a signal through the digital pins of it being high then low and so on. Thanks for the help i now know where to start and how to add extra analogue pins to the arduino or to a module.
Thanks
Logged

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 4
Posts: 297
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I sort of underatnd that but i thought the digital pins on the arduino could only read high or low
Perhaps your confusion is in not being aware that the arduino is reading the digital pin (detecting either a high or low) very quickly 16 times to gather in two bytes of data.

I am a newbie, myself. Perhaps the veterans here might need to correct me but this is the way I think it works.

- Scotty
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23748
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are correct in your understanding Scotty.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah that is what i figued thanks for clearing everything up.
Logged

Pages: [1]   Go Up
Jump to: