📜  Arduino - 使用 python 代码示例通过串行通信发送命令

📅  最后修改于: 2022-03-11 14:46:02.375000             🧑  作者: Mango

代码示例1
# Importing Libraries
import serial
import time
arduino = serial.Serial(port='COM4', baudrate=115200, timeout=.1)
def write_read(x):
    arduino.write(bytes(x, 'utf-8'))
    time.sleep(0.05)
    data = arduino.readline()
    return data
while True:
    num = input("Enter a number: ") # Taking input from user
    value = write_read(num)
    print(value) # printing the value