GitHub

GPIO Instructions

Cập nhật 4 phút đọc 27/09/2026

EG800K & EG800AK Module — Part 1: GPIO

This document summarizes how GPIO can be used on QuecPython firmware for the Quectel EG800K and EG800AK modules, including the machine API. Battery, logical level read/write, external interrupt configuration (ExtInt), and practical considerations when deploying.

1. Overview

GPIO (General-Purpose Input/Output) is a general-purpose I/O pin, configurable as an input or output for logic-level read/control (0/1). On QuecPython, GPIO is manipulated through machine modules, the Pin layer (for conventional I/O) and the ExtInt class (for external interrupts).

Important Note: The GPIOn number in the code (e.g. Pin.GPIO1) is the logical number of QuecPython, NOT the number of physical pins on the module. Each module line (EG800K, EG800AK, EC800M…) has its own GPIO – Physical Pin mapping table, and not all GPIOs are available or free (some are occupied by default functions such as UART, SIM, LED network status, etc.). Always check the “GPIO multiplexing table” in the Hardware Design of the correct model before connecting.

2. Machine grade. Battery

2.1. Initialization

from machine import Pin

# Pin(GPIOn, direction, pullMode, level)
gpio1 = Pin(Pin.GPIO1, Pin.OUT, Pin.PULL_DISABLE, 1)

ParameterTypeMeaning
GPIOnintThe logical GPIO number, using the Pin.GPIOx constant (x according to the module’s mapping table) or a direct integer.
directionintI/O Dimension: Pin.IN (input) or Pin.OUT (output).
pullModeintPin.PULL_DISABLE (float), Pin.PULL_PU (pull up), Pin.PULL_PD (pull down).
levelintInitialization logic level when configuring OUT: 0 (low) or 1 (high).

2.2. Main methods

MethodDescription
read()Read the current logic level of the pin (returns 0 or 1).
write(value)Write the logic level to the pin: write(0) = low pull, write(1) = high drag.
set_dir(direction)Change I/O direction while running: Pin.IN or Pin.OUT.
get_dir()Returns the current I/O dimension of the pin.

2.3. Example: LED strobe / relay control

from machine import Pin
import utime

led = Pin(Pin.GPIO1, Pin.OUT, Pin.PULL_DISABLE, 0)

while True:
    led.write(1)
    utime.sleep(1)
    led.write(0)
    utime.sleep(1)

from machine import Pin

# Read push button status (pull up, low level positive)
btn = Pin(Pin.GPIO2, Pin.IN, Pin.PULL_PU, 1)

if btn.read() == 0:
print(‘Button Pressed’)

3. External interruption — machine. ExtInt

In addition to regular read/write, most GPIOs on QuecPython (except for some specific chips such as BG95) support rising/falling.

3.1. Initialization

from machine import ExtInt

def gpio_irq_cb(args):
# args[0]: GPIO number interrupts
# args[1]: trigger edge(0 = rising, 1 = falling)
print(‘IRQ from GPIO:’, args[0], ‘wing:’, args[1])

extint1 = ExtInt(
ExtInt.GPIO2,
ExtInt.IRQ_RISING_FALLING,
ExtInt.PULL_PU,
gpio_irq_cb,
)
extint1.enable()

# When no longer used:
# extint1.disable()

ParameterMeaning
GPIOnGPIO number (refer to Pin Modules of the correct model).
modeIRQ_RISING / IRQ_FALLING / IRQ_RISING_FALLING.
pullPULL_PU / PULL_PD / PULL_DISABLE.
CallbackThe callback function receives tuple args (args[0]=GPIO, args[1]=trigger edge).
filter_time(Optional) noise filtering time, in ms, must be a multiple of 10.

4. Practical differences between EG800K and EG800AK

  • They both share an API machine. Battery/machine. QuecPython’s ExtInt — code written for GPIO that doesn’t need to be modified when porting modules.
  • The GPIO multiplexing table (GPIOn ↔ the default functional physical pin) ↔ differs between the two models — the EG800K’s Hardware Design/Pinout documentation or the corresponding EG800AK should be looked up, not crossed.
  • EG800AK has support for an sms module, while the EG800K (standard version) does not—if your project needs to control the GPIO remotely via SMS, you should choose EG800AK.
  • Some GPIOs may be occupied by default for other functions (NET_STATUS LED, UART debug, etc.) depending on the hardware configuration of the board — it is recommended to test with get_dir()/read() or actual measurements before assigning a new function.

Note: After checking the IO pins

GPIO Pins 1 – 4: Works well on both EG800K and EG800AK.

GPIO Pins 5 – 6: The EG800K is not available due to internal multiplex hardware for GPS/GNSS blocks. EG800AK can be used normally.

GPIO Pins 7 – 12: Not available on both versions

5. Common mistakes

PhenomenonCommon causesHow to handle
Battery() gives an initialization errorGPIOn number does not exist/is not supported on the current modelReconcile the GPIO multiplexing table of the correct module
write() does not workThe pin is being used by the firmware/board for another function (mux)Check the Default Function of the Pins in Hardware Design
ExtInt Callback Not TriggeringForgot to call enable(), or pull mode doesn’t match the external circuitCall enable() after creating an object; Actual Tensile Resistance Test
Read interference, hang up calls continuouslyUnfiltered signal interference (bounce)Transmit filter_time (multiples of 10ms) when initializing ExtInt

6. References

  • QuecPython API Reference — machine. Battery, machine. ExtInt (developer.quectel.com/python.quectel.com)
  • Hardware Design & GPIO multiplexing table for EG800K and EG800AK (Quectel documentation)