As the title says... Chat on...

User avatar
By raz123
#7835 Using the ESP8266-01, I am trying to read the states of GPIO:0 and GPIO:2 as I am applying either 3.3 v or 0 v to them.
As can be seen below, I have been getting very strange results:

Code: Select allVoltage |  Pin  |  Mode  |  Value returned
3.3 v    GPIO:0   Pullup    1
3.3 v    GPIO:0   Float     1
3.3 v    GPIO:2   Pullup    1
3.3 v    GPIO:2   Float     1
0 v      GPIO:0   Pullup    1
0 v      GPIO:0   Float     1
0 v      GPIO:2   Pullup    1
0 v      GPIO:2   Float     1


This is the code that I ran:

Code: Select allfunction readpin (pin, mode)

     -- Mode = 0 means float. Mode = 1 means pullup.
     gpio.mode(pin, gpio.INPUT, mode)
     print("PIN" .. pin .. "=" .. gpio.read(pin) .. ", in mode: " .. mode)

end

readpin(0, 0)
readpin(0, 1)
readpin(2, 0)
readpin(2, 1)


The code returned these results (for both 3.3 v and 0 v):

Code: Select allPIN0=1, in mode: 0
PIN0=1, in mode: 1
PIN2=1, in mode: 0
PIN2=1, in mode: 1


I have tried this with build 20150118 and build 20150108.
I must be doing something wrong. Any hints?
User avatar
By papagenic
#7843 hello,

Are the pins gpio0 and gpio2 connected to anything?
I run into this problem with a GPIO output in which I added a pullup resistor.
No matter the mode and the value I was setting the returned value after reading was 1.
try first without anything connected to the gpio pins.
User avatar
By raz123
#7870
jankop wrote:Your GPIO index is bad. GPIO0 is 3 and GPIO2 is 4, not 0 and 2.


Thanks, that was the problem. All good now.

GPIO:0 = pin 3
GPIO:2 = pin 4

Talk about non-intuitive.