Hi,
could someone explain me why pullup/pulldown for some pins works for some no ?
I tried on arduino uno and mega.
I'm doing simple test like:
void setup() {
Serial.begin(9600);
for (int i=0; i < 54; i++)
{
pinMode(i, INPUT_PULLUP);
//digitalWrite(i, LOW);
}
for (int i=0; i < 54; i++)
{
int state = digitalRead(i);
Serial.print(i);
Serial.print(" state " );
Serial.println(state);
}
}
which gives me on output
PULLUP
0 state 1
1 state 0
2 state 1
3 state 1
4 state 0
5 state 1
6 state 1
7 state 1
8 state 1
9 state 1
10 state 1
11 state 0
12 state 1
13 state 0
PULLDOWN
0 state 1
1 state 0
2 state 1
3 state 1
4 state 0
5 state 0
6 state 0
7 state 0
8 state 0
9 state 0
10 state 1
11 state 0
12 state 1
13 state 0
could someone explain me why pullup/pulldown for some pins works for some no ?
There are no pulldown resistors, so that's easy to explain.
Some pins, like 0 and 1, have other purposes. Pins 0 and 1 are the hardware serial pins that Serial uses. You can't expect to use them for Serial and other purposes at the same time.
We can not see what else you have attached to the Arduino, so we don't know what other pins are also being used.
Even though the default is to set the pins LOW, it doesn't hurt to do it again, to make sure.
I did not connect anything to arduino - all Im doing is setting pins.
For example when try to set all pins to LOW on arduino mega here response:
-some of pins are set to LOW some not
0 state 1
1 state 0
2 state 0
3 state 0
4 state 0
5 state 0
6 state 0
7 state 0
8 state 0
9 state 0
10 state 0
11 state 0
12 state 0
13 state 1
14 state 0
15 state 0
16 state 0
17 state 0
18 state 0
19 state 0
20 state 1
21 state 1
22 state 1
23 state 1
24 state 1
25 state 1
26 state 1
27 state 1
28 state 1
29 state 1
30 state 1
31 state 1
32 state 1
33 state 1
34 state 1
35 state 1
36 state 1
37 state 0
38 state 0
39 state 0
40 state 0
41 state 0
42 state 0
43 state 0
44 state 0
45 state 0
46 state 0
47 state 0
48 state 0
49 state 0
50 state 0
51 state 0
52 state 0
53 state 0
So you set ALL pins to LOW - assuming pinMode(x, OUTPUT) and without anything being connected to the pins you check their state using digitalRead(x).
Never mind that you are messing around with Serial pins ( wonder where are all your Serial prints coming from ?) , what else is wrong with this picture?
In my test I set all pins to low as input - which do not work for all pins. Some of them are low some high.
We can exclude pins 0 and 1 from tests as they are serial pins.
Currently my question is why pullup works on arudinos without ethernet sheld - but when I plug in ethernet sheld pins 4,13,51 and 52 dont want to set to HIGH.
I tried on 2 different arudinos and 2 different eth sheld - both cases same result
In my test I set all pins to low as input - which do not work for all pins.
If you do this:
pinMode (pinX, INPUT);
and then
digitalWrite (pinX, LOW);
followed by
Serial.read(digitalRead (pinX));
what happens is that the digitalWrite turns off the internal pullup resistor only (if it was on), and you are reading an CMOS input that is floating. The input pins only need 1uA to change them form low to high, or high to low, or to float in the nether region between high and low (~0.9V to 3V for a 5V powered Mega), and return an unknown 0 or 1 when read.
use this pinMode (pinX, INPUT_PULLUP);
to turn on the internal pullup, do not turn them off, and your reads will always be 1 unless something is pulling them low.
lonas:
Ok I see in specification that pin 4 is used for SD card and pins 10.11.12,13 used by eth sheld- what abuot 51 and 52 ?
Pins 50 to 53 are used by SPI on the Mega, which the Ethernet shield uses. It mightn't be obvious, but that 6-pin plug in the middle connects to the SPI pins, which are 50 to 53.
I did not connect anything to arduino - all Im doing is setting pins.
...
I've noticed one more thing like when I plug off ethernet sheld - pullup seems to work / pulldown (set LOW - not works)
Nothing apart from that whopping great shield, eh?