This is a auto coil maker using Arduino, I'm using PyFirmata2 to make it(I don't use C++ because C++ is kinda hard for me), then there are some error and I can't fix it:
Traceback (most recent call last):
File "c:\Users\user\Desktop\Knob\py.py", line 9, in <module>
board = Arduino('COM4')
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\pyfirmata2\__init__.py", line 13, in __init__
super(Arduino, self).__init__(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\pyfirmata2\pyfirmata2.py", line 119, in __init__
self.sp = serial.Serial(port, baudrate, timeout=timeout)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\serial\serialwin32.py", line 33, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\serial\serialutil.py", line 244, in __init__
self.open()
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM4': PermissionError(13, '存取被拒。', None, 5)
(sorry if you notice I'm using Chinese)
I tried reboot my PC, run as Administrator and NT AUTHORITY\SYSTEM, also I run the code on other computer, still same error.Heres my code below:
from pyfirmata2 import Arduino
import multiprocessing
import time
tmp = None
tmp2 = None
tmp3 = None
i = 0
port = 'COM4'
board = Arduino('COM4')
mycircle = float(input('How many circle you want?'))
carg = float(input('Coil arg?'))
rpm = float(input('Motor rpm?'))
print('start!')
def a0():
board.digital[2].write(1)
board.digital[3].write(0)
board.digital[4].write(0)
board.digital[5].write(0)
def a1():
board.digital[2].write(0)
board.digital[3].write(1)
board.digital[4].write(0)
board.digital[5].write(0)
def b0():
board.digital[2].write(0)
board.digital[3].write(0)
board.digital[4].write(1)
board.digital[5].write(0)
def b1():
board.digital[2].write(0)
board.digital[3].write(0)
board.digital[4].write(0)
board.digital[5].write(1)
def motor():
global i
print('start21')
while True:
for e in range(0,round(30/carg)):
a0()
time.sleep(tmp3)
a1()
time.sleep(tmp3)
b0()
time.sleep(tmp3)
b1()
time.sleep(tmp3)
print(i)
i = i+1
e = 0
for e in range(0,round(30/carg)):
b1()
time.sleep(tmp3)
b0()
time.sleep(tmp3)
a1()
time.sleep(tmp3)
a0()
time.sleep(tmp3)
print(i)
i = i+1
e = 0
tmp = 60/rpm
tmp2 = 40*carg
tmp3 = tmp/tmp2
print(tmp3)
p=multiprocessing.Process(target=motor)
p.start()
board.digital[10].write(1)
while True:
if i == mycircle:
c = 1
print('complate')
p.terminate()
board.digital[10].write(0)
break
else:
pass
(I know it's kinda/very messy, because it's prototype)
System Info:Windows 10 Pro 2004 build 19041.1415, i7-8700, 8G ram, you can get other info by Here
The answer is use Linux instead Windows. Windows have a lot of problem for me. And Windows sux.