Page 1 of 1

How to read GPIO state?

Posted: 14 Apr 2018, 12:24
by NickOver
Hi!
I have second blocking problem.
I connect ESP-01 as following:
https://imgur.com/a/TxlXn

On raspberry i set GPIO2 as out with high state (i check it with multimeter).
I setup ESP as following:
https://imgur.com/a/n4XIC
But as value i have only 0.
What im doing wrong?

Re: How to read GPIO state?

Posted: 14 Apr 2018, 16:33
by Tommmii
without knowing your exact usage case, I believe what you need to do is go into the devices tab, and create a Switch on the pin that is connected to your R-Pi.

Re: How to read GPIO state?

Posted: 14 Apr 2018, 17:14
by NickOver
My usage case is pretty simple. ESP are connected to device sending low or high state. I need read that state by http request (i know how ;)) but all time in /pinstates i got 0.
It's how i set :
https://imgur.com/a/wAa3k

Re: How to read GPIO state?

Posted: 14 Apr 2018, 17:19
by Tommmii
I had a tough time figuring out the same....
But got through it finally.

You can not leave Send to Controller IDX = 0
Set any value, but not 0.

use this as a baseline :
https://www.letscontrolit.com/wiki/inde ... sy_Devices

and I prefer to check the devices page (http://<IP ESPEASY>/devices ) to see the state of the pin, or the web logging in tools.

Re: How to read GPIO state?

Posted: 14 Apr 2018, 17:28
by NickOver
I check 'Send To Controller' And set idx to 1, but still in /pinstates it show 0

Re: How to read GPIO state?

Posted: 14 Apr 2018, 17:34
by Tommmii
I wouldn't use GPIO 0 because that's the pin that you need to set low to get into flash mode.
Are you using a pullup resistor ?
http://www.letscontrolit.com/forum/viewtopic.php?t=1718

Forget about /pinstates , i do not know what its purpose is.
Just tested it, the state doesn't move.
Like I said earlier, use /log , that refreshes automatically.
Or use /devices , but you need to refresh manually.

Also :
http://www.forward.com.au/pfod/ESP8266/ ... index.html

Re: How to read GPIO state?

Posted: 14 Apr 2018, 17:49
by NickOver
I think only if i give to CH_PD high state gpio0 are determinate flashing mode.
Ok, i change to gipo2, but still without any results. Changing state doesn't give any result.

EDIT
It's strange but when i check 'Invereted output) in /devices value dont change.

Re: How to read GPIO state?

Posted: 15 Apr 2018, 11:36
by Tommmii
I messed up the previous post with inline images. Starting over...


Here's my config, only big diff being i'm on an ESP32.
The theory of functioning is the same though.

https://imgur.com/a/28JbC

On the hardware side, I do not think that you can just connect any pin on the esp to a gpio on the Pi.
You will certainly need a resistor in there.
But there are dozens of videos and tutorial with schematics that explain how to add a simple button to the esp8266-01

Re: How to read GPIO state?

Posted: 15 Apr 2018, 11:57
by NickOver
I don't understand why it doesn't work.
I set everything almost as you:
https://imgur.com/a/BUMm4
set high state on gpio2 and all time i get 0.
I try select all pins, but always i got 0.

Re: How to read GPIO state?

Posted: 15 Apr 2018, 11:59
by Tommmii
are you refreshing the /devices page ?
Or are you watching the logging ?
Or are you still on that /pinstates page ?

Re: How to read GPIO state?

Posted: 15 Apr 2018, 12:01
by NickOver
Yeah, i refresh /devices tab.
In log i have only info about network

EDIT
I got something. In log i got:
1504911 : SW : Switch state 1 Output value 1
And after set low state i got 0 but after a long time. Is ESP need minute or two to update GPIO state?

Re: How to read GPIO state?

Posted: 15 Apr 2018, 12:05
by Tommmii
in your device config, i notice that you are not using the "internal pullup".
In this case, you need to add a resistor in the circuit for sure.

If gpio-2 has an internal pullup available, then you need to activate this if you do not want to add your own external resistor into the circuit.
I have no idea if gpio-2 on the esp826-01 has internal pullup available or not.

Re: How to read GPIO state?

Posted: 15 Apr 2018, 12:24
by NickOver
Ok, i check time between update and now esp need more than 7 minutes to update pin state. Can i speed up this?
EDIT
Now update from high to low lested something near minute. How it's work?

Re: How to read GPIO state?

Posted: 15 Apr 2018, 12:29
by Tommmii
doesn't seem right.
It should be nearly instant...

Are you sure there isn't a delay at the R-Pi side ?

Not sure if related : do you have a controller defined?
Because it _looks_ as if the device config is pointing to Controller/IDX 1 ?
I would change this to smt like 100, at least while experimenting.

Re: How to read GPIO state?

Posted: 15 Apr 2018, 13:10
by TD-er
You can set the loglevel of the serial port (or the web log view) to at least "info" level and keep an eye on those logs.
The switch state should be near instantaneous. You can set it as "normal switch", which just reports the state of the pin.

And you should indeed look at the pull-up resistor state. Either internal, or add some resistor external to pull it to 3V3.
If there is no (or incorrect) pull up, you are just waiting for a fluke to happen to trigger the state above some level.