Closed oskarsjogren closed 1 year ago
What is likely happening is that SimpleHX711
is hogging the CPU and not giving the stepper motor a chance to "catch up". Try using AdvancedHX711
instead and running the script with elevated permissions (ie. sudo
). More details here .
Thank you endail.
I took your advice and checked CPU usage during the execution of the script. It actually seems like it's my stepper that is consuming the most clock power, completely saturating one CPU.
I will review my code.
Hi.
I'm trying to run a stepper motor and a load cell simultaneously from my Raspberry Pi 3B+.
I have a HX711 running at 80Hz, and by itself it is working perfectly using the code from endail! Thank you! The HX711 is hooked up to: GND on HX711 --> GND on Raspberry DT on HX711 --> GPIO 5 on Raspberry SCK on HX711 --> GPIO 6 on Raspberry VCC on HX711 --> 5V on Raspberry
For the loadcell I am using channel A. I have created an instance hx = SimpleHX711(5,6,4,1918), with 4 and 1918 coming from the calibration script.
I also have a A4988 stepper driver connected into GPIO 20 (Direction pin) and GPIO 21 (Step pin). I have also tried to run it using RPiMotorLib, but that gives exactly the same issue.
As I want to be able to run the motor independently of the load readings, I have launched two threads, one dedicated to the load cell and another to the stepper motor.
If I start the motor first, it runs smoothly until I start the load acquisition, then it starts to jerk.
If start the weight acquisition first, the motor has a jerky motion from the moment I start it. It runs smoothly again when I stop the load acquisition.
Is the hx711 shutting down all GPIO outputs when doing the reading? Or am I missing some obvious point here?
Maybe this is not an issue at all, and I would need separate controllers for each of the features. I cannot get my head around it.
I am grateful for any help on this.