[SOLVED]Using i2c and analog pins at the same time.

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?

No, those pins are just duplicates of A4/A5. Once you enable I2C the hardware takes over control of those pins.

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

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

A6 a7 are analog input only and may or may be present at header pins. Check schematic on board you are using.

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.

Jeebiss: 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.

You can get an analog multiplexer:


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.

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

Ah, thanks for the info guys!

The Uno only has dedicated pin headers. They physically connected to A4 and A5.

MAS3: 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.

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.

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.