Arduino Python Serial


I want to get data from serial port, so I used this code to arduino:

int potPin = 0;

void setup() { Serial.begin(9600); }

void loop() { int val = map(analogRead(potPin), 0, 1023, 0, 255); Serial.println(val); delay(1000); }

And this code to python:

import serial ser=serial.Serial(port='COM3',timeout=3) #reading up to 100 bytes print s

When I connect the arduino to the serial port, python show 4 values from the serial port. But, if a run the code in python again, occurs this error:

raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError())) serial.serialutil.SerialException: could not open port COM3: [Error 5] Access denied.

Can you help me?


Can you help me?

Don't you think that closing the port is a good idea?