<p>我是新来的,我想做一个游戏。我用Python把串行数据发送到Arduino。我想让Arduino等待,直到它从Python接收到串行数据。你知道吗</p>
<p>我的问题是:</p>
<ul>
<li>为什么Arduino程序不能处理来自Python的串行数据,但可以处理来自串行监视器的数据?你知道吗</li>
<li>如何使程序使用Python中的数据?(等待Python中的串行数据,然后保存数据。)</li>
</ul>
<p>Arduino代码:</p>
<pre><code>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);
}
</code></pre>
<p>Python代码:</p>
<pre><code>import serial
ser=serial.Serial('COM4',9600)
ser.write(b'1235')
ser.close()
</code></pre>
<blockquote>
<p>Solved the problem that I don't get the serial data, but a new problem occured:</p>
<p>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(){}. </p>
</blockquote>