retouched

blakadder 2019-11-07 11:30:00 +01:00
parent 0af3fccbd5
commit 6915d825dd
1 changed files with 25 additions and 44 deletions

@ -1,36 +1,31 @@
One capability of Tasmota is that you can connect additional things to available pins on the [ESP8266](https://en.wikipedia.org/wiki/ESP8266) that controls these devices.
You can wire peripherals (sensors, displays, switches, LED lights, ...) to available pins of the [ESP8266](https://en.wikipedia.org/wiki/ESP8266) chip that controls these devices.
If a pin is defined as GPIO_USER in the module template, you can assign a function to it. (Complete [list](https://github.com/arendst/Tasmota/wiki/Components#components-list)) of functions.
> To make a link between the different naming schemes the [Pin Definition overview](https://github.com/esp8266/esp8266-wiki/wiki/Pin-definition) in the ESP8266 wiki is quite helpful.
To make a link between the different naming schemes of pins, connectors and logical functions, the [Pin Definition overview](https://github.com/esp8266/esp8266-wiki/wiki/Pin-definition) in the esp8266 wiki is quite helpful.
# :red_circle: Restrictions
## Restrictions 🚨
If you can avoid it, don't use GPIOs: **0, 1, 2, 6-11, 15 and 16**. That leaves **4, 5, 12, 13, 14** as GPIOs without any constraints. **3** being RX is also good to avoid (PWM is not working on this GPIO).
Don't use GPIO: 0, 1, 2, 6-11, 15, 16 if you can avoid it. 3 is RX, so best to avoid also (PWM not working here). That leaves 4, 5, 12, 13, 14 that don't have any constraints. The others can be used, but you have to mind the constraints outlined in [this document](https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html).
Others ***can*** be used but you have to mind the constraints outlined in [this document](https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html).
## Examples
### Connect switch
If you take a Sonoff Basic and connect a switch between pin4 (GND) and pin5 (GPIO14) of the 5 pin programming header you now have a second switch connected to the device. You can set this through the module config page as option ``09 Switch1`` or from the command line with ``gpio14 9``.
If you have fewer than two relays on the module, the additional switch(es) will not show up in the web UI and will control the single relay unless you set switchtopic to something other than 0 (either 1 or a custom topic). Once this is done the built-in switch will produce ``stat/<topic>/POWER1`` while the new switch will produce ``cmnd/<switchtopic>/POWER1``
With more relays on the modules, the additional switch will create additional POWER\<n> events without the need to set switchtopic.
You can set the mode of each switch individually with ``switchmode1`` or ``switchmode2``
### Examples
#### Connect switch
If you take a Sonoff Basic and connect a switch between pin4 (GND) and pin5 (GPIO14) of the 5 pin programming header you now have a second switch connected to the device. You can set this through the module config page as option `Switch1 (9)` or from the command line with `gpio14 9`.
See [Buttons-and-Switches](Buttons-and-Switches) for more information.
## Connect jack
#### Connect jack
Instead of connecting a switch, you could connect a 4-pin 2.5mm jack, with the pins wired:
* tip pin5 (GPIO14)
* r1 no connection
* r2 pin1 (ground)
* r3 pin4 (3.3V)
|jack|ESP8266|
|---|---|
tip pin5 |GPIO14
R1 | no connection
R2 pin1 | GND
R3 pin4 | 3.3V
You can then plug a sensor into the jack like you would to a Sonoff TH10/TH16 and define what sensor you have connected to GPIO14
## Electrical considerations
You can then plug a sensor into the jack like you would to a [Sonoff TH](Sonoff-TH) and define what sensor you have connected to GPIO14.
# :red_circle: Electrical considerations
When you switch a GPIO pin to an input and hang a long wire off of it, that wire can pick up stray signals and cause the voltage on the GPIO pin to vary. This can cause the system to think the switch has changed.
To fix this, there are several things you can do.
@ -46,22 +41,14 @@ A bypass capacitor is a small (pF range) capacitor that is connected between the
Shielding or using twisted pair wiring are other ways to reduce the effect of radio signals on the system.
Example for 10K Resistor:
![](https://user-images.githubusercontent.com/35574450/39960640-8b2735ca-5626-11e8-8128-461b6d9976ad.png)
Read here:
[#2708](https://github.com/arendst/Tasmota/issues/2708#issuecomment-388574891)
If the Sensor is connected, go on here: [Sensor Configuration](https://github.com/arendst/Tasmota/wiki/Sensor-Configuration)
# The ESP8266 - [Hardware](https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html)
[Example for 10K Resistor](https://user-images.githubusercontent.com/35574450/39960640-8b2735ca-5626-11e8-8128-461b6d9976ad.png)
(issue[#2708](https://github.com/arendst/Tasmota/issues/2708#issuecomment-388574891))
# The ESP8266 [Hardware](https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html)
## Digital I/O
Just like a normal Arduino, the ESP8266 has digital input/output pins (I/O or GPIO, General Purpose Input/Output pins). As the name implies, they can be used as digital inputs to read a digital voltage, or as digital outputs to output either 0V (sink current) or 3.3V (source current).
## Voltage and current restrictions
## :red_circle: Voltage and current restrictions
The ESP8266 is a 3.3V microcontroller, so its I/O operates at 3.3V as well. The pins are not 5V tolerant, applying more than 3.6V on any pin will kill the chip.
The maximum current that can be drawn from a single GPIO pin is 12mA.
@ -69,13 +56,11 @@ The maximum current that can be drawn from a single GPIO pin is 12mA.
The [power supplied to the device](https://www.letscontrolit.com/wiki/index.php?title=Power) is **one of the most important elements** for stable device operation. Voltage regulation issues typically result in fatal exception [fault code](https://github.com/esp8266/Arduino/blob/master/doc/exception_causes.rst) `1`. You must ensure that the device receives sufficient power (current AND appropriate voltage level). You must take into account the current that each sensor powered from the device itself will draw. Connected sensors may strain the ability of the power supply on the device to deliver appropriate power to all the components, both on-board as well as externally connected.
## Usable pins
The ESP8266 and ESP8255 have 17 GPIO pins (0-16) but several are [reserved or have constraints](https://i.imgur.com/IH1fYqF.jpg). Do not use any of the _**reserved**_ pins. If you do, you might crash your program. On the ESP8266, six pins (GPIO 6 - 11) are used to interface the flash memory (the small 8-legged chip usually right next to the ESP8266). The ESP8255 has its flash memory integrated into the chip which frees up GPIO 9 and 10.
GPIO 1 and 3 are used as TX and RX of the hardware Serial port (UART), so in most cases, you cant use them as normal I/O while sending/receiving serial data.
### Boot modes
Some I/O pins have a special function during boot: They select 1 of 3 boot modes:
GPIO15 | GPIO0 | GPIO2 | Mode
@ -102,8 +87,7 @@ The ESP8266 has a single analog input, with an input range of 0 - 1.0V. If you s
The ADC (analog to digital converter) has a resolution of 10 bits.
### Communication
## Communication
### Serial
The ESP8266 has two hardware UARTS (Serial ports):
UART0 on pins 1 and 3 (TX0 and RX0 resp.), and UART1 on pins 2 and 8 (TX1 and RX1 resp.), however, GPIO8 is used to connect the flash chip. This means that UART1 can only transmit data.
@ -111,16 +95,13 @@ UART0 on pins 1 and 3 (TX0 and RX0 resp.), and UART1 on pins 2 and 8 (TX1 and RX
UART0 also has hardware flow control on pins 15 and 13 (RTS0 and CTS0 resp.). These two pins can also be used as alternative TX0 and RX0 pins.
### I²C
The ESP doesnt have a hardware TWI (Two Wire Interface), but it is implemented in software. This means that you can use pretty much any two digital pins. By default, the I²C library uses pin 4 as SDA and pin 5 as SCL. (The data sheet specifies GPIO2 as SDA and GPIO14 as SCL.) The maximum speed is approximately 450kHz.
ESP8266 doesnt have a hardware TWI (Two Wire Interface) but it is implemented in software. This means that you can use pretty much any two digital pins. By default, the I²C library uses pin 4 as SDA and pin 5 as SCL. (The data sheet specifies GPIO2 as SDA and GPIO14 as SCL.) The maximum speed is approximately 450kHz.
### SPI
The ESP8266 has one SPI connection available to the user, referred to as HSPI. It uses GPIO14 as CLK, 12 as MISO, 13 as MOSI and 15 as Slave Select (SS). It can be used in both Slave and Master mode (in software).
### GPIO overview
[NodeMCU Labelled Pin](https://techtutorialsx.com/2017/04/02/esp8266-nodemcu-pin-mappings/) | GPIO | Function | State | Restrictions
[NodeMCU Labelled Pin](https://techtutorialsx.com/2017/04/02/esp8266-nodemcu-pin-mappings/) | GPIO# | Function | State | Restrictions
-|-|-|-|-
D3 | 0 | Boot mode select | 3.3V | No Hi-Z
D10 | 1 | TX0 | - | Not usable during Serial transmission
@ -129,7 +110,7 @@ D9 | 3 | RX0 | - | Not usable during Serial transmission
D2 | 4 | SDA (I²C) | - | -
D1 | 5 | SCL (I²C) | - | -
x | 6 - 8 | Flash connection | x | Not usable, and not broken out
x | 9, 10 | Flash connection * | | * Only available on the ESP8285
x | 9, 10 | Flash connection * | | *Only available on the ESP8285*
x | 11 | Flash connection | x | Not usable, and not broken out
D6 | 12 | MISO (SPI) | - | -
D7 | 13 | MOSI (SPI) | - | -