在Arduino显示器上打印Python输出

2024-09-27 00:13:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我完全迷路了。我想用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上(只是有一点侧面的“嗨!”但这不是问题)。在


Tags: thetonumberlcdincludelibrarypinserial

热门问题