little_birdie
little_birdie

Reputation: 5867

How to disable input pullup on Arduino (Atmega1284p). Regular methods don't seem to work

Using the "Mighty Mini" board which uses the Atmega1284p processor, with Arduino IDE 2:1.0.5 on Raspbian, with Mighty Mini "board" files installed.

I was having some erratic behavior on inputs, so I checked it with a 'scope and it seems that although I have not enabled the internal pullup, I have +3.3v appearing on the input pin. I need the pin to float.

I ran a simple test to make sure it wasn't a coding issue:

void setup() {
    pinMode(8, INPUT);
}

void loop() {
}

According to the docs, this should put the pin in a high impedance state. But a scope shows ~3.2 volts on the pin even when I connect a 1K resistor to ground. So the pin is definitely being driven.

I decided to try accessing the registers directly, eg:

void setup() {
    DDRA = 0;
    DDRB = 0;
    DDRC = 0;
    DDRD = 0;

    PORTA = 0;
    PORTB = 0;
    PORTC = 0;
    PORTD = 0;
}

void loop() {
}

This didn't work either.. still +3.3v on the pin. I've also tried different pins.

I thought that possibly the board definition for the Mighty Mini could have gotten the register defines wrong.. but it's worked perfectly in every other way.. my actual application uses SPI, I2C, Serial, Tone.. a lot of hardware I/O.. and other than this problem it works perfectly.. so I hesitate to blame the libraries when everything else seems to run correctly.

Thanks!

Upvotes: 0

Views: 6401

Answers (2)

Jeff Loughlin
Jeff Loughlin

Reputation: 4174

When you configure a pin as an input, you can enable or disable the internal pullup by writing HIGH (enable) or LOW (disable) to the pin:

pinMode(8, INPUT);
digitalWrite(8, LOW); // disable internal pullup

Arduino documentation https://www.arduino.cc/en/Reference/DigitalWrite states:

If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the digital pins tutorial for more information.

Upvotes: 2

mactro
mactro

Reputation: 518

It seems you have wiring problem somewhere, or you are doing your measurements wrong. Internal pullups in ATmega are 10k, so if you connected a pin to GND through 1k resistor, you got a voltage divider, which would output 0.3V.

My advice: double check all the connections. Test a pin as an output using blinky example code.

Upvotes: 1

Related Questions