Efficient and fast Python While loop while using sleep()

前端 未结 3 1018
日久生厌
日久生厌 2021-01-31 17:16

I am attempting to communicate with a device over serial using Pyserial. As commands need to be continually sent, they have to be placed in a while loop in Python.

I am

3条回答
  •  耶瑟儿~
    2021-01-31 17:45

    In regards to your comment on Joachim's answer:

    Then your microcontroller code needs a redesign. Otherwise you're just turning you general-purpose computer into nothing more than a dumb "microcontroller" that iterates over unneeded code repeatedly, hence the 100% cpu. Another symptom of you using your computer incorrectly is the fact that your hardware motor's speed depends on the speed at which you send commands to it via the serial interface. You need to "command" it with the computer which will host your high-level logic. And your micro-controller needs to handle the low-level, repetative control of the motor.

提交回复
热议问题