D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#1 Post by Oetsch » 06 Sep 2020, 19:49

Hi
today I finished connecting all equpiment I like to connect to a D1 Mini which is running ESPEasy.
In total should be connected:
-RCW-0001 Ultrasonic Distance Sensor
-Max7219 Display
- 4 Switches
- 4 LED
- 1 RGB LED using R&G
In total the GPIOs are not sufficient so I planned to expanded the GPIOs by 1x PCF8574.
But today I added to the working RCW+Max7219+ 2 Switches (Start & Stop) the rest of 4 LEDs + 1 RGB LED and 2 Switches. This addition also included the PCF8574 and finally I identified that 1 GPIO is missing. Had only GPIO16/D0 free but had the need to connect 2 Switches (Start & Stop) which before already worked at GPIO4 & 5. But 4&5 are now used for I2C connection.

Therefore I thought it should be possible to disable serial communication in the advanced ESPEasy settings and make use of GPIO 1 & 3 for these two switches. But so far it isn´t possible/working. The Push Button push isn´t recognized by ESPEasy and I´m struggeling why.

In general all switch are connected to GND and the push connects GND to the GPIO.
The LEDs are connected to 3,3V (Anode) and the Cathode is connected to a GPIO (of course a resistor in between).

Can you please help me checking if this is possible what I like to do (first) usage of GPIO 1 & 3 for the 2 switches and (second) if my allocation in general can be used this way. I´m struggeling with the settings and the charakteristics auf the GPIOs (PullUp or No-Pullup internal etc etc.)

Thank you very much in advance. In case any information are needed please let me know.

Thx!
Attachments
allocation.JPG
allocation.JPG (115.4 KiB) Viewed 20055 times
IMG_20200906_180943.jpg
IMG_20200906_180943.jpg (685.06 KiB) Viewed 20058 times
1599397291683-eseasy.png
1599397291683-eseasy.png (44.67 KiB) Viewed 20059 times

User avatar
Ath
Normal user
Posts: 3515
Joined: 10 Jun 2018, 12:06
Location: NL

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#2 Post by Ath » 06 Sep 2020, 20:52

This looks like a setup that should work (I've re-used RX and TX myself in several ESP01's and Sonoff S20's), but you really need to use external pull-ups when connecting switches/buttons, so the only question I can think of right now is: Have you used external pull-ups (4k7 - 10k) on RX and TX?

(The internal pull-ups are way to high in ohm (80k - 100k) to work reliably for wires > 10 cm, they act as antennas when not closed)
/Ton (PayPal.me)

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#3 Post by Oetsch » 06 Sep 2020, 21:14

Thx for your reply.
No I have not used external pullups for RX & TX. As you can imagine from the pictures (D1 mini inside of this Box) the Red and Green Button are connected directly to GPIO 1 & 3.
The Buttons (other Pin) are all connected to GND. For the connection from button to GPIO I used prefabricated Dupont cables and cutted them by ~3/4 so would guess the cable is ~7/8cm long.

Sorry, a bit late for me....you suggest connecting 3,3V -> 4,7kOhm->GPIO in addition to pull the GPIO up to high level in case push button is not pressed, right?

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#4 Post by TD-er » 06 Sep 2020, 21:57

Also make sure to disable the serial port in the Tools => Advanced settings page.

It is best to add a resistor in series with the switch to prevent the connected ESP and/or USB to serial chip.
For example if the output of the pin is driving the pin high and you're shorting it directly to GND, you may exceed the max. current delivered by the chip that's driving the pin high.
Please have a look at the schematic of the NodeMCU, which is using a small (470 Ohm?) resistor just for this purpose.

The pull up should be something like 4k7 - 15k.
The exact value depends a bit on your application.
Usually 10k or 12k is used on NodeMCU boards as pull-up value.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#5 Post by Oetsch » 06 Sep 2020, 22:15

Thx!
TD-er wrote: 06 Sep 2020, 21:57 Also make sure to disable the serial port in the Tools => Advanced settings page.
done
TD-er wrote: 06 Sep 2020, 21:57 It is best to add a resistor in series with the switch to prevent the connected ESP and/or USB to serial chip.
For example if the output of the pin is driving the pin high and you're shorting it directly to GND, you may exceed the max. current delivered by the chip that's driving the pin high.
Please have a look at the schematic of the NodeMCU, which is using a small (470 Ohm?) resistor just for this purpose.
Checked and according the schematics i found the 470Ohm are only shown for TX. RX is directly connected. Better also use 470Ohm in series or skip it here?
TD-er wrote: 06 Sep 2020, 21:57 The pull up should be something like 4k7 - 15k.
The exact value depends a bit on your application.
Usually 10k or 12k is used on NodeMCU boards as pull-up value.
Thx, have 10k & 12K ready for use.

I´ll thank you very much but because I´m out for business now I will have access for changing these on friday.

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#6 Post by TD-er » 06 Sep 2020, 22:26

Oetsch wrote: 06 Sep 2020, 22:15 [...]

I´ll thank you very much but because I´m out for business now I will have access for changing these on friday.
Well better to be out for business than out of business :)

