Go Down

Topic: My i/o pins (0-5) are having Opposite Day... (Read 838 times) previous topic - next topic

Somaxman

Mar 01, 2009, 09:47 am Last Edit: Mar 01, 2009, 09:50 am by Somaxman Reason: 1
Hi.
I'm completely new to this, so I might ask stupid questions.
But: Yesterday I finally invested and bought the equipment I needed to start my Arduino project/experiment/whatever. I wanted to use all the digital i/o pins and wired everything together, only to find that some of them are working the opposite way I tell them.
They are always set to HIGH, and I have to switch them manually to LOW. Even if they are in input mode, I have to tell them to be on LOW.
Srsly guys, WTF?
I've had it only for a week. Even the bag was closed, sealed back in its original state. I opened it only for testing on pin 13. (god, I didn't test the others...)

[glow]tl;dr:[/glow] Some pins are set to HIGH without a reason. What should I do?


SORRY GUYS! I DIDN'T REALIZE THAT THERE IS A TROUBLESHOOTING BOARD! Mods, pls move this thread.

Digger450

Can you post your code and some more information about what you are trying to accomplish?  Do you actually have all of your hardware hooked up when you are getting the strange results?

Somaxman

Now that was a fast response:D

The funny thing is, that I've tried almost everything.
I mean after running our own code we decided to run some "official" stuff. Thats why we tried the button tutorial which comes with the SDK.
Unfortunately it is also working in this funny manner, because the input pin is specified as the number 2.

Is my board completely faulty?
I'm not an expert, but can a corrupted bootloader cause all my problems?
I really don't want to return the board. I hope I can manage to unbrick this with some kind of reprogramming.

Oh, yeah, we wanted to write a simple "driver" for a 5x5 led matrix.

Anachrocomputer

Can you please be much more specific in exactly what code you are running, how you have the hardware wired up, what happens/doesn't happen and what machine/OS you are using as the host?  Thanks!

Somaxman

So, to make it clear, I run the example code called "Button" which came with the software programmer.
I am on WinXP SP2, using standard Arduino Duemilanove.

If you don't have the examples, here is the exact code:
Code: [Select]
/*
* Button
* by DojoDave <http://www.0j0.org>
*
* Turns on and off a light emitting diode(LED) connected to digital  
* pin 13, when pressing a pushbutton attached to pin 7.
*
* http://www.arduino.cc/en/Tutorial/Button
*/

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for a pushbutton)
int val = 0;                    // variable for reading the pin status

void setup() {
 pinMode(ledPin, OUTPUT);      // declare LED as output
 pinMode(inputPin, INPUT);     // declare pushbutton as input
}

void loop(){
 val = digitalRead(inputPin);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
   digitalWrite(ledPin, LOW);  // turn LED OFF
 } else {
   digitalWrite(ledPin, HIGH); // turn LED ON
 }
}


What happens is this: The led connected to pin 13 and grounded at the GND pin next to pin 13 does not light up initially (as it should), only if I connect pin 2 to a GND pin (I used the on next to the 5V pin).
The same happens if I modify the inputPin to any other between 5 and 0.
That's what I call the opposite.

If there is anything I didn't tell, please ask.

halley

#5
Mar 01, 2009, 04:13 pm Last Edit: Mar 01, 2009, 04:14 pm by halley Reason: 1


This is the hardware hookup for Tutorial Button.  (Except the green wire should go to Digital I/O 2 if your code is expecting digital I/O 2.)

Note the use of a resistor.  This "pull down" resistor keeps the input LOW when the button is not making any connection to HIGH.  If you don't wire the button this way, then the input will be either HIGH or "floating," picking a value you can't easily predict.

(You don't need an additional LED on the Duemilanove, there's one near Digital I/O 13 on the board that will light up when you output HIGH to that pin.)

Somaxman

Wow, thanks, I didn't realize the necessity of that resistor.
But either way, according to the program the led should be lit, if I don't give the input pin any voltage (I mean I don't even touch it with any wire, just leave it). Am I wrong?

And yeah, if I change the inputPin variable back to 7, it will work correctly, with the led turning off on button press. The only pins not behaving well are 0,1,2,3 and 4.
(sorry, now that I tested again, the fifth one is working after all)

Anachrocomputer

Quote
I mean I don't even touch it with any wire, just leave it


An unconnected input on the Arduino will "float" unpredictably HIGH or LOW, seemingly at random.  That's why you always need a resistor as either a pull-up or a pull-down.

Somaxman

Thanks, I'll try.
So it is normal.
The only question is now: why do the first five pins work differently than the others? (Because on the other pins I didn't need a resistor, the arduino just worked according to its program).

halley

Anachrocomputer wrote, "seemingly at random."  I wrote, "that you can't easily predict."  However, I have also written that it can be swayed by the proximity of moisture, the phase of the moon, your mayor's preference in cuisine, and other environmental conditions.

The first few pins belong to one hardware register, the next few pins belong to a different hardware register.  It's conceivable that this difference alone is part of the equation on your board, and probably more conceivable than what flavor of cheese is in your mayor's pantry.  That said, I haven't seen any difference between inputs 0-5 and inputs 6-13 here on my board, and I'm not surprised by that fact.

Go Up