Pages: [1]   Go Down
Author Topic: Trying to use digital input 0 & 1 as button inputs - unsucsesfully  (Read 591 times)
0 Members and 1 Guest are viewing this topic.
Cape Town, South Africa
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Time to get the projects going
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello people

I went through the forum and read that you can't use digital pins 0 & 1 as inputs or outputs if your using serial communication i.e. serial begin. Now I'm trying to use it as button inputs but it is not working, I'm not using serial print and my wiring is the same as in the arduino button example of here: http://arduino.cc/en/Tutorial/Button

If I move my button inputs to digital pins 2 & 3 it is working like a charm but on 0 & 1 it just won't budge. With the project I'm currently working on the only available pins are digital pins 0 & 1, the rest are all used and I want to move the buttons located at 2 & 3 to 0 & 1 so that I can use the PWM output at pin 3 and use pin 2 to switch something on and off.

When I connect my buttons inputs to pins 0 & 1 and I press one of the buttons then the TX led lights up, I don't know if this might be a clue. Any input would be greatly appreciated. Thank you very much.  smiley-eek-blue
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Confirm you're not calling Serial.begin()?

Post your code and we might be able to offer better answers.

-br
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't use that external pull-down resistor on pin 0 because there is a de facto pull-up resistor already on pin 0 from the USB serial converter chip. If you wish to use a button on pin 0 just wire it from ground to pin 0 and a digitalRead LOW will mean the button is being pressed and a reading of HIGH will mean it's not being pressed. Pin 1 can use a pull-down resistor if you wish but it's simpler to just enable the internal pull-up resistor and wire the button between pin 1 and ground and have it return the same values as pin 0 would do.

Lefty
Logged

Cape Town, South Africa
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Time to get the projects going
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@ Billroy

No I'm not calling Serial.Begin()

@ Retrolefty

Thanks for the feedback I will try that, just one question. Is there a specific piece of code that I must use to enable the internal pull-up resistor or is it enabled by default?

Thanks for the feedback gents
Dirk
Logged

Värmland, Sweden
Offline Offline
Sr. Member
****
Karma: 9
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do it by setting pinMode to INPUT_PULLUP like this
Code:
pinMode(1, INPUT_PULLUP);
http://arduino.cc/en/Reference/PinMode

You can also do it by just setting your input pin HIGH
Code:
digitalWrite(1, HIGH);
This was the way to do it in older versions.
Logged

Cape Town, South Africa
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Time to get the projects going
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Perhof

Yes I just came across that piece of code. Thanks for sharing, but it turned out that I didn't have to enable the internal pull-up resistor on digital I/O pin 1. I also connected it the same way as described by Retrolefty and it's working splendidly. Now I've got my PWM output pin open with an additional I/O pin. Thanks everyone for the input and I hope that each one of you will enjoy a wonderful day.

Dirk
Logged

Pages: [1]   Go Up
Jump to: