I want to open led on board ESP32 by GUI python

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
chatchaiCC
Posts: 1
Joined: Sat Nov 20, 2021 2:12 pm

I want to open led on board ESP32 by GUI python

Post by chatchaiCC » Sat Nov 20, 2021 2:22 pm

i have gui code
i want to click gui print("On") led on bord on
data sent usb port

:?: :?: :?:
#Python

Code: Select all

import serial
import time
 
# Define the serial port and baud rate.
ser = serial.Serial('COM14', 9600)
 
def led_on_off():
    user_input = input("\n Type on / off / quit : ")
    if user_input =="on":
        print("LED is on...")
        time.sleep(0.1) 
        ser.write(b'H') 
        led_on_off()
    elif user_input =="off":
        print("LED is off...")
        time.sleep(0.1)
        ser.write(b'L')
        led_on_off()
    elif user_input =="quit" or user_input == "q":
        print("Program Exiting")
        time.sleep(0.1)
        ser.write(b'L')
        ser.close()
    else:
        print("Invalid input. Type on / off / quit.")
        led_on_off()
 
time.sleep(2) # wait for the serial connection to initialize
 
led_on_off()
#on borad esp32

Code: Select all

import machine
import os


led = machine.Pin(2, machine.Pin,OUT)
uert = machine.UART(0, 115200)
os.dupterm(None, 1)

str = ''

whhile True:
    if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: :
        str =  sys.stdin.read()
        if 'H' in str:
            led.on()           
        elif 'L' in str:
            led.off()
          

Post Reply