qertko.blogg.se

Thonny pi pico
Thonny pi pico





thonny pi pico

from machine import Pin, ADC import network import random import socket import time import constants # Just making our internet connection wlan = network.WLAN(network.STA_IF) wlan.active(True) nnect(constants.INTERNET_NAME, constants.INTERNET_PASSWORD) # Wait for connect or fail max_wait = 10 while max_wait > 0: if wlan.status() = 3: break max_wait -= 1 print('waiting for connection.') time.sleep(1) # Handle connection error if wlan.status() != 3: raise RuntimeError('network connection failed') else: print('connected') status = wlan.ifconfig() #print('ip = ' + status) # Open socket addr = socket.getaddrinfo('0.0.0.0', 80) s = socket.socket() s.bind(addr) s.listen(1) print('listening on', addr) # Listen for connections while True: try: cl, addr = s.accept() request = cl.recv(1024) print(request) # No need to unpack request in this example ran_num = str(random.randint(0, 100)) cl.send(ran_num) print("Sent: " + ran_num) cl.close() except OSError as e: cl.close() print('connection closed') In one instance run the following server code, you can select either Pico W to do this. If you have the devices connected to your computer you should be able to connect both in the separate screens. You can open cmd and do something similar or you can double-tap the application to open another instance.Īfterward, you can select the corresponding device in the corresponding Thonny instances.

#Thonny pi pico windows

If you are using Windows or Linux, the process is a little different. To open another instance on a Mac, go to the Terminal and run the following code: /Applications/Thonny.app/Contents/MacOS/thonnyĪfter running this you should see another Thonny instance pop up.

thonny pi pico thonny pi pico

Restart Thonny to activate this behavior.







Thonny pi pico