Access Denied using Python and Arduino IDE but I need both open

I'm making a program that reads Arduino's Output and sends it to an SQLITE3 database.
Before making the program, I wanted to test if Python was reading Arduino's Output.
If I have the Arduino IDE open, it doesn't work. I searched and found that if it says Access Denied is because Arduino's is already being executed.

How can I solve this problem?

Python Code

import sqlite3
import serial

dbConn = sqlite3.connect("database_arduino.db")
cursor = dbConn.cursor()


print("Trying...", 'COM4')
arduino = serial.Serial('COM4', 9600)
if arduino:
    print("Connected")

data = arduino.readline()  
print(data)

dbConn.commit()  # commit the insert
cursor.close()  # close the cursor

Arduino Code

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <HX711_ADC.h>

#define SS_PIN 10
#define RST_PIN 9
#define LED_G 6
#define LED_R 4
#define BUZZER 2
///////////////////////////////Célula de Carga
HX711_ADC LoadCell(4, 5);
MFRC522 mfrc522(SS_PIN, RST_PIN);
long t;
///////////////////////////////
Servo myServo;
//--------------------------//

void setup(){
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  myServo.attach(3);
  myServo.write(0);
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  Serial.println("------------TI-TRASH------------");
  //lcd.print("----TI-Trash----")
  delay(1500);
  Serial.println("LOADING...");
  //lcd.print("LOADING...")
  delay(3500);
  Serial.println("APROXIME O SEU CARTÃO...");
  //lcd.print("APROXIMAR CARTAO")
  Serial.println();
}

void loop(){
  if( ! mfrc522.PICC_IsNewCardPresent()){
    return;
  }
  if(!mfrc522.PICC_ReadCardSerial()){
    return;
  }
  Serial.print("UID tag:");
  String content="";
  byte letter;
  for (byte i = 0; i<mfrc522.uid.size; i++){
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] <0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  //Serial.print("Message: ");
  content.toUpperCase();
  if (content.substring(1) == "92 7B BD 30"){
    Serial.println("Utilizador : Tiago Gonçalves");
    //lcd.print("Tiago Goncalves");
    Serial.println("Acesso autorizado...");
    //lcd.print("Acesso Concedido")
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(0);
    digitalWrite(LED_G, LOW);
    Serial.println("");
    //a partir desta linha, código da LoadCell
    LoadCell.begin();
    long stabilisingtime = 2000; // a precisao da tare pode ser melhorada com a adicao de alguns milisegundos
    LoadCell.start(stabilisingtime);
    LoadCell.setCalFactor(696.0); // factor de calibracao (float)
    delay(2500);
    LoadCell.update();

  //permite valores precisos a partir do data set + factor de calibracao
  if (millis() > t + 250) {
    float i = LoadCell.getData();
    Serial.println(i);
    t = millis();
  }

  //receive from serial terminal
  if (Serial.available() > 0) {
    float i;
    char inByte = Serial.read();
    if (inByte == 't') LoadCell.tareNoDelay();
  }

  }
  else if(content.substring(1) == "F3 36 4B 73"){
    Serial.println("Utilizador : Martim Sousa");
    Serial.println("Acesso autorizado...");
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(0);
    digitalWrite(LED_G, LOW);
    Serial.println("");
  }
  else{
    Serial.println("Utilizador : desconhecido");
    Serial.println("Acesso Negado...");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
  }
}

Python Errors
File "C:\Users\Tiago\Desktop\asdf.py", line 9, in
arduino = serial.Serial('COM4', 9600)

File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 31, in init
super(Serial, self).init(*args, **kwargs)

File "C:\Python27\lib\site-packages\serial\serialutil.py", line 240, in init
self.open()

File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))

SerialException: could not open port 'COM4': WindowsError(5, 'Acesso negado.')

tiagogclvs:
I searched and found that if it says Access Denied is because Arduino's is already being executed.

Wrong. That error means the serial port is already open. There should only be two reasons why the Arduino IDE has the serial port open:

  • You are uploading a sketch to your Arduino. This is done over the serial port.
  • You have the Serial Monitor open.

You cannot connect two PC programs to the same serial port.

If you want to monitor what your Arduino is sending then add some code to your Python program to print on the screen what it receives. That way you don't need the Arduino Serial Monitor.

...R