메뉴 건너뛰기

목록
2022.12.08 18:22

짭두이노라 실수했음

profile
조회 수 89 댓글 1 예스잼 0 노잼 0

No Attached Image

import time
import serial
import serial.tools.list_ports
import threading
 
def send_buzzer(freq):
    sendData = f"BUZZER={freq}\n"
    my_serial.write( sendData.encode() )
def serial_read_thread():
    while True:
        read_data = my_serial.readline()
        print(read_data.decode())
 
def main():
        try:
            while True:
                    send_buzzer(261)
                    send_buzzer(293)
                    send_buzzer(329)
                    send_buzzer(349)
                   
        except KeyboardInterrupt:
            send_buzzer(0)


 
if __name__ == '__main__':
   
 
    ports = list(serial.tools.list_ports.comports())
    for p in ports:
        if 'USB-SERIAL CH340' in p.description:
            print(f"{p} 포트에 연결하였습니다.")
            my_serial = serial.Serial(p.device, baudrate=9600, timeout=1.0)
            time.sleep(2.0)
 
    t1 = threading.Thread(target=serial_read_thread)
    t1.daemon = True
    t1.start()
 
    main()
 
    my_serial.close()
           
  • profile
    그리드 2022.12.08 18:23
    포트연결시 설정코드를 바꿔줘야함 ...