Stepper motor rotates while the load cell sensor is reading. HX711 MULTITASKING

Please help. I might miss something, need this problem to be solved badly.
For the microcontroller we use Arduino Due, for the HX711 we use this library GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales..

Objective:

  1. while stepper motor moves counter-clockwise, the load cell sensor will display its output to the serial monitor.

NOTE: I already try using scheduler but the stepper motor turns very slow.

If you have OTHER suggestion with regards with MULTITASKING then that would be a great help

Here's the code:

// HX711.DOUT  - pin #A1
// HX711.PD_SCK - pin #A0
#include <Scheduler.h>
#include "HX711.h"
#include <Stepper.h>

 //Loadcell initialization
 HX711 scale(A1, A0);  
 float temp = 0.00;
 int Value =0;
 int CompareValue = 0;
 int FinalValue = 0;

 //Stepper motor initialization
 const int stepsPerRevolution = 200;
 Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
 int stepCount = 0;
 
void setup() {
  Serial.begin(9600);
  
  myStepper.setSpeed(40);
  
  scale.set_scale(2280.f);           
  scale.tare(); 

  Scheduler.startLoop(loop2);
  
}

//Load cell
void loop() {

  temp = scale.get_units(), 1;
  temp = temp*10;
  Value = (int)(temp);
  Serial.println(Value);
 
  scale.power_down();              // put the ADC in sleep mode
  delay(10);
  scale.power_up();
}


void loop2() {
  myStepper.step(1);
  stepCount++;
   delay(1);
}
1 Like

Which Arduino? Which Scheduler library?

This one appears to be what you used: Scheduler - Arduino Reference This only works on a SAM-based Arduino such as a Due.

Where did you get the HX711 library? This one: GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales. seems to actually know about the yield() function and should work properly with the above scheduler.

Sorry I miss something. we use arduino due and for the HX711.h library as to which you suggested is what we are currently using and the output seems not that good.
NOTE: Additional Problem is that yield() function seems have conflict with scheduler when both integrated.

yield() is part of the scheduler. It can't "conflict" although depending on how you use it, it may give you the wrong result.

I don't have an HX711 so it's difficult for me to test this.

How well does the stepper motor work when you aren't using the HX711? What is the stepper driver you are using?

When we run both devices independently, the output has a good result though after integrating the problem occur. We use L298N driver for the stepper motor.

I don't know anything about that Scheduler library. I am generally suspicious that things like waste CPU cycles doing something that could just as easily be done using millis() as illustrated in Several Things at a Time

That said, it seems to me that you have your code organised backwards. I would schedule the scale readings because they don't need to be done nearly as often as you need the stepper to step.

And look at the AccelStepper library - it is designed to run in the background.

Finally, an L298 is a poor choice for driving a stepper motor. If you use a specialized stepper driver that takes step and direction signals it removes a lot of calculation from the Arduino.

...R
Stepper Motor Basics

Good day sir robin, my overall objective is to monitor the load cell output constantly while the stepper motor turns, as the load cell sensor output has an increasing value the stepper motor will turn counter-clockwise and when the load cell sensor output has an decreasing value the stepper motor know turns clockwise.
Another additions is that the stepper motor we use is a bipolar 4 leads.

Limfao:
Good day sir robin, my overall objective is to monitor the load cell output constantly while the stepper motor turns,

Constantly does not mean the same thing to a computer as it does to a human.

You need to decide what is an acceptable interval between load cell readings - maybe 2 times per second would be sufficient.

Another additions is that the stepper motor we use is a bipolar 4 leads.

That is what I had assumed.

...R

Thank you sir robin, we can already run both devices at once via elapsedmillis and some accelstepper functions. It was a GREAT HELP sir robin

Can somebody confirm that arduino due can run 3 stepper motor and 3 load cell sensor SIMULTANEOUSLY? Newbie here.
PLEASE HELP!

Hardware use:
For Stepper Motor Driver: L298N
For Load Cell Sensor: HX711

Library use:
For Stepper Motor: Stepper.h (Default Library)
For Load Cell Sensor: bodge Library GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.

NOTE: We already tried using the millis, accelStepper, and stepper.h

Why are you starting this Thread when you were already getting advice in your other Thread about the same subject?

I had the impression from your Reply #8 in the other Thread that things are working as you want.

I am suggesting to the Moderator to merge this with your other Thread so I am not reading or answering the same questions twice.

...R

Yes, the Arduino can do this. Can you do it? That is the question.

We already know a little of what you tried in the earlier thread. But how about you bring us up to date with what you've tried since then? Post your code.