RX is directly connected to the TX of the USB to serial chip? Then that chip may use a pull-up resistor somewhere.

The 470 Ohm resistor in series of the TX ( you also see 500 Ohm some times) is to prevent "ringing" in the signal where the sent signal may reflect back to the chip.

What I meant was the separate part of the NodeMCU schematics where they describe the resistors surrounding the push buttons of the board.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#7 Post by Oetsch » 06 Sep 2020, 22:42

TD-er wrote: 06 Sep 2020, 22:26
Oetsch wrote: 06 Sep 2020, 22:15 [...]

I´ll thank you very much but because I´m out for business now I will have access for changing these on friday.
Well better to be out for business than out of business :)
true :)
TD-er wrote: 06 Sep 2020, 22:26 What I meant was the separate part of the NodeMCU schematics where they describe the resistors surrounding the push buttons of the board.
Think you mean this. see attached and will add this resistor for RX & TX.
Attachments
470.JPG
470.JPG (28.02 KiB) Viewed 20020 times

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#8 Post by TD-er » 06 Sep 2020, 22:46

Yep, but keep in mind GPIO-0 is already pulled up by a 10k or 12k resistor to make sure it boots in the correct mode.

GPIO-0, GPIO-2 must be pulled up at boot
GPIO-15 must be pulled down at boot.

GPIO-16 is special as it cannot have an interrupt set to its state.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#9 Post by Oetsch » 06 Sep 2020, 23:03

Ok, thx so should be fine for GPIO 1 & 3 to pull up by 10k/12k and put 470Ohm in series each. GPIO16 will stay free as spare.

The rest would be fine if i did somthing right today and therefore not have to dismount everything again? :)

Can you say if PCF8574 also needs a external Pullup?
Just connected Push Button to GND & LED in series with an Resistor to sink to PCF8574 PIN.

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#10 Post by TD-er » 06 Sep 2020, 23:20

I don't know from my own experience what the internals of the PCF8574 can or can't do.
Maybe also have a look at the wiki: https://www.letscontrolit.com/wiki/inde ... le=PCF8574

GPIO-16 can still be used for driving a LED if you need to.
But I guess adding a GPIO-expander is the best option here.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#11 Post by Oetsch » 07 Sep 2020, 09:03

Thx, the PCF8574 is already in place and connected.

Because Start/Stop Button at GPIO 1/3 will earliest work on friday, I thought of using the other 2 buttons (yellow, blue) which are connected to pcf8574 for start/stop until then.

Selection possibility by MotorOperatedValves isn´t mounted yet.

Checked the wiki regarding PCF8574 before and this helped to build up the LED circuit to sink the current, because current operability is limited.
But I´m not sure how in detail the switch input should be configured and later on the result will look like.

e.g. Because of sink the current I thought of "Inversed Logik" in the setup must be ticked?
Based on this the switches are showing a result of -1 at the moment without beeing pushed. This looks strange to me because expecting a 0.
Attachments
pcfswitch.JPG
pcfswitch.JPG (58.67 KiB) Viewed 20001 times
devices.JPG
devices.JPG (82.42 KiB) Viewed 20001 times

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#12 Post by Oetsch » 07 Sep 2020, 12:17

Ah, the I2C Scan does not show the PCF8574 anymore. There must be a problem. Will check the wiring on friday.

User avatar
Ath
Normal user
Posts: 3515
Joined: 10 Jun 2018, 12:06
Location: NL

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#13 Post by Ath » 07 Sep 2020, 13:08

Oetsch wrote: 07 Sep 2020, 12:17 Ah, the I2C Scan does not show the PCF8574 anymore. There must be a problem. Will check the wiring on friday.
Does it show the address? In that case: code has been changed that on 'memory challenged' builds the names of I2C devices are no longer shown, only the address is shown, as this is a fixed set of names, but that costs some resources that are left out in this build.

If it says 'No I2C devices found' (or smth similar) then you could have a wiring issue.
/Ton (PayPal.me)

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#14 Post by Oetsch » 07 Sep 2020, 13:56

Ath wrote: 07 Sep 2020, 13:08
Oetsch wrote: 07 Sep 2020, 12:17 Ah, the I2C Scan does not show the PCF8574 anymore. There must be a problem. Will check the wiring on friday.
Does it show the address? In that case: code has been changed that on 'memory challenged' builds the names of I2C devices are no longer shown, only the address is shown, as this is a fixed set of names, but that costs some resources that are left out in this build.

