使用 Raspberry Pi Pico、Waveshare NB-IoT SIM7020E 模块和 Twilio Super SIM 卡,我使用插头引脚将 Raspberry Pi Pico 安装到 SIM7020E 模块中:
要发送 AT 命令来配置调制解调器并设置 APN,我使用 MicroPython 并在执行 CTRL + C、CTRL + E 和 CTRL + D 后将 Python 代码复制粘贴到 Putty 中运行代码。发送 AT 命令的函数有
uart.write
、uart.any
和 uart.read
:
#Send an AT command - just return the response
def send_at_get_resp(cmd, timeout=1000):
# Send the AT command
uart.write((cmd + "\r\n").encode())
# Read and return the response (until timeout)
return read_buffer(timeout)
#Read in the buffer by sampling the UART until timeout
def read_buffer(timeout):
buffer = bytes()
now = ticks_ms()
while (ticks_ms() - now) < timeout and len(buffer) < 1025:
if uart.any(): # check if there is anything to be read
buffer += uart.read(1) # read 1 characters, returns a bytes object
return buffer.decode()
#Send an AT command - return True if we got an expected otherwise False
def send_at(cmd, back="OK", timeout=1000):
# Send the command and get the response (until timeout)
buffer = send_at_get_resp(cmd, timeout)
if len(buffer) > 0:
return True
else:
return False
send_at("AT")
send_at("ATE1")
uart.read
读取到‘b\x00’,而不是AT指令。 SIM7020E 模块没有响应(我应该收到响应“OK”)。Read_buffer
(图2)通过采样UART来读取缓冲区中的命令,返回一个空字符串。在发送 AT 命令之前,我使用 SIM7020E 模块的引脚 (14) 打开和关闭模块以启动调制解调器。通电后,模块的 LED 会亮起,以便 Python 代码可以进行通信,并且仅 AT 命令会出现此问题。在 Putty 中输入 AT 命令“AT”和“ATE1”(我没有按 CTRL + C 来中断到 Python REPL)收到错误消息:
Simcom模块AT命令测试仪识别到端口但无法连接。它建议其他波特率并启用流量控制,但这不起作用。流量控制不知道怎么配置。
如何让模块响应AT指令?
您在 Putty 中使用的串行接口似乎不正确。当您直接在 Putty 中发送 AT 命令时,COM5 端口是什么?它应该是设备管理器中调制解调器下显示的 COM 端口。