Arduino Python Serial

Hi,

I see your post in Arduino Forum.

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) s=ser.read(100) #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?

Thanks

does the python script release the com port ? ==> you might need an explicit ser.close()

be aware that ser.read(100) read 100 bytes and that the Arduino sends 1-4 chars followed by \r\n per value. So the variable s need to be processed to get the values back.