Go Down

Topic: [SOLVED]Using i2c and analog pins at the same time. (Read 10370 times) previous topic - next topic

Jeebiss

Oct 02, 2013, 11:25 pm Last Edit: Oct 03, 2013, 01:24 am by Jeebiss Reason: 1
So I am converting my project to run off a standalone atmega328p but I am a little confused about the i2c bus.

On the Arduino UNO R3, there are dedicated SDA and SCL pins, which I am using for my i2c devices. Im looking at the pinout of the atmega328p and it uses A5 and A4 for SDA and SCL. Are the pins that I am using on the UNO, just connected to those analog pins?

Can I use all 5 analog pins, while still using i2c?

nickgammon

No, those pins are just duplicates of A4/A5. Once you enable I2C the hardware takes over control of those pins.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

doughboy

if you really need two more analog pins, use a pro-mini, it has A6 and A7.

MAS3

That's great.
Can you point us to the pins of the pro mini which are to be used for A6 and A7 ?
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

CrossRoads

A6 a7 are analog input only and may or may be present at header pins.
Check schematic on board you are using.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

MAS3

Point is that doughboy mentioned pro mini, and according to this page that one doesn't have A6 and A7 on it's headers.
That same page does show the mini (without pro) to have these header pins, as i saw just now.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

MichaelMeissner


Can I use all 5 analog pins, while still using i2c?

Well if you don't need high speed conversion, you could also put an analog to digital i2c chip on your i2c bus.  I was just playing around with a PFC8591 that I got off of ebay this morning that has 4 analog inputs and 1 analog outputs.  This particular version has a builtin potentiometer, thermistor, and photoresistor, but you can get the PFC8591 without the add-ons.

The PFC8591 only has a resolution of 8 bits (Arduino is 10 bits).  If you need more accuracy, you can get 12 or 16-bit i2c chips.  For example: http://www.adafruit.com/products/1083.

nickgammon

You can get an analog multiplexer:

http://www.gammon.com.au/forum/?id=11976
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Jeebiss

I am in the process of converting my current project to a standalone atmega328p, to free up my UNO R3 for my other project. I pulled up the pinout of the atmega328p and am now a bit confused. The UNO has 2 dedicated pins for i2c, which I have been using, under the assumption that it would leave me all 5 analog pins. According to the pinout diagram, i2c uses A5 and A4. Does that mean I wont be able to use those analog inputs? The UNO schematic confuses me a bit, but it didnt seem to show where the i2c pins connected to, so I was hoping someone could clear it up for me.

Jeebiss

Bah, I got an error last time I posted... Sorry for the double post, thought the first didnt go through...

Jeebiss


cmiyc

The Uno only has dedicated pin headers.  They physically connected to A4 and A5.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

doughboy


That's great.
Can you point us to the pins of the pro mini which are to be used for A6 and A7 ?



Pro mini sold on eBay comes with A6 and A7 connection. You need  an ftdi or ICSP programmer to upload your sketch to the promini.

MarkT

Sparkfun do a dinky little USB->serial converter using the FTDI chip that has a
USB mini socket and a 6-pin socket header, I've had one for years, left permanently on
a USB lead, programs all my Arduino Pro Minis and other breadboarded or PCB projects.

They come in 5V and 3.3V varieties.

There are cheaper options too, but I've had my money's worth from that thing over the years.

https://www.sparkfun.com/products/9716
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

joshuabardwell


You can get an analog multiplexer:


I'm a big fan of the analog mux for expanding analog inputs. It is dead-simple to use, and the 4051 (and similar chips) have an Arduino library already written to make them even easier to use. However, if keeping pin count to the absolute minimum is a requirement, there's no substitute for I2C, and in that respect, I think an ADC is the clear winner. With a 4051, you need at least four pins: an analog in and three digital pins to select the input. If you go beyond two 4051's, the pin count goes up even higher. With I2C, it's 2 pins, and you're done.

Go Up