Mar-21-2017, 11:26 PM
Hello,
I am trying to write a base program that will connect to an Arduino, Via Serial, and will send and receive data.
For some reason though, I can't seem to get Python to connect with the Arduino Uno.
Here is the code I have, and the error that I get.
If anyone knows a possible solution, any help would be great!
I am trying to write a base program that will connect to an Arduino, Via Serial, and will send and receive data.
For some reason though, I can't seem to get Python to connect with the Arduino Uno.
Here is the code I have, and the error that I get.
If anyone knows a possible solution, any help would be great!
import serial connected = False ser = serial.Serial("COM3", 19200) while not connected: serin = ser.read() connected = True myStr = "1" asBytes = str.encode(myStr) ser.write(asBytes) while ser.read() =='1': ser.read() ser.close
Error:runfile('C:/Users/Christopher Martone/Desktop/pythonArduino.py', wdir='C:/Users/Christopher Martone/Desktop')
Traceback (most recent call last):
File "<ipython-input-3-f2cfc99aed65>", line 1, in <module>
runfile('C:/Users/Christopher Martone/Desktop/pythonArduino.py', wdir='C:/Users/Christopher Martone/Desktop')
File "D:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "D:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Christopher Martone/Desktop/pythonArduino.py", line 12, in <module>
ser = serial.Serial("COM3", 19200)
File "D:\Anaconda\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialwin32.py", line 31, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "D:\Anaconda\lib\site-packages\pyserial-3.3-py3.6.egg\serial\serialutil.py", line 240, in __init__
self.open()
File "D:\Anaconda\lib\site-packages\pyserial-3.3-py3.6.egg\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 'COM3': PermissionError(13, 'Access is denied.', None, 5)