GPIO
The ESP8266ex chip has 9 freely usable digital pins. Each can be used as input, output, or PWM (quasi-analog output).
Each pin has a software-switchable pull-up resistor of approximately 50k. The inputs are 5V tolerant. This means that even though the module operates at 3.3V,
if a pin is programmed as an input with the PULL-UP resistor disabled or set as an OPEN-DRAIN output, 5V can be applied to it without causing damage.
When programmed as an output, each pin can handle a maximum current of 12mA according to the IC datasheet. The GPIO command is used to control these pins and read their status. It can automatically execute other commands when certain events occur.
Pin designation: D0-D8, A0. These are labeled on the WeMos D1 mini module. Note that these labels are not the actual chip IO ports!
WeMos PIN ESP8266 PIN Function WeMos resistor BOOT OK
D0 io16 WakeUP Not internal x
D1 io5 I2C CLOCK x x
D2 io4 I2C DATA x x
D3 io0 x 10k pullup HIGH
D4 io2 Built in LED 10k pullup HIGH
D5 io14 SPI SCLK x x
D6 io12 SPI MISO x x
D7 io13 SPI MOSI x x
D8 io15 SPI CS 10k pulldown LOW
A0 A0 Analog Input x x
RESET RESET RESET 10k pullup HIGH
It is not advisable to use pins D3, D4, and D8 as inputs, as the module may not boot if the signal levels are not appropriate during power-up!
The ESP8266 A0 analog input can be used between 0V-1V. The WeMos module A0 pin goes to the chip via a divider, so the input range is 0V-3.3V.
TXD, RXD pins are connected to the WeMos module CH341 USB-SERIAL converter and are not used.
Digital Input/Output
GPIO[D0]@
Queries the pin status regardless of the data direction.
GPIO[D5]CL:LED(OFF);STD@OFF
If the pin switches from HIGH to LOW, the LED turns off. Data direction does not matter. (Command Low)
GPIO[D5]CH:LED(ON);STD@ON
If the pin switches from LOW to HIGH, the LED turns on. Data direction does not matter. (Command High)
GPIO[D5]C
Executes the command corresponding to the pin status
GPIO[D5]PU
Enables the PullUp resistor. Default: OFF
GPIO[D5]PU!
Disables the PullUp resistor.
GPIO[D5]IN
Sets the pin as an input.
GPIO[D5]@IN
Sets the pin as an input and sends its status to STDOUT.
The @ character can also be used in other commands in this form.
GPIO[D5]INP
Sets the pin as an input and enables the PullUp resistor.
GPIO[D5]INR
Sets the pin as an input and repeats the CL: CH: commands.
GPIO[D5]INPR
Sets the pin as an input and enables the PullUp resistor and repeats the CL: CH: commands.
GPIO[D]IR=1000
Sets the repeat time, unit: milliseconds. Default:50, Min:5
This applies to all GPIO pins simultaneously.
GPIO[D1]OD
Enables OpenDrain output mode. Default: OFF
GPIO[D1]OD!
Disables OpenDrain output mode.
GPIO[D1]L
Sets the pin as an output with a LOW logic level.
GPIO[D1]H
Sets the pin as an output with a HIGH logic level.
GPIO[D1]I
Sets the pin as an output with an INVERTED logic level.
GPIO[D1]LC
Sets the pin as an output with a LOW logic level and executes the Command Low command.
GPIO[D1]HC
Sets the pin as an output with a HIGH logic level and executes the Command High command.
GPIO[D1]$
Saves the pin status to flash memory.
GPIO[D1]!$
Deletes the saved status from flash memory.
GPIO[D1]RS
Resets the settings (CL, CH, PU, OD, IR), sets the pin as an input with the PullUp resistor disabled.
GPIO[D]IN
Sets all pins as inputs.
GPIO[D]INP
Sets all pins as input and enables the PullUp resistors.
GPIO[D]L
Sets all pins as outputs with a LOW logic level.
GPIO[D]LO
Sets all pins as outputs in OpenDrain mode with a LOW logic level.
GPIO[D]H
Sets all pins as outputs with a HIGH logic level.
GPIO[D]HO
Sets all pins as outputs in OpenDrain mode with a HIGH logic level.
Analog Input
GPIO[A0]@
Sends the value of A0 to STDOUT.
GPIO[A0]CC:NUM[0]@=%A0
If the analog level of the pin changes, the current value is stored in NUM[0] and written to STDOUT. (Command Changed)
GPIO[A0]AR=100
Sets the range of A0. Default:255 (0V=0, 3.3V=255)
After issuing the command, 0V=0 3.3V=100. Valid: 2-1024.
GPIO[A0]RS
Resets the settings (CC, AR).
PWM Output
GPIO[D1]@
Sends the value of D1 to STDOUT.
GPIO[D1]P=128
Outputs a PWM signal with a 50% duty cycle on pin D1.
GPIO[D1]PI=25
Outputs a PWM signal with a 90% duty cycle (inverted) on pin D1.
This is useful, for example, if something is connected between an OpenDrain pin and 5V.
GPIO[D1]P=NUM[0]
GPIO[D1]PI=NUM[0]
The duty cycle of pin D1 is set by the value of NUM[0].
GPIO[D1]P+10
GPIO[D1]PI+10
The duty cycle of pin D1 increases by 10 units.
GPIO[D1]P-10
GPIO[D1]PI-10
The duty cycle of pin D1 decreases by 10 units.
GPIO[D]PR=100
Sets the PWM range. Default:255 (0=0%, 255=100%)
After issuing the command, this changes to 0=0% 100=100%. Valid:15(!!!)-65535
This applies to all GPIO pins simultaneously.
GPIO[D]PF=8000
Sets the PWM frequency. Default:1000. Unit: Hz
After issuing the command, this changes to 8kHz. Valid:100-40000.
This applies to all GPIO pins simultaneously.
GPIO[D1]P=A0
GPIO[D1]PI=A0
The duty cycle of pin D1 is set by the value of A0.
The ranges must match! For example: GPIO[D]PR=100|GPIO[D]AR=100
GPIO[D1]P==A0
GPIO[D1]PI==A0
The duty cycle of pin D1 is set by the value of A0. It updates automatically.
NVR
NVR[0]=P=210
GPIO[4]=NVR[0]
The value of NVR[0] non-volatile memory will be the status of GPIO[4].