Access is denied to python from using COM3 (I want to send data to my arduino )

djsfantasi

Joined Apr 11, 2010
9,160
Once you close the IDE, you may have to a) reset the Arduino or b) remove and replace the USB cable between the PC and Arduino.

Just out of curiosity, how are you powering the UNO?
 

Thread Starter

filipmr

Joined Jan 2, 2021
64
Once you close the IDE, you may have to a) reset the Arduino or b) remove and replace the USB cable between the PC and Arduino.

Just out of curiosity, how are you powering the UNO?
With the usb cable, but on some other projects I use a 9V b
attery
 

Thread Starter

filipmr

Joined Jan 2, 2021
64
Have you tried my suggestions?

The Windows USB driver for the Arduino has its issues. Sometimes you need to reload it. Option b will do that. Option a might reset it.
I tried it, but nothing is working, I also tried connected a smaller program to Arduino, that just sends a number, and if i first start python i don't get the error, but than nothing is showing up on Arduino(I also can't use Serial monitor than), so I tried to display the number on a LCD display, but nothing was showing up.
 

djsfantasi

Joined Apr 11, 2010
9,160
I tried it, but nothing is working, I also tried connected a smaller program to Arduino, that just sends a number, and if i first start python i don't get the error, but than nothing is showing up on Arduino(I also can't use Serial monitor than), so I tried to display the number on a LCD display, but nothing was showing up.
Now you’ve introduced another issue... you’ll never figure this out this way...

I’ve been following MrChips’ advice in my replies to you. Trying to address his first point.

Write simple test programs. Send an “A” from Python to the Arduino and illuminate the built-in Arduino led when it’s received. No worries if your LCD is working. Simple programs that are likely to work.

Otherwise, proceed as MrChips suggests.
 

Thread Starter

filipmr

Joined Jan 2, 2021
64
Now you’ve introduced another issue... you’ll never figure this out this way...

I’ve been following MrChips’ advice in my replies to you. Trying to address his first point.

Write simple test programs. Send an “A” from Python to the Arduino and illuminate the built-in Arduino led when it’s received. No worries if your LCD is working. Simple programs that are likely to work.

Otherwise, proceed as MrChips suggests.
Ok , I will try, thanks
 
Put the line serialPort = serial.Serial ( port="COM3", baudrate=9600,bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE ) outside the for loop. This program is trying to open a serial port even though it is already open every time it is in the loop.

It's connected with a normal USB to B cable,that you get when u buy an arduino uno. My python code is :
Python:
import cv2
import serial
import time
cap=cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')


while True:
    _,img = cap.read ()
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.1, 4)
    for (x,y,w,h) in faces:

        cv2.rectangle( img, (x, y),(x+w,y+h),(0, 0, 255), 2 )
        serialPort = serial.Serial ( port="COM3", baudrate=9600,bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE )
        cv2.imshow ( 'img', img )
        r1=str(round ( x + w / 2 ))
        r2=str(round ( y + h / 2 ))

        data="X:"+r1+"Y:"+r2
        serialPort.write ( bytes(data, encoding='utf8' ))

    k = cv2.waitKey ( 30 ) & 0xff
    if k == 27:
        break
cap.release()
and this is my arduino code:
C:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
String data;
void setup() {
while(1){
  Serial.begin(9600);

  data=Serial.read();
  lcd.begin(16,2);
  lcd.print(data);
  delay(1000);

}

}

void loop() {
}
 
Top