| Function | Definition |
|---|---|
| gpio.mode() | Define the GPIP Pin mode, set the pin to input output or interrupt mode |
| gpio.read() | Read the pin value |
| gpio.write() | Set the pin value |
| gpio.toggle() | Toggle the pin’s output value |
| gpio | Function |
|---|---|
| gpio.INPUT | Input with an internal pull-up resistor |
| gpio.INPUT_PULL_UP | Input with an internal pull-up resistor |
| gpio.INPUT_PULL_DOWN | Input with an internal pull-down resistor |
| gpio.INPUT_INPUT_HIGH_IMPEDANCE_DOWN | Input high impedance down |
| gpio.OUTPUT | Output actively driven high and actively driven low |
| gpio.OUTPUT_PUSH_PULL | Output actively driven high and actively driven low |
| gpio.OUTPUT_OPEN_DRAIN_NO_PULL | Output actively driven low but is high-impedance when set high |
| gpio.OUTPUT_OPEN_DRAIN_PULL_UP | Output actively driven low and is pulled high with an internal resistor when set high |
| gpio.INT | Interrupt |
| gpio.HIGH | High voltage level |
| gpio.LOW | Low voltage level |
| WiFiMCU Index | Alternative Function | Discription |
|---|---|---|
| D0 | GPIO/BOOT | WiFiMCU would enter into Bootloader Mode, if D0 goes to LOW |
| D1 | GPIO/PWM/ADC | - |
| D2 | GPIO | - |
| D3 | GPIO/PWM | - |
| D4 | GPIO | - |
| D5 | GPIO | SWD Flash Programming Pin: swclk |
| D6 | GPIO | SWD Flash Programming Pin: swdio |
| D7 | GPIO | - |
| D8 | GPIO/PWM | Uart1 rx pin: RX1 |
| D9 | GPIO/PWM | Uart1 tx pin: TX1 |
| D10 | GPIO/PWM | I2C interface: SCL |
| D11 | GPIO/PWM | I2C interface: SDA |
| D12 | GPIO/PWM | - |
| D13 | GPIO/PWM/ADC | - |
| D14 | GPIO/PWM | - |
| D15 | GPIO/PWM/ADC | - |
| D16 | GPIO/PWM/ADC | - |
| D17 | GPIO/ADC | A LED is connected on WiFiMCU board |
Description
Define the GPIP Pin mode, set the pin to input output or interrupt mode.
Syntax
gpio.mode(pin, mode)
gpio.mode(pin, gpio.INT, trigMode, func_cb)
Parameters
pin: gpio ID, 0~17
mode: Should be one of the followings:
gpio.INPUT
gpio.INPUT_PULL_UP
gpio.INPUT_PULL_DOWN
gpio.INPUT_INPUT_HIGH_IMPEDANCE_DOWN
gpio.OUTPUT
gpio.OUTPUT_PUSH_PULL
gpio.OUTPUT_OPEN_DRAIN_NO_PULL
gpio.OUTPUT_OPEN_DRAIN_PULL_UP
gpio.INT
trigMode: if mode is gpio.INT, trigMode should be:
‘rising’: Interrupt triggered at input signal's rising edge
‘falling’: Interrupt triggered at input signal's falling edge
‘both’: Interrupt triggered at both rising and falling edge
func_cb: if mode is gpio.INT, the interrupt call back function
Note: It’s recommend that DO NOT do too much time consumption operations in the func_cb.
Returns
nil
Examples
-gpio.mode(0, gpio.OUTPUT)
-gpio.write(0, gpio.HIGH)
-gpio.mode(1,gpio.INPUT)
-print(gpio.read(1))
-0
Description
Read the pin value.
Syntax
value=gpio.read(pin)
Parameters
pin: gpio ID, 0~17
Returns
value: 0 - low, 1 - high
Examples
-gpio.mode(0, gpio.INPUT)
-print(gpio.read(0))
-0
Description
Set the pin value.
Syntax
gpio.write(pin, value)
Parameters
pin: gpio ID, 0~17
value: 0 or 1 or gpio.HIGH or gpio.LOW
Returns
nil
Examples
-gpio.mode(0, gpio.OUTPUT)
-gpio.write(0,gpio.HIGH)
-gpio.write(0,0)
Description
Toggle the pin’s output value
Syntax
gpio.toggle(pin)
Parameters
pin: gpio ID, 0~17
Returns
nil
Examples
-gpio.mode(17, gpio.OUTPUT)
-gpio.toggle(17)