How to read GPIO state?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

How to read GPIO state?

#1 Post by NickOver » 14 Apr 2018, 12:24

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?

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#2 Post by Tommmii » 14 Apr 2018, 16:33

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.

NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

Re: How to read GPIO state?

#3 Post by NickOver » 14 Apr 2018, 17:14

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

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#4 Post by Tommmii » 14 Apr 2018, 17:19

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.

NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

Re: How to read GPIO state?

#5 Post by NickOver » 14 Apr 2018, 17:28

I check 'Send To Controller' And set idx to 1, but still in /pinstates it show 0

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#6 Post by Tommmii » 14 Apr 2018, 17:34

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

NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

Re: How to read GPIO state?

#7 Post by NickOver » 14 Apr 2018, 17:49

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.

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#8 Post by Tommmii » 15 Apr 2018, 11:36

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

NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

Re: How to read GPIO state?

#9 Post by NickOver » 15 Apr 2018, 11:57

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.

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#10 Post by Tommmii » 15 Apr 2018, 11:59

are you refreshing the /devices page ?
Or are you watching the logging ?
Or are you still on that /pinstates page ?

NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

Re: How to read GPIO state?

#11 Post by NickOver » 15 Apr 2018, 12:01

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?
Last edited by NickOver on 15 Apr 2018, 12:06, edited 1 time in total.

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#12 Post by Tommmii » 15 Apr 2018, 12:05

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.

NickOver
Normal user
Posts: 13
Joined: 13 Apr 2018, 18:57

Re: How to read GPIO state?

#13 Post by NickOver » 15 Apr 2018, 12:24

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?

Tommmii
Normal user
Posts: 37
Joined: 06 Apr 2018, 12:37

Re: How to read GPIO state?

#14 Post by Tommmii » 15 Apr 2018, 12:29

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.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to read GPIO state?

#15 Post by TD-er » 15 Apr 2018, 13:10

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 20 guests