我完全迷路了。我想用Python在Arduino的显示器上打印一些东西。我知道这可以在没有Python的情况下通过使用:
lcd.write("my string");
但是我想用pySerial库来做这个。在
这是我的Python代码:
^{pr2}$这是我的Arduino密码:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
}
void loop() {
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
另外,当我用串行监视器输入文本时,它会像它应该显示的那样出现在Arduino上(只是有一点侧面的“嗨!”但这不是问题)。在
串行数据可以由Python缓冲。在
尝试:
相关问题 更多 >
编程相关推荐