0
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ Try using low level port access for the pin: If you see the Arduino source code, there is some housekeeping code in the GPIO library functions that validates pin numbers as per whichever board you build for. The actual hardware does not get disabled by the libraries, so it's still there for you to use. \$\endgroup\$ – Anindo Ghosh Aug 27 '13 at 19:11
  • \$\begingroup\$ You are on the right track in selecting a board that has that analog input. Since its on a breadboard, can you disconnect the the other IC that is putting out the analog signal and see if the signal looks good? That will tell you if the Arduino pin is not correctly configured as an input. \$\endgroup\$ – BrianK Aug 27 '13 at 19:12
  • \$\begingroup\$ In the particular case of ADC6 & ADC7 on an ATmega328, there is no GPIO functionality, and no need to configure them as an input, because they are exclusively hooked up to the A/D MUX. Reading through the analogRead() source code in github.com/arduino/Arduino/blob/master/hardware/arduino/cores/…, I don’t see any overzealous validation that would prevent ADC6/7 from being usable even in a 6 analog input board configuration. \$\endgroup\$ – microtherion Aug 27 '13 at 22:20
  • \$\begingroup\$ You are probably unable to program your Uno as a Nano because the Uno uses a 115200 baud bootloader and the Nano uses a 57600 baud. Create a new entry which is a synthetic combination with the appropriate properties of each in your boards.txt, restart the IDE, select the custom board, and you should be fine. Or just edit the uno ADC setting and remember that yours is custom. \$\endgroup\$ – Chris Stratton Sep 26 '13 at 20:29
1
\$\begingroup\$

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"

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.