Python serial communication

前端 未结 2 1180
走了就别回头了
走了就别回头了 2021-02-15 02:13

I\'m working on an Arduino project, and I am interfacing it with a Python script due to memory limitations. On the Python side I have a 2 dimensional matrix containing respectiv

2条回答
  •  天涯浪人
    2021-02-15 02:57

    You should wait a bit for the serial data to arrive.

    The Arduino code should be:

    if (Serial.available()){
        delay(100); // Wait for all data.
        while (Serial.available()) {
            char d = Serial.read();
            str.concat(d);
        }
    }
    

    Also you have to clear your string before re-using it.

    [Edit]

    I forgot to mention ÿ == -1 == 255 which means Serial.read() it is saying it can't read anything.

提交回复
热议问题