Go Down

Topic: (Solved)Steppermotor and serial.print and read combined (Read 20294 times) previous topic - next topic

backbone

Next is to find out the touching point of the spring by the moving top plate. I hope I can find some time this evening to add some code and test it. One step furhter!

Thanks, Paco
Never to old to learn and I learn every day

backbone

Robin,

I changed the code to see how a real stepper would react instead of pulsing led 13 in the void stepperMotor()
So for the test I want to move the stepper in 180 degrees = 100 steps just to see if it works and if there is any motion.
But the stepper only steps one step per second with this code.

Paco

Code: [Select]
[/// this is just to test the understanding of using the HX711 and steppermotor

#include <HX711.h>
#include <AccelStepper.h>

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); // 24 bit load cell amplifier

AccelStepper stepper(1,9,8); // set up the stepper as 4 wire bipolair on pin 8,9 for EASY DRIVER or other driver board

unsigned long startMillis;
unsigned long endMillis;
unsigned long currMillis;
unsigned long prevMillis;
unsigned long intervalMillis = 10; // do not change

byte maxTests = 100;
byte curTest = 1;

byte maxSteps = 100;
byte curStep = 1;

long scaleData = 0;

void setup()
{
  Serial.begin(9600);
  stepper.setMaxSpeed(3000);
  stepper.setSpeed(3000);
  stepper.setAcceleration(800); // do not remove!
  prevMillis = millis();
}

void loop()
{
  if (curTest > maxTests)
  {
    return;
  }
  startMillis = millis();
  curStep = 0;
  testTiming();
  endMillis = millis();
  curTest ++;
  stepper.run(); // does it block the 100 steps?
}

void testTiming()
{
  while (curStep < maxSteps)   // will loop through the steps at the speed set by intervalMillis
  {   
    currMillis = millis();
    if (currMillis - prevMillis >= intervalMillis)
    {
      stepMotor();
      prevMillis += intervalMillis;
      curStep ++;
    }
  }
  // now the Scale should be ready for reading
  scaleData = (scale.read()/100);
  Serial.print("B,");
  Serial.println(scaleData);
  Serial.print("A,");
  Serial.println(stepper.currentPosition());
}

void stepMotor()
{
  stepper.moveTo(100);
}
code]
Never to old to learn and I learn every day

Robin2

Shouldn't you have stepper.run() inside stepMotor() and nothing else.

Stepper.run() is what actually causes the steps to happen. Because this is a demo program very little happens in loop and there is no use putting stepper.run() there.

You seem to have chosen acceleration - that may interfere with what you are trying to do, take it out for now. And be sure to set the motor speed to match the step time that you want.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

backbone

Quote
Shouldn't you have stepper.run() inside stepMotor() and nothing else.

stepper.runSpeed(); did the trick.
For testing purpose I just set maxTest to 100.
Motor runs and values of the force come in.

Quote
You seem to have chosen acceleration - that may interfere with what you are trying to do, take it out for now. And be sure to set the motor speed to match the step time that you want.


Acceleration line removed.

Thanks,

Paco
Never to old to learn and I learn every day

backbone

Hi Robin,

I could not get your solution to work with satisfaction.
So I went for a bypass.
2 x Nano
Nano1 to measure Position and Force
nano2 to control the stepper motor.
Two digital pins in between them to control the ON/OFF of the stepper motor.

Thanks for all the effort and time taken.

Paco
Never to old to learn and I learn every day

Go Up