ATMegau4 flashed as a Leonardo Pin Control

int pinTest = 30;

void setup() {
  Serial.begin(9600);
  pinMode(pinTest, INPUT_PULLUP);  // A0 = PF7
}

void loop() {
  Serial.println(digitalRead(pinTest));  // Expect: 1
  delay(100);
}

As the header says, I have flashed my chip with usbasp as a leonardo.

I have this very simple code snippet above which tests which pins are outputting a voltage. All pins are acting normally when being set as an input_pullup and outputting 5v, however.. A0-A3 (D18, 19, 20, 21) are outputting at 0v.

I've read that it could be something to do with JTAG, so I disabled JTAG and when running the following I do get '0x98' which indicates that its off.
avrdude -c usbasp -p atmega32u4 -U hfuse:r:-:h

So are there any ideas as to why this might be happening? I want to use them as inputs but currently can't as they are just forced down. These pins are currently connected to nothing, open circuits on all pins.

Welcome to the Forum.

Are you sure that there is a pin 30 on a Leonardo? Because I don't think there is.

Welcome to the forum

int pinTest = 30;

Are you confusing the chip pin number with the Leonardo board pin number ?

Sounds like you designed your own board. If so, please show the schematic

There is; it is the TX LED.

But the experienced problem is on A0..A3 which should work; I often use A0 with INPUT_PULLUP.


The pin30 from that code comes from the pins_arduino.h code in the leonardo folder. It seems the TXLED pin is pin D30, I've since been able to control this pin.

I first used my schematic to identify the pin on the Atmega I want to control is PF7, I then match that with the image below to see that this corresponds to Analog 0, which is D18 in the arduino_pins.h file.

Correct yep, own board.

Here is my schematic!

Never post code as an image, it is one of the most useless thing you can do.

We will never type that in.

Also it looks like you are making a mistake because as I said before there is no pin30 on a Leonard.

Hi @Grumpy_Mike. Here is the core variant code that implements Arduino pin 30 for the Leonardo board:

Its just a comment, not code? And D30 as shown at the bottom correlates to PD5, this pin I can control no problem. The problem as mentioned above is D18-D21.

Regardless of whether or not you want to classify it as code, it is indisputably text. Text should always be posted as text. It is not very helpful to post pictures of text.

Did you burn the bootloader to the atmega32u4, or at least set the fuses the same as used for the Leonardo?

I burnt the Leonardo bootloader onto the chip. Is there something else I should do regarding the fuses?

Did you burn the bootloader via Arduino IDE (i.e., Tools > Burn Bootloader), or did you do it by some other method such as using AVRDUDE directly from the command line?

I ask because Arduino IDE's "Burn Bootloader" feature actually does two separate things:

So if you used Arduino IDE, then you have already set the fuses as appropriate for the Leonardo board. However, if you used some other method then you will not have set the fuses unless you explicitly performed that operation, separate from flashing the bootloader binary.

Amazing, yep that's fixed it! Flashed it with the arduino IDE and the pin has begun acting as expected, thankyou!

Then please mark post #14 as the solution, to signal that the problem has been solved.

Apologies, yep thank you.