我在 pico pi W 上用 micropython 编写了一段简短的代码。该代码设置了一个服务器,主要是为了显示一个网站,您可以在该网站上检查所有 GPIO 引脚的状态。 现在,当我遍历从 0 到 28 的每个引脚时,我会得到所有值,但如果我尝试发送引脚 23 和 25 的值,我会得到 OSError -1。
错误消息(如果我不跳过23和25):
Traceback (most recent call last):
File "<stdin>", line 134, in <module>
OSError: -1
获取引脚状态:
gpio_html = ""
for pin_number in range(0, 29):# Adjust based on your setup
if pin_number in (23,25): # I use this to not get error
continue
pin = Pin(pin_number, Pin.IN) # Set GPIO as input
state = pin.value() # Read GPIO state
gpio_html += f"""
{space}<tr>
{space}<td>{pin_number}</td>
{space}<td>{state}</td>
{space}</tr>"""
发送回复:
# Generate HTML response
response = webpage(random_value, state)
# Send the HTTP response and close the connection
conn.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') # line 134
conn.send(response.encode('utf-8'))
conn.close()