Hi,
apparently I don't know how to google properly
A simple question:
Connecting digital output to digital input,
do I need to add a pull-down or digital output LOW is a pulldown already?
Hi,
apparently I don't know how to google properly
A simple question:
Connecting digital output to digital input,
do I need to add a pull-down or digital output LOW is a pulldown already?
I meant Arduino digital input/output. Mega pins 22-37 to be precise.
If shorting output directly to input, is it possible, that input reads random values between Lo/Hi for a couple of seconds after output went from Hi to Lo?
I am connecting 4x4 keypad.
8 pins go directly to Arduino.
This should give an idea:
//test keypad
digitalWrite(23, HIGH);
if(digitalRead(31))lcdline("1");
if(digitalRead(33))lcdline("4");
if(digitalRead(35))lcdline("7");
if(digitalRead(37))lcdline("*");
digitalWrite(23, LOW);
digitalWrite(25, HIGH);
if(digitalRead(31))lcdline("2");
if(digitalRead(33))lcdline("5");
if(digitalRead(35))lcdline("8");
if(digitalRead(37))lcdline("0");
digitalWrite(25, LOW);
digitalWrite(27, HIGH);
if(digitalRead(31))lcdline("3");
if(digitalRead(33))lcdline("6");
if(digitalRead(35))lcdline("9");
if(digitalRead(37))lcdline("#");
digitalWrite(27, LOW);
digitalWrite(29, HIGH);
if(digitalRead(31))lcdline("A");
if(digitalRead(33))lcdline("B");
if(digitalRead(35))lcdline("C");
if(digitalRead(37))lcdline("D");
digitalWrite(29, LOW);
lcdline() outputs to lcd and delays execution for under a second.
However when I press the button I get all the row of buttons one after another sometimes with some button from another row included, quite randomly. Whole array of buttons is of random length too.
Edit: Not sure if this could affect anything at this scale, but connection wire is about 40cm (trimmed floppy drive cable).
We really need to see how you have it wired up and the datasheet for your 4x4 buttons
With a bit of headache because of lack of space I managed tuck in the pulldown resistors with diodes on 4 of 8 pins and everything works now. The quiestion remains - why is pull-down necessary if arduino have it buil-it?
found a tutorial on keypad and they suggest pulldown too...
http://www.instructables.com/id/Arduino-laser-detector-with-keypad/step7/Pull-down-resistors/
About wiring - the wire is going directly from keypad to Arduino in the same order as it is on keypad. The keypad itself is a standart 4x4, 1..0, A..D. Seller obviously thinks it's so common that doesn't even bother to provide a datasheet (or, as there's no print left on it, I suppose it comes from China and never had a datasheet).
why is pull-down necessary if arduino have it buil-it?
The AVR 328p chip used in arduino boards does NOT have built-in pull-down resistor option for input pins. It DOES have built in pull-up resistor option that one can enable or disable on a individual input pin basis. The default is no pull-up enabled.
If wiring a digital input pin to a digital output pin, no pull-up or pull-down resistor is required as the AVR output pins both sink and source current. However wiring two I/O pins together is always risky in case of software errors or bugs because if both pins ever became outputs at the same time and one is high and the other low output, a direct short circuit would exsist that would destroy both pins if not the whole chip.
Lefty
Yes, I see my mistake If I'd have a drawing, I'd definitely notice that pins are actually open.
Thank you very much!
Next sounds logical to me, but as my previous assumptions did too and turned out totally wrong, I'll ask
kivig:
Next sounds logical to me, but as my previous assumptions did too and turned out totally wrong, I'll ask
- basically, I can turn on Arduino pullups on inputs, set all outputs high, and probe buttons by setting one output Low?
Yes - although you will probably have to turn the diodes the other way round as well.
Works perfectly
Thanks for all the suggestions.
So, if someone stumbles on this:
Maybe just go here:
KE7GKP:
Suggest going to this forum FIRST for this sort of information. For example:
http://www.arduino.cc/playground/Main/KeypadTutorial
http://www.arduino.cc/playground/Code/Keypad
All the pins go straight to arduino. Double check not to short any output to another output!
Though as Lefty metioned about danger of shorting outputs a resistor probably should be placed on each of them to limit current draw for safety.
Setup:
//setup keypad
pinMode(23, INPUT);
pinMode(25, INPUT);
pinMode(27, INPUT);
pinMode(29, INPUT);
pinMode(31, OUTPUT);
pinMode(33, OUTPUT);
pinMode(35, OUTPUT);
pinMode(37, OUTPUT);
digitalWrite(23, HIGH);//turn pullups on
digitalWrite(25, HIGH);
digitalWrite(27, HIGH);
digitalWrite(29, HIGH);
digitalWrite(31, HIGH);//set outputs
digitalWrite(33, HIGH);
digitalWrite(35, HIGH);
digitalWrite(37, HIGH);
Loop:
//probe keypad
digitalWrite(31, LOW);
if(!digitalRead(23))lcdline("D");
if(!digitalRead(25))lcdline("C");
if(!digitalRead(27))lcdline("B");
if(!digitalRead(29))lcdline("A");
digitalWrite(31, HIGH);
digitalWrite(33, LOW);
if(!digitalRead(23))lcdline("#");
if(!digitalRead(25))lcdline("9");
if(!digitalRead(27))lcdline("6");
if(!digitalRead(29))lcdline("3");
digitalWrite(33, HIGH);
digitalWrite(35, LOW);
if(!digitalRead(23))lcdline("0");
if(!digitalRead(25))lcdline("8");
if(!digitalRead(27))lcdline("5");
if(!digitalRead(29))lcdline("2");
digitalWrite(35, HIGH);
digitalWrite(37, LOW);
if(!digitalRead(23))lcdline("*");
if(!digitalRead(25))lcdline("7");
if(!digitalRead(27))lcdline("4");
if(!digitalRead(29))lcdline("1");
digitalWrite(37, HIGH);