# https://wokwi.com/projects/414259207241315329
import os
from machine import Pin
from machine import UART
class Board:
class BoardType:
PICO_2W = 'Raspberry Pi Pico 2 W'
PICO2 = 'Raspberry Pi Pico 2'
PICO_W = 'Raspberry Pi Pico W'
PICO = 'Raspberry Pi Pico'
RP2040 = 'RP2040'
ESP8266 = 'ESP8266'
ESP32 = 'ESP32'
UNKNOWN = 'Unknown'
def __init__(self):
self.type = self.detect_board_type()
def detect_board_type(self):
sysname = os.uname().sysname.lower()
machine = os.uname().machine.lower()
# print(sysname +'.'+ machine)
# Detect Raspberry Pi Pico W and Pico
if sysname == 'rp2' and 'pico 2 w' in machine:
return self.BoardType.PICO_2W
elif sysname == 'rp2' and 'pico 2' in machine:
return self.BoardType.PICO2
elif sysname == 'rp2' and 'pico w' in machine:
return self.BoardType.PICO_W
elif sysname == 'rp2' and 'pico' in machine:
return self.BoardType.PICO
elif sysname == 'rp2' and 'rp2040' in machine:
return self.BoardType.RP2040
# Detect ESP8266
elif sysname == 'esp8266':
return self.BoardType.ESP8266
# Detect ESP32
elif sysname == 'esp32' and 'esp32' in machine:
return self.BoardType.ESP32
# A stranger
else:
return self.BoardType.UNKNOWN
# wifi credentials (if needed)
wifi_ssid = ("Wokwi-GUEST")
wifi_password = ("")
if __name__ == "__main__":
# Detect license plate type
BOARD_TYPE = Board().type
print("Plate type: " + BOARD_TYPE)
# Pin configuration according to the detected card
if BOARD_TYPE == Board.BoardType.PICO_W or BOARD_TYPE == Board.BoardType.PICO_2W:
led = Pin("LED", Pin.OUT) # Internal LED for Raspberry Pi Pico W
elif BOARD_TYPE == Board.BoardType.PICO or BOARD_TYPE == Board.BoardType.RP2040:
led = Pin(25, Pin.OUT) # Internal LED for Raspberry Pi Pico RP2040
elif BOARD_TYPE == Board.BoardType.ESP8266:
led = Pin(2, Pin.OUT) # GPIO 2 for the ESP8266 (internal LED)
elif BOARD_TYPE == Board.BoardType.ESP32:
led = Pin(2, Pin.OUT) # GPIO 2 for the ESP32 (integrated LED)
else:
print("Unknown motherboard, using GPIO 2 and ADC 0 by default.")
uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1)) # uart on uart1 with baud of 115200
# Connect to wifi, this only needs to run once, ESP will retain the CWMODE and wifi details and reconnect after power cycle, leave commented out unless this has been run once.
print (" - Setting AP Mode...")
uart.write('AT+CWMODE=1'+'\r\n')
time.sleep(2)
print (" - Connecting to WiFi...")
uart.write('AT+CWJAP="'+wifi_ssid+'","'+wifi_password+'"'+'\r\n')
time.sleep(15)
Loading
esp-01
esp-01