Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial Python and Arduino
#1
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!


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)
Reply


Messages In This Thread
Serial Python and Arduino - by delfar - Mar-21-2017, 11:26 PM
RE: Serial Python and Arduino - by wavic - Mar-22-2017, 12:07 AM
RE: Serial Python and Arduino - by j.crater - Mar-22-2017, 06:12 AM
RE: Serial Python and Arduino - by Larz60+ - Mar-22-2017, 12:58 PM
RE: Serial Python and Arduino - by delfar - Mar-22-2017, 07:41 PM
RE: Serial Python and Arduino - by Larz60+ - Mar-22-2017, 07:50 PM
RE: Serial Python and Arduino - by delfar - Mar-22-2017, 10:24 PM
RE: Serial Python and Arduino - by Larz60+ - Mar-23-2017, 02:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,389 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Python error on mentioned Arduino port name dghosal 5 881 Aug-22-2023, 04:54 PM
Last Post: deanhystad
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 850 Mar-21-2023, 10:06 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 4,169 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,748 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  python serial port barryjo 2 1,688 Dec-27-2021, 11:09 PM
Last Post: barryjo
  serial connection to Arduino Jack9 4 2,505 Oct-22-2021, 10:18 AM
Last Post: Jack9
  Serial loopback with Arduino doesn't work ThomasS 3 2,807 Sep-19-2020, 12:47 PM
Last Post: deanhystad
  Can't transmit serial fast Python to Arduino pyserial mRKlean 0 2,388 Mar-29-2020, 08:12 PM
Last Post: mRKlean
  About Arduino and Python usb webcam tuts Simurg 1 2,187 Mar-20-2020, 07:25 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020