ATMEGA32U4 Breakout Board Issue - Analog Pins as Digital

Hey all

i have an interesting issue i can't seem to figure out. i have an ATMEGA32U4 Breakout Board running the Leonardo bootloader.

When i do: pinMode([0-17], OUTPUT); digitalWrite([0-17],[HIGH|LOW]); everything works as intended.

When i try to address the Analog Pins (A0-A5) on Port F(PF0-PF7) as Digital pins pinMode([18-23], OUTPUT); digitalWrite([18-23], [HIGH|LOW]); no dice

my question is, on the ATMEGA32U4, can the Analog Pins not be used as Digital Pins as they where on the ATMEGA328?

I don't know but, in the pin.H assignment list it does not show digital 18-23.

I would try

pinMode([A0-A5], OUTPUT);
digitalWrite([A0-A5], [HIGH|LOW])

Let us know if that works.

The position of the pins in the list is was determines their digital #.

This is from the Leonardo pins_arduino.h file,
C:\Arduino-1.0\hardware\arduino\variants\leonardo\pins_arduino.h

So the pins do seem to be defined.

const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
PD, // D0 - PD2
PD, // D1 - PD3
PD, // D2 - PD1
PD, // D3 - PD0
PD, // D4 - PD4
PC, // D5 - PC6
PD, // D6 - PD7
PE, // D7 - PE6

PB, // D8 - PB4
PB, // D9 - PB5
PB, // D10 - PB6
PB, // D11 - PB7
PD, // D12 - PD6
PC, // D13 - PC7

PB, // D14 - MISO - PB3
PB, // D15 - SCK - PB1
PB, // D16 - MOSI - PB2
PB, // D17 - SS - PB0

PF, // D18 - A0 - PF7
PF, // D19 - A1 - PF6
PF, // D20 - A2 - PF5
PF, // D21 - A3 - PF4
PF, // D22 - A4 - PF1
PF, // D23 - A5 - PF0

PD, // D24 / D4 - A6 - PD4
PD, // D25 / D6 - A7 - PD7
PB, // D26 / D8 - A8 - PB4
PB, // D27 / D9 - A9 - PB5
PB, // D28 / D10 - A10 - PB6
PD, // D29 / D12 - A11 - PD6
};

Thanks CrossRoads. I double checked my pin assignment in the code and it is accurate to my wiring and the pins_arduino.h

Although while double checking my design to the pins_arduino.h i noticed some duplication of port usage for A6 - A11 (see below)

CrossRoads: const uint8_t PROGMEM digital_pin_to_port_PGM[30] = { PD, // D0 - PD2 PD, // D1 - PD3 PD, // D2 - PD1 PD, // D3 - PD0 PD, // D4 - PD4 PC, // D5 - PC6 PD, // D6 - PD7 PE, // D7 - PE6

PB, // D8 - PB4 PB, // D9 - PB5 PB, // D10 - PB6 PB, // D11 - PB7 PD, // D12 - PD6 PC, // D13 - PC7

PB, // D14 - MISO - PB3 PB, // D15 - SCK - PB1 PB, // D16 - MOSI - PB2 PB, // D17 - SS - PB0

PF, // D18 - A0 - PF7 PF, // D19 - A1 - PF6 PF, // D20 - A2 - PF5 PF, // D21 - A3 - PF4 PF, // D22 - A4 - PF1 PF, // D23 - A5 - PF0

PD, // D24 / D4 - A6 - PD4 PD, // D25 / D6 - A7 - PD7 PB, // D26 / D8 - A8 - PB4 PB, // D27 / D9 - A9 - PB5 PB, // D28 / D10 - A10 - PB6 PD, // D29 / D12 - A11 - PD6 };

Does the Leonardo do some kind of multiplexing on those pins? I did notice in the datasheet that these are ADC8 - ADC13, but as i understand you either would use them as A6-A11 or D4, D6, D8, D9, D10, D12 not both.

Also asked this in the Adafruit forum and got this answer about the lack of Digital support on Analog 0-5 "this is a bug in the leonardo support for Arduino - its still beta so we suspect it will be fixed when its out of beta " "this is part of the IDE itself, no idea how to fix it."

I suspect you as the coder will have to do the multiplexing if the pins are connected to the same header pin. If using an Analog pin, then the digital pin will have to pinMode'd as an input so as not to interfere, as an example.

I know this is 3 years after the original post, but maybe this will help someone. II had the same problem using my own ATmega32u4 on a breakout board where I could not use the analog pins as GPIO. I discovered it was because the JTAGEN fuse bit was set. When this bit is set, the Port F pins are all pulled high. Disable the fuse and it should start working as expected.

1 Like

you can use the extra Analogs as inputs same as you would A6 and A7 on the pro

int state;
state = analogRead(A6) > 100 ? 0 : 1;