I use a button on digital pins 0 and 1. To test, I do not use serial because those pins are in use for serial.
I display the results on an lcd.
This is my code (below).
I simply get a 0 or 1 to see the status of the buttons.
when no pin connected to a button, both are on 1 (high).
when I connect a button to pin 0, it stays on 1, nothing hapens.
Pin 1 works fine, when I connect the button to it, it show a 0, and when pressed it shows 1.
But why isn't it working on pin 0?
I tried two arduino deumilanove's, both the same results.
You seem to use the switch to pull the pins to high. The standard way to connect switches is to pull pins to low. In addition it is common to enable the pullups such that pins will default to high. Your code did not activate the pullups hence my suspicion. If I am guessing right then the FTDI is basically as a pullup rendering your switch useless.
--> Connect the switches to GND instead of 5V and reverse your evaluation logic. And do not forget to activate the pullups.
I need to use pin 0 and 1 simply because I don't have any digital or analog pins left for my project (flashlight).
This is how I connect buttons... http://www.ledcreations.net/buttoncircuit.jpg
I can't make big modifications on the circuit, whats the easiest way to make pin 0 work?
"--> Connect the switches to GND instead of 5V and reverse your evaluation logic. And do not forget to activate the pullups."
one button pin to pin 0, the other button pin to GND? No resistor in between?
And I need to add "digitalWrite(pin,HIGH); " to void setep code?
Pin 1 works fine, but strange thing is, when nothing is connected to that pin, it's already high, not like the other pins that are low when not used.
But when connected the button like I did, i't does go low, and high again when the button is pressed.
The FTDI is making pin 1 go high to?
Why does a connected button makes pin 0 not low to, like pin 1?
They both have a pull down resistor of 10K, why is that not enough?
Update...
I have tested it, a line from pin 0 to GND does make it go low.
The easiest way to correct my circuit is to change the 10K pull down resistor into a 500 Ohm resistor.
It pulls it down from a minimum of 1K, but goes down to slow after the button is pushed. A 500 Ohm works fine.
Good idea?
The best thing I can do now is taking the GND to pin 0 with a switch in between.
The serial won't be afected if the button is not pushed, but it will bring the pin low when pushed.
I tested it without resistor, works fine, is it better do use a resistor between pin 0 and GND?
mwhens:
The best thing I can do now is taking the GND to pin 0 with a switch in between.
The serial won't be afected if the button is not pushed, but it will bring the pin low when pushed.
I tested it without resistor, works fine, is it better do use a resistor between pin 0 and GND?
Here is whats happening.
The USB serial chip when there is no serial communications being sent by the PC is in a idle condition, which is a HIGH and wired to pin 0 through a series 1k resistor, this is therefore acting just like a pull-up resistor wired to +5vc. Grounding out pin 0 through a switch wired to ground will override that high and read as a valid low. Because of the 1k resistor there will be no harm to the usb serial data output pin wired to pin 0. Also having your switch wired like that will work without harming uploading as long as you don't press the switch, as you already figured out.
However when you wire a switch to ground and then on to a arduino digital input pin there is always the risk of a 'brain fart' where in your sketch by accident you change the pin to be an output pin and set it to high and then if you press the switch, you will be short circuiting the high output pin to ground, destroying the pin. So for safety I would recommend you wire your switch as follows, digital pin > switch terminal1> switch terminal2> 150 ohm resistor > ground. Then it will still function as a switch to low when pressed for a digital input pin, but will limit current to a safe value if pressed if the pin is, in error, set to output mode and then set high.
That makes sence.
I will instal a 150 Ohm resistor to be sure.
This kind of information should be in "getting started" .
When beginners start making there own projects, this would surprise everyone.
Just like PWM pin 5 and 6 share timing functions, and PWM pin 3 and 11 can't work with tone command.
And now, pin 0 is pulled high. And pin 0 and 1 can't be used when serial is active.
mwhens:
That makes sence.
I will instal a 150 Ohm resistor to be sure.
This kind of information should be in "getting started" .
When beginners start making there own projects, this would surprise everyone.
Just like PWM pin 5 and 6 share timing functions, and PWM pin 3 and 11 can't work with tone command.
And now, pin 0 is pulled high. And pin 0 and 1 can't be used when serial is active.
The problem is that there can be so many possible software and hardware conflicts that any newcomer using a 'getting started" would most likely be overwhelmed by it all. Also some problems are specific to a given board model or arduino IDE version number. Many of the conflicts have to do with 3rd party contributed libraries that the arduino team has nothing to do with. In a perfect world we would have perfect documentation, in the mean time just be thankful that we have this great forum to post about questions and problems we are having at times.