我是新来的,我想做一个游戏。我用Python把串行数据发送到Arduino。我想让Arduino等待,直到它从Python接收到串行数据。你知道吗
我的问题是:
Arduino代码:
int select;
void setup() {
Serial.begin(9600);
Serial.flush();
while(!Serial.available()){
}
if(Serial.available()>0){
select=Serial.read();
}
}
void loop() {
Serial.println(select);
delay(500);
}
Python代码:
import serial
ser=serial.Serial('COM4',9600)
ser.write(b'1235')
ser.close()
Solved the problem that I don't get the serial data, but a new problem occured:
The problem is that, if I get the serial data, my Arduino program jumps back to the while(!Serial.available()){} loop, and not goes to the void loop(){}.
就像Juraj所说的重置Arduino,你应该添加代码等待它恢复
使用
ser=serial.Serial('COM4',9600)
的新USB连接重置Arduino。由于Arduino启动,连接后立即发送的数据丢失。你知道吗相关问题 更多 >
编程相关推荐