Go Down

Topic: Using Pins 13 / 0 / 1 as Digital Input to Arduino (Read 992 times) previous topic - next topic

lasithg

Hi There,
I have a requirement where all the Digital Input Pins, apart from 0,1 and 13 are utilized. I have read documentation which indicates that one should steer away from those pins, unless unavoidable. In my case I can't avoid them : I need one more input.

My Input is a from a Set of photo transistors (Which would output either 0 or +5V). When I connect it as it is to Pin13, the values jump to 0 in some cases where I would expect 1(+5). I've connected a 10K Resistor to the Input and grounded it, but it hasnt done much difference.

Can someone advice me on whether the above is the best option in this case ?. Note that I tried to connect Pin 0 and 1 without success...

Thanks in advance
LG

retrolefty

Pin 13 drives a on-board series resistor and led and this may on may not cause a problem with your photo-transistor trying to drive the input pin high due the the current draw of the led and 1k ohm series resistor. If you are using a Uno or Mega Rev3 board then it should work as there is a op-amp driving the led but on other older boards there is just the load of the led/resistor seen on the shield pin 13. Are you using up all your analog input pins, as they can also be used as digital input or output pins?

Lefty

lasithg

Thanks retrolefty for the prompt reply. My Board is a Uno R2. So I guess that One Option is out...However, Yes All my Analog Pins are free...I'll check that option out. Many Thanks!

dc42

You could use pin 13 as an input of you desolder the LED connected to that pin. You should also be able to use pin 1 as an input, but you may have to disconnect the phototransistor (or at least keep it in the dark) when uploading sketches.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

fungus

Pins 0 and 1 can be used as inputs so long as you disconnect the device when you need to upload a sketches.

But...you have to disable the USART because it overrides the normal pin functions. The code for this is:

Code: [Select]

UCSR0B = 0;


Using pin 13 as an input is more difficult.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

lasithg

Thanks Fungus!. Although I tried to use Pin 1,0 while unplugging it during uploading sketches it didnt work. I'll try this too...

retrolefty

The OP already stated he is not presently using his analog input pins, so he has no need to utilize pins 0,1, and 13.

Lefty

fungus


The OP already stated he is not presently using his analog input pins, so he has no need to utilize pins 0,1, and 13.

Lefty



Oh, yes!  :D

No problem then, he's got another 6 pins...

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

lasithg

Thanks Everyone, I've used the Analog Input to work it around and works fine. But I'll try to use the UCSR0B = 0; option too. I assume it's in the setup phase in code ?.

dc42


Pins 0 and 1 can be used as inputs so long as you disconnect the device when you need to upload a sketches.

But...you have to disable the USART because it overrides the normal pin functions. The code for this is:

Code: [Select]

UCSR0B = 0;



Shouldn't the USART be disabled already when the sketch starts, assuming no Serial.begin() call is made?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

fungus


Shouldn't the USART be disabled already when the sketch starts, assuming no Serial.begin() call is made?


Let's try it and see...

Code: [Select]

void setup()
{
  int a = UCSR0B;
  Serial.begin(115200);
  int b = UCSR0B;
  Serial.println(a,HEX);
  Serial.println(b,HEX);
}
void loop()
{
}


That printed "0" and "0x98" so it looks like you're right.

I've could swear I've seen threads where that fixed it though. Maybe they'd called Serial.begin() before they tried to use it.

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Clemens


Are you using up all your analog input pins, as they can also be used as digital input or output pins?


This is a good suggestion. You can find more information about use _analog_ input pins as _digital_ input pins under

http://arduino.cc/en/Reference/Board
Quote
Most of the analog inputs can also be used as digital pins: analog input 0 as digital pin 14 through analog input 5 as digital pin 19.


lasithg

Thanks Clemens and Everyone Else...Yes I do confirm using the Analog Pins as Digital Input Pins (Addressing Analog Pin0 as Digital Pin 14 ..) and it works fine. I did not have to use Digital Pins 0,1 and 13.

Go Up