Arduino Serial Communication. TX lags RX.
i using opencv , python video processing. code detects binary thresholded object in camera frame. if particular colored object in front of cam, python sends char '"1" using pyserial. while loop used go through each frame of video, rx active of time on arduino. if receive char "1", want set servo 90 degrees else every time want set servo 0 degrees.
python code -
arduino code -
the rx receives byte on time loop stucks while transmitting. how can optimize code solve issue? tried serial.flush() function waits transmission complete of no help.
thanks in advance.
python code -
code: [select]
import opencv
import serial
ser = serial.serial("/dev/ttyacm0", 115200)
cap = cv2.videocapture(0)
while(cap.issopened()):
ret, img = cap.read()
#thresolding code
if(object_detected):
serial.write("1")
arduino code -
code: [select]
#include <servo.h>
int incomingbyte = 0;
servo myservo;
void setup() {
serial.begin(115200);
myservo.attach(9);
}
void loop() {
if (serial.available() > 0) {
incomingbyte = serial.read();
if(incomingbyte == 49){
myservo.write(90);
}
else{
myservo.write(0);
}
}
}
the rx receives byte on time loop stucks while transmitting. how can optimize code solve issue? tried serial.flush() function waits transmission complete of no help.
thanks in advance.
hint
code: [select]
if(incomingbyte == '1'){
Arduino Forum > Using Arduino > Programming Questions > Arduino Serial Communication. TX lags RX.
arduino
Comments
Post a Comment