Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6814

Troubleshooting • (Solved)PicoW: Code refused to work

$
0
0
SOLVED: THE ISSUE WAS WRONG FIRMWARE BEING INSTALLED



Hello everyone,


(context)
I just got yesterday a set of Pico MCUs. I already had the regular one, and I decided to buy the WiFi version. At the start, everything went smoothly: I followed Raspberry Pi's tutorial on how to set up the Pico. It went correctly, setting up the website and lighting up the light on and off. After that, I plugged it in to a battery, saved it as "main.py" and went try it out in my home.

Today I plugged it in to my computer again but, oh no! It did not work. I re downloaded the micropython bootloader (a few times) but nothing happens. I also tried using the reset for the "main.py" (attached) that I use for the regular Picos, but to no avail. Yes, it did press the "bootsel" button before plugging and uploading things, but nothing happens.

Problem
I would say that Thonny isn't compiling well, because when I uploaded the basic code:

Code:

import networkimport socketfrom time import sleepfrom picozero import pico_temp_sensor, pico_ledimport machinessid = 'this'password = 'that'def connect():    #Connect to WLAN    wlan = network.WLAN(network.STA_IF)    wlan.active(True)    wlan.connect(ssid, password)    while wlan.isconnected() == False:        print('Waiting for connection...')        sleep(1)    print(wlan.ifconfig())    ip = wlan.ifconfig()[0]    return ip    def open_socket(ip):    # Open a socket    address = (ip, 80)    connection = socket.socket()    connection.bind(address)    connection.listen(1)    print(connection)    return connectiondef serve(connection):    #Start a web server    state = 'OFF'    pico_led.off()    temperature = 0    while True:        client = connection.accept()[0]        request = client.recv(1024)        request = str(request)        try:            request = request.split()[1]        except IndexError:            pass        if request == '/lighton?':            pico_led.on()            state = 'ON'        elif request =='/lightoff?':            pico_led.off()            state = 'OFF'        temperature = pico_temp_sensor.temp        html = webpage(temperature, state)        client.send(html)        client.close()        def webpage(temperature, state):    #Template HTML    html = f"""            <!DOCTYPE html>            <html>            <form action="./lighton">            <input type="submit" value="Light on" />            </form>            <form action="./lightoff">            <input type="submit" value="Light off" />            </form>            <p>LED is {state}</p>            <p>Temperature is {temperature}</p>            </body>            </html>            """    return str(html)def open_socket(ip):    # Open a socket    address = (ip, 80)    connection = socket.socket()    connection.bind(address)    connection.listen(1)    return connectiontry:    ip = connect()    connection = open_socket(ip)except KeyboardInterrupt:    machine.reset()
It gave me this error output:

Code:

MPY: soft rebootTraceback (most recent call last):  File "<stdin>", line 58SyntaxError: invalid syntax
Saying that I wrote wrong the format of the html. Sometimes, I have an error code that says that none of the wifi dependencies (network and socket) do not exist.


Does anyone know how to fix this? Thank you.

(P.D. this is my first post in the forum. If I made something wrong, please tell me so I can fix it. Thanks!)
MicroPython_RenameMainDotPy.uf2.zip

Statistics: Posted by MicroAnalog — Wed Jun 05, 2024 9:13 pm — Replies 2 — Views 29



Viewing all articles
Browse latest Browse all 6814

Trending Articles