# GPIO Instructions

> Source: https://maker.tdlogy.com/wiki-doc/gpio-instructions/

EG800K &amp; 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)

ParameterTypeMeaningGPIOnintThe 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

MethodDescriptionread()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 Pinimport utimeled = Pin(Pin.GPIO1, Pin.OUT, Pin.PULL_DISABLE, 0)while True:&nbsp;&nbsp;&nbsp; led.write(1)&nbsp;&nbsp;&nbsp; utime.sleep(1)&nbsp;&nbsp;&nbsp; led.write(0)&nbsp;&nbsp;&nbsp; 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 ExtIntdef 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()

ParameterMeaningGPIOnGPIO 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

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 handleBattery() gives an initialization errorGPIOn number does not exist/is not supported on the current modelReconcile the GPIO multiplexing table of the correct modulewrite() does not workThe pin is being used by the firmware/board for another function (mux)Check the Default Function of the Pins in Hardware DesignExtInt Callback Not TriggeringForgot to call enable(), or pull mode doesn't match the external circuitCall enable() after creating an object; Actual Tensile Resistance TestRead interference, hang up calls continuouslyUnfiltered signal interference (bounce)Transmit filter_time (multiples of 10ms) when initializing ExtInt

# 6. References