ss32
ss32

Reputation: 67

Serial communication in python causing higher CPU usage over time

I have a script that utilizes OpenCV to track an object and communicate the location to an arduino. Essentially all it's doing is passing an integer to the arduino and the arduino interprets the integer as left/middle/right and turns on the appropriate LED. It works fine for ~30 seconds after which CPU usage jumps to 95%+ and the process begins to lag like crazy. If I remove the ser.write command and print left/middle/right to terminal then it runs fine. What might be getting backed up causing the high CPU usage? I've tried different baud rates and there is a 0.01 second delay after each ser.write command.

Upvotes: 0

Views: 342

Answers (1)

ss32
ss32

Reputation: 67

It was a buffer issue on the Arduino side. There was a line that kept printing a blank character out for every character it read in, causing the buffer to overflow. I removed that line and it's working fine now.

Upvotes: 1

Related Questions