admin管理员组

文章数量:1123407

I'm trying to communicate with my Arduino nano via Python, but it doesn't work. The Python code works just fine with my other Arduino. The nano works just fine with serial communication via the Arduino IDE. I'm a little clueless as all the elements seem to work for them self. Arduino Code:

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

}

void loop() {
  if (Serial.available()>0) {
    int i = Serial.read();
    digitalWrite(LED_BUILTIN,HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN,LOW);
  }
}

Python:

import serial
import time


arduino2 = serial.Serial(port='COM12', baudrate=9600, timeout=.1)
time.sleep(1)
arduino2.write(str.encode("u"))

Edit: I Know there is some communication between Python and the nano as it blinks (really short, not the 1 second) both when arduino2 gets initialized and when "u" is written to it.

本文标签: serial portWhy can39t Python communicate with the Arduino nano and Arduino IDE canStack Overflow