cvzone WARNING:root:Serial Device Not Connected

1k Views Asked by At

I'm trying to use the cvzone module to connect my python file to arduino but i cant seem to connect to my port "COM3" even though i made sure that it's turned on (arduino shows Port: "COM3")

from cvzone.SerialModule import SerialObject 
import time

arduino = SerialObject("COM3") #input arduino port number

while True:
    arduino.sendData([1]) #Send signals [1] means "turn on"
    time.sleep(1)
    arduino.sendData([0])
    time.sleep(1)

When I run the program, nothing happens and it shows:

WARNING:root:Serial Device Not Connected

2

There are 2 best solutions below

0
On

I was facing the same issue but when I put my COM port number it working fine. Here is my code:

import cv2
from cvzone.FaceDetectionModule import FaceDetector
from cvzone.SerialModule import SerialObject

cap = cv2.VideoCapture(0)
detector = FaceDetector()
arduino = SerialObject("COM5")
while True:
    success , img = cap.read()
    img,bboxs = detector.findFaces(img)

    if bboxs:
        arduino.sendData([1])
    else:
        arduino.sendData([0])

    cv2.imshow("Image",img)
    if cv2.waitKey(10) == ord("q"):
        break
0
On

Try closing the Serial monitor in Arduino or any other place if it is being used. This would solve the issue.

This happens because the Serial port is pre-occupied. I had this same issue and was apparently using the same com in Arduino Serial monitor.