Go Down

Topic: New Arduino has mind of its own? (Read 346 times) previous topic - next topic

egaertner

My very first Arduino arrived in the mail today, and it already seems to have a mind of its own!

Looking at the code below, I'm using pin 12 as an input, and pin 11 as an output. Pin 12 is pulled down during initialization, and during the main loop, yet when I poll the read register it returns high some of the time. A common serial output would be 0,0,0,1,1,1,1,0,1,1,1,1,0,1,1 for instance, sometimes changing on it's own, although handling the device seems to provoke changes too.

I have found this only happens when pin 11 is outputting high. If I remove pin 11 from the code, or replace pin 11 with any other pin (10,9,etc), there is no problem.

So my first thought was a short on the board. I examined the board, scraped off any loose hairs, everything looks clean. I buzzed it with a DMM and it couldn't detect any short, infinite impedance.

Now I'm at a loss for what to do. I was so excited to start on some projects. Any suggestions? (I purchased from Lady Ada btw)

Thanks,
Erc

Quote


int inputPin = 12;
int outputPin = 11;
int status;

void setup()                    // run once, when the sketch starts
{
 pinMode(outputPin, OUTPUT);
 pinMode(inputPin, INPUT);
 digitalWrite(outputPin, HIGH);
 digitalWrite(inputPin, LOW);
 Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}

void loop()                     // run over and over again
{
 digitalWrite(outputPin, HIGH);
 status = digitalRead(inputPin);
 Serial.println(status);
 delay(1000);
}



mewControl

This line in Setup()

digitalWrite(outputPin, HIGH);

sets the internal pullup resistor on the microprocessor.

The main loop then tries to set the output for that pin high again.  In other words, there will be no change in state.  Seems to me the code is behaving as expected.

Try digitalWrite(outputPin, LOW); in your setup routine and see if that changes things.

egaertner

Correct, I didn't expect it would do anything, but I had the line in there to try and "hold" it to a state just in case. If I change the line to write LOW as you suggest, then the serial output will always print 0 as the state of the input pin.

Previously I had that code line controlling the input pin instead, trying to hold it low with the internal pull-up, to no avail. Regardless of what I do, if that output pin is high, and I have a pull-down on the input pin, the input pin acts flaky.

ladyada

there is no such thing as an internal pulldown
there is only an internal pullup
your arduino is fine, the input is floating, and when you touch it, the bodys capacitance changes the values. this is completely normal

egaertner

Quote
there is no such thing as an internal pulldown
there is only an internal pullup
your arduino is fine, the input is floating, and when you touch it, the bodys capacitance changes the values. this is completely normal


Yup, what she said. Everything is fine, pin was just floating when I thought it was pulled down.

Thread closed, thanks all.

Go Up