For all this, I am using Windows 7, Python 2.7.3 and Pyserial 2.6. I am using COM6 for my Arduino.
I am trying to send data from a Python program, to the Arduino to read, and it keeps returning a "SerialException error.
Here is the Python code:
import serial
import time
ser = serial.Serial('COM6', 9600, timeout=0)
var = raw_input("Enter something: ")
ser.write(var)
while 1:
try:
print ser.readline()
time.sleep(1)
except ser.SerialTimeoutException:
print('Data could not be read')
Here is the Arduino code:
int incomingByte = 0;
void setup(){
// Open serial connection.
Serial.begin(9600);
}
void loop(){
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I got: "); // ASCII printable characters
Serial.println(incomingByte, DEC);
}
}
Here is the error I am getting in Python when I run the script:
Traceback (most recent call last):
File "C:/Users/admin/Desktop/test", line 3, in <module>
ser = serial.Serial('COM6', 9600, timeout=0)
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 34, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\serial\serialutil.py", line 261, in __init__
self.open()
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError()))
SerialException: could not open port COM6: [Error 5] Access is denied.
How can I resolve that error? Python will read from the Arduino just fine, but not write to it.