Outils pour utilisateurs

Outils du site


raspberry_pi_pico:esp-01

Connexion Wifi via une carte ESP-01

Schéma de câblage :

Repérage des broches :

ESP01 PICO
Pin 8 : VCC Pin 36 : 3V3(OUT)
Pin 4 : CH_EN
Pin 1 : GND Pin 38 : GND
Pin 2 : TX Pin 7 : RX
Pin 7 : RX Pin 6 : TX

Programme de connexion Wifi

Connexion Wifi sur un point d'accès, suivi de l'affichage de l'adresse IP et de l'adresse MAC.

from machine import UART
import utime
 
uart0 = UART(1, 115200)
print(uart)		# affichage de la configuration de la liaison série
 
 
def sendCMD_waitResp(cmd, uart=uart0, timeout=2000):
    print("CMD: " + cmd)
    uart.write(cmd)
    waitResp(uart, timeout)
    print()
 
def waitResp(uart=uart0, timeout=2000):
    prvMills = utime.ticks_ms()
    resp = b""
    while (utime.ticks_ms()-prvMills)<timeout:
        if uart.any():
            resp = b"".join([resp, uart.read(1)])
    print("resp:")
    try:
        print(resp.decode())
    except UnicodeError:
        print(resp)
 
# sendCMD_waitResp('AT\r\n')    # teste la communication AT
# sendCMD_waitResp('AT+CWMODE?\r\n')    # affiche le mode wifi
# sendCMD_waitResp('AT+CWLAP\r\n', timeout=5000)    # affiche les PA disponibles
sendCMD_waitResp('AT+CWJAP="ssid","password"\r\n')  # connexion au PA
sendCMD_waitResp('AT+CIPSTATUS\r\n')    # affichage des info sur la connexion
sendCMD_waitResp('AT+CIFSR\r\n', timeout=1000)    # affiche les adresses IP et MAC
raspberry_pi_pico/esp-01.txt · Dernière modification : 2023/03/28 16:57 de dan