标签:pytho highlight waiting code ready ber open NPU nio
树莓派查询串口
ls /dev/tty*
通过 拔插发现多了一个
就是他了。
arudnio代码
void setup() { Serial.begin(9600); //打开串口 } void loop() { Serial.println("Hello Raspberry,I am Arduino."); delay(1000); if ( Serial.available()) { if(‘s‘ == Serial.read()) Serial.println("Hello Raspberry,I am Arduino."); } }
# -*- coding: utf-8 -* import serial import time ser = serial.Serial(‘/dev/ttyUSB0‘, 9600) if ser.isOpen == False: ser.open() # 打开串口 ser.write(b"Raspberry pi is ready") try: while True: size = ser.inWaiting() # 获得缓冲区字符 if size != 0: response = ser.read(size) # 读取内容并显示 print(response) ser.flushInput() # 清空接收缓存区 time.sleep(0.1) # 软件延时 except KeyboardInterrupt: ser.close()
标签:pytho highlight waiting code ready ber open NPU nio
原文地址:https://www.cnblogs.com/kekeoutlook/p/11621280.html