If it says 'No I2C devices found' (or smth similar) then you could have a wiring issue.
Thx, had seen adress 0x20 after a scan on sunday but now it shows "No I2C devices found" so there is sth wrong I have to check.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#15 Post by Oetsch » 07 Sep 2020, 15:18

I have an additional question regarding boot behavouir of GPIO 1 & 3.
Just got a call that the pump was running which is coused by a true value which is send by GPIO1 over Mqtt (log file told me that).
Nobody has pushed a button or the Start button but I have rebooted the ESP8266 several times.
So I think the GPIO1 changed it´s value during reboot. Is there a fix bahvouir so I can prevent for unwanted starts?
Think reboot of the ESP8266 can happen at everytime this should be considered by me.

Do not believe this can be solved by a rule inside of the ESP8266 because during this short GPIO signal the EasyESP software is maybe not running, right?
Or simply do?:

Code: Select all

on System#Boot do
  gpio,1,0
  gpio,3,0
endon

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#16 Post by TD-er » 07 Sep 2020, 16:02

It is always a good idea to initialize the values at boot.
Also the ESP does output some data to the serial port during boot, so if the pins must absolutely not be changed at boot, then you should use another pin.

See:
https://espeasy.readthedocs.io/en/lates ... on-esp8266
http://rabbithole.wwwdotorg.org/2017/03 ... -gpio.html
https://randomnerdtutorials.com/esp8266 ... nce-gpios/

Last one might be the most clear to read as they do have a nice table with boot states.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#17 Post by Oetsch » 08 Sep 2020, 10:02

TD-er wrote: 07 Sep 2020, 16:02
https://randomnerdtutorials.com/esp8266 ... nce-gpios/

Last one might be the most clear to read as they do have a nice table with boot states.
Thx, this table/information is great! So will reallocate the buttons for start/stop to other GPIOs. Seems to be better/easier than filtering a valid push or unvalid high from boot procedure.

Do not have a feeling which of my used equipment is to be used best / uncritical for this bootup behaviour of (High) GPIO 1 & 3.

According the table I will first try GPIO 12 & 13 for the buttons. The Trigger of the RCW-0001 distance sensor and the CS-Pin auf the Max7219 will then be connected to GPIO 1 & 3. Hope this will work stable.

Or according this link and my experience. GPIO 4 & 5 is most uncritical and will work for the push buttons. But I use I2C now and these are the standard GPIOs. So have to switch I2C to other GPIOs. Do not know if the I2C communication ports "like" a high at bootup or this is uncritical.
Attachments
gpio-table.JPG
gpio-table.JPG (85.02 KiB) Viewed 19947 times

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#18 Post by TD-er » 08 Sep 2020, 11:44

I2C is most of the time quite forgiving.
Only some devices may act a bit strange, but as long as the clock and the data line are not likely to act together, I don't think any device may think it is addressed.
If so, you can also swap the SDA/SCL.

I think it is best to use at least those pins that allow to be pulled up, or are already pulled up.
So GPIO-15 is a big no-no for I2C and GPIO-16 as that one doesn't allow interrupts.

But better test first. I'm not 100% sure if ESP82xx does act differntly on using other pins for I2C, but I know some available boards do have other pins assigned, so it should work just fine I guess.

GPIO-0 is also perfectly fine for a button, as long as you don't press it during boot.
For example Sonoff's use GPIO-0 always for a button, which makes flashing also a lot easier.

GPIO-2 is often connected to the LED. Some ESP12E/F/S modules have a blue LED on the module itself, which is then connected to GPIO-2. (inverted)

If you need UART, you can also swap the pins of Serial0 to GPIO 15 and 13 (need a PNP transistor on GPIO15 to make sure it can boot).
This way you have hardware UART and not using the pins that will receive data during boot, before ESPEasy is sending anything.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#19 Post by Oetsch » 09 Sep 2020, 12:15

Thx, think now I have to try and see what will work.
Current status is to start testing according following re-allocated asignment:
Attachments
Reassignment.JPG
Reassignment.JPG (32.49 KiB) Viewed 19922 times

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#20 Post by Oetsch » 11 Sep 2020, 17:21

Big Thx! According this allocation it is working and so far also by reboot of the ESP8266 no High signal/Start signal according the push buttons.
Think this is the solution for me, Thx!

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

Re: D1 Mini usage of GPIO1&3 (RX/TX) for Switches and general allocation?

#21 Post by TD-er » 11 Sep 2020, 20:36

Good to know it is working OK.
Have fun with it.

Post Reply

Who is online

Users browsing this forum: No registered users and 119 guests