Command Prompt Gets Stuck Upon Running PyFirmata Function

63 Views Asked by At

I'm trying to run some Python to control a servo on my Arduino. About a week ago, I got it all working, and there were no issues. Now, when I run the same code (code below) my computer gets stuck in the rotate function. Im using the module PyFirmata2, though I have tried it with PyFirmata. Im using a really old version of Python (3.9.9) because PyFirmata leaves something to be desired.

This is the python, it's saved in a note (MCT3.py) which is then run. I have verified all the ports and pins are correct.

from pyfirmata2 import Arduino ,SERVO,util
from time import sleep

port = 'COM4'
pin = 10
board = Arduino(port)

board.digital[pin].mode = SERVO

def rotate(pin, angle):
    board.digital[pin].write(angle)
    sleep(1000)

print('START')
x = str(input('Angle: '))
rotate(pin, x)
print('DONE')

This is my steps and the output:

C:\Users\bguyl>python MCT3.py
START
Angle: 90

I can let it sit as long as it wants and it won't print "DONE". It does, however, rotate the servo to the correct angle, it just won't continue the code afterward.

This is a problem because I need this in a while loop eventually and if it cant get past the rotate function I wont be able to enter multiple angles in a row.

This might be a really easy fix, but I don't use windows that much :)

Python Version:            Python 3.9.9
OS Name:                   Microsoft Windows 10 Home
OS Version:                10.0.19045 N/A Build 19045
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          ----------------
Registered Organization:
Product ID:                ----------------
Original Install Date:     1/10/2023, 4:29:04 AM
System Boot Time:          7/14/2023, 3:18:42 PM
System Manufacturer:       Dell Inc.
System Model:              OptiPlex 9020
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 60 Stepping 3 GenuineIntel ~3201 Mhz
BIOS Version:              Dell Inc. A25, 5/30/2019
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC-06:00) Central Time (US & Canada)
Total Physical Memory:     16,324 MB
Available Physical Memory: 8,361 MB
Virtual Memory: Max Size:  23,178 MB
Virtual Memory: Available: 11,224 MB
Virtual Memory: In Use:    11,954 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              ----------------
Hotfix(s):                 13 Hotfix(s) Installed.
0

There are 0 best solutions below