Arduino – accessing extra analog pins on 32-pin SMT package

arduino

I've got a 32-pin ATMega328 on a breadboard. I have its analog pin #6 as an input pin from another IC on my board. The IC sends data to this analog pin.

Now, the ATMega328 DIP package (used on the Uno, and other default arduino boards), has 28 pins (instead of 32), and only 6 analog pins (numbered 0-5) total.

I don't get any complaints from the compiler, and am able to upload code successfully to the arduino.

I bootloaded the board using optiloader.

Problem

Using my scope, I expect to see signals coming from the IC, but I just see a flat-line signal. My guess is that, by choosing 'Arduino Uno' as my board from within the Arduino IDE, the code dealing with setting up the analog pin 6 is ignored, because the compiler assumes there is no analog pin 6 on this board. Therefore, the analog pin is automatically just pulled down to zero, and any variations in voltage coming from the IC output pin are brought down to 0 by virtue of being connected to analog pin 6.

Attempted Solution

I tried switching the board I use from the Uno to the Nano (with ATMega328), since the Nano actually runs on the same 32-pin SMT package I'm using.

But now I can't get even the most basic sketch to upload to the board. I tried selecting a few other boards from the menu in the Arduino IDE, and am unable to upload code using any selection besides the Uno.

I'll keep hacking away and researching. Any solutions popping out?

Best Answer

The platform as selected by the boards.txt file directs pins_arduino.h that correspond the unique pinouts of each platform. Where the UNO's 328 is defined to use \arduino\variants\standard\pins_arduino.h. aka the standard. Which has the pins A6 and A7 defined but the NUM_ANALOG_INPUTS to 6 not eight. Note the IDE 1.0.5 boards.txt for the Nano, Fio and Mini's all use a variant of eightanaloginputs which simply includes the ../standard/pins_arduino.h and replaces the NUM_ANALOG_INPUTS to 8. Allowing the extra AD6 and 7 to be accessed.

Note the compiler will work regardless, likely using the value of 0. But will have problems running.

Noting that the value falls to 0, or pin offset zero, this will likely map to PD0 or RXD, as attempting to be configured as an input. Where I suspect (not sure) that OptiBoot may have a smaller window for the Flashing, which may be missed by the IDE and the standard platform.

Where looking at OptiBoot's boards.txt I see "minio.name=[Optiboot] Arduino Mini" using the "minio.build.variant=arduino:eightanaloginputs"