Go Down

Topic: Using digital pins 0 and 1 (Read 345 times) previous topic - next topic

spencer2004

I am currently working on a fairly complicated project at the moment which uses all but one pin on my Arduino Uno so I'm having to use digital pins 0 and 1 as inputs but for some reason I cannot get digital pin 0 to work whereas pin 1 works fine. Digital pin 0 seems to read high all the time but I cannot check as serial obviously wont work with pins 1 and 2 in use.

The pins are being used to detect a signal from a hall effect sensor to find the position of 2 servo motors, the inputs have 10k pull-down resistors on them.

Here is the code that reads the pins, it is run in void setup()

Code: [Select]
void calibrateMotors(){
  boolean calibrated = 0;
   motor1pos = 4096; //pretend that the motors are 4096 steps ahead of 0
   motor2pos = 4096;
   
while(calibrated == 0){
if(digitalRead(0) == HIGH){ //if input is high...
  motor1pos = 0; //motor is zeroed
}
if(digitalRead(1) == HIGH){
  motor2pos = 0;
}
if(motor1pos == 0 && motor2pos == 0){ //if both motors are calibrated...
calibrated = 1; //end the while loop
}
else{
stepperMove(0,0,1);  //otherwise move the motor(s) back a step if they arent zeroed yet
}
}
}


The pins are declared as inputs in void setup() before the code is run. Serial is not used anywhere else in the program.

So am I missing something really obvious here? I could not find any special requirments for using digital pins 0 and 1.

westfw

Pin 0 essentially has a pretty strong external pullup (1k) because of the connection to the USB chip TXdata signal (which is "high" in idle state.)
Since there is a 1K resistor, you should be ok to connect pin 0 to "stong" logic signals, but it's not ever going to behave like a true high-impedence input (and your 10k pulldown resistor won't be enough...)

Nick Gammon

Swap things around so pins 0 and 1 are used as outputs only. Use another set of pins for inputs, for the reasons westfw gave.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

spencer2004

Thanks for the quick replies. I guess I'll use them as outputs then.

Go Up