0

I have a short code written in micropython on pico pi W. This codes sets up a server and is mainly supposed to display a website on which you can check the states of all the GPIO pins. Now when I go through each Pin from 0 to 28 I get all the values but if I try to send the values of pins 23 and 25 I get OSError -1.

Error message(if I dont skip 23 and 25):

Traceback (most recent call last):
 File "<stdin>", line 134, in <module>
OSError: -1

Getting states of pins:

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>"""

Sending response:

        # 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()

1 Answer 1

0

I was looking through the pi pico W diagram again and realized that that pins 23 24 25 are not actual pins. Maybe that is way the code did not work. Not sure but I will stick with this explanation for my self.

You can see the functions of the three pins in the table below the diagram:

Pi Pico W pinout diagram

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah. Your code sets every pin to an input when it reads it, and you even documented that it's doing that. So it makes total sense that it would mess up the wireless communication. Instead, you should just use mem32 to read directly from the GPIO input register, which gives you the digital values of all the pins without tampering with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.