I have a sketch on my Arduino sending an analog pin value to the computer through serial.println.... It is working fine. I am trying to read that value through python using the PySerial library. My python code is this:
import serial
ser = serial.Serial('COM4', 9600)
while 1:
ser.readline()
When I put the code in a line at a time through the python shell it works but if I try to run it from a saved file (F5) it gives me this error:
Traceback (most recent call last):
File "C:\Users\Peter\Dropbox\3D printer\Python Interface.py", line 2, in
ser = serial.Serial('COM4', 9600)
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 30, in init
SerialBase.init(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\serial\serialutil.py", line 260, in init
self.open()
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 56, in open
raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError()))
SerialException: could not open port COM4: [Error 2] The system cannot find the file specified.
I am running the code on a win7 64 bit Toshiba laptop running win7 ultimate 32 bit. Python verision 2.7.2
Thanks in advance,
Peter