'python: GPIO / RpiMotorLib in virtual environment with Django - stepper motor is rotating jerky
I´m trying to run a stepper motor (NEMA17) with a DRV8225 stepper motor controller inside a python/Djano app in a virtual environment.
The script for running the stepper motor with the RPiMotorLib is the script in this tutorial: https://makersportal.com/blog/raspberry-pi-stepper-motor-control-with-nema-17
When I run the script from command line inside/outside the virtual environment, the motor is rotating smooth.
But if I run the script in my Django app, the motor is rotating jerky. In Django, I´m firing the script with a Django signal after updating the database:
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.utils.crypto import get_random_string
from django.utils.text import slugify
from steppermotors.models import Steppermotor
import RPi.GPIO as GPIO
from RpiMotorLib import RpiMotorLib
import time
@receiver(pre_save, sender=Steppermotor)
def run_steppermotor(sender, instance, *args, **kwargs):
direction= 22 # Direction (DIR) GPIO Pin
step = 23 # Step GPIO Pin
EN_pin = 24 # enable pin (LOW to enable)
# Declare a instance of class pass GPIO pins numbers and the motor type
mymotortest = RpiMotorLib.A4988Nema(direction, step, (21,21,21), "DRV8825")
GPIO.setup(EN_pin,GPIO.OUT) # set enable pin as output
GPIO.output(EN_pin,GPIO.LOW) # pull enable to low to enable motor
mymotortest.motor_go(False, # True=Clockwise, False=Counter-Clockwise
"Full" , # Step type (Full,Half,1/4,1/8,1/16,1/32)
instance.last_steps, # number of steps
.0005, # step delay [sec]
True, # True = print verbose output
.05) # initial delay [sec]
GPIO.cleanup() # clear GPIO allocations after run
Are there any ideas why the motor is jerky?
Thanks in advance
My requiremts.txt:
asgiref==3.5.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.11
confusable-homoglyphs==3.2.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==36.0.1
defusedxml==0.7.1
Django==3.1.14
django-registration==3.2
django-templated-mail==1.1.1
django-widget-tweaks==1.4.12
djangorestframework==3.12.4
djangorestframework-simplejwt==4.8.0
djoser==2.1.0
html5lib==1.1
idna==3.3
itypes==1.2.0
Jinja2==3.0.3
MarkupSafe==2.0.1
oauthlib==3.2.0
pycparser==2.21
PyJWT==2.3.0
python3-openid==3.2.0
pytz==2021.3
requests==2.27.1
requests-oauthlib==1.3.1
RPi.GPIO==0.7.1
rpimotorlib==3.1
six==1.16.0
social-auth-app-django==4.0.0
social-auth-core==4.2.0
sqlparse==0.4.2
uritemplate==4.1.1
urllib3==1.26.8
webencodings==0.5.1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
