Go Down

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

Robin2

I've now had a little time to look at your earlier posts ...

If this means that you don't care about missing steps
Quote
Let the accuracy or motor amp be the last hurdle to sort out.
then you will have to sort the problem out without my help. Going that route is like trying to push something with string.

In an earlier post you have
Quote
For below code I have to find a way to switch off the coils after each step because I will smoke this board too..
Sorry, but this is nonsense and just gets in the way. Choose a suitable motor voltage that works with your driver and motor and stop confusing your code with stuff lke this.

Quote
I tried to put the "stepper.run();" into a "blinkwithout delay" so it would be called in a lesser tempo but that slows down the stepper too. When I set 1 millisecond it still is to slow even.
You need more frequent calls to stepper.run() - not less. There is nothing to prevent you having stepper.run() at a few places within loop().

Quote
use it inside the arduino to send a reset signal to the PC
Why would you want to reset the PC? How could that speed things up. My PC takes a minute or so to reset.

My advice is simple ...

Take out the encoder stuff (at least for now)
Get the motor to step accurately without a load and then see if it also works under load.
Don't do anything else until the motor ALWAYS steps accurately under load.

Before concluding that you need a more powerful motor
Check the voltage available to the motor - perhaps by temporarily replacing the motor with an equivalent high wattage resistor.
Try it with a proper stepper motor driver board and a high voltage power supply.

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

Gilgamesh90

Is that a unipolar or bipolar stepper? Why dont you use a personally developed code to run the stepper and avoid any problems with the library?

Robin2


Why dont you use a personally developed code to run the stepper and avoid any problems with the library?

Rest assured, the problem is not with the library in this case.

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

backbone

Robin,

Thanks for your time again.

In the end I care about using the stepper only to make it less complicated and no encoder part and code but I had to start somewhere and the encoder is/was a part of detecting and learning. I know it is all a steep curve but willing to learn.
The first original design of this device to emasure compression was a rebuild vertical drilling stand equipped with an linear encoder strip so that was a heritage for counting the steps. The second design used a DC motor and the YES the encoder again, but I promiss I will get rid of all related to the encoder.

Due to limited time I have to work currently with the mechanics and electronics I have in stock.
New parts can be ordered but that takes time and I am not the person to sit down and wait untill........parts arrive.
Then for a certain time with less accuracy untill all the coding is working properly and the harware can be tuned to perfection to over come the accuracy.

Switching off the coils was a workaround for not having the good hardware.

I will not reset the PC! :-) I send a reset signal from the Arduino to the program on the PC so it knows we can start to measure.
Sorry if that was not clear written down.

I will crank up the motor voltage  and working on getting an other driver board.
The lastest BED driver is 1,4 amps max. So I have to look for other options.

I know the accelstep lib is OK.
It looks like the HX711.lib is causing the problem in combination with the stepper.lib.

Stepper is a bipolar one as far as I know as the spec with the unit only say 1.5 amps. Stepper Motor :42BYGH series ( NEMA17)

Did I for got something? :-)





Never to old to learn and I learn every day

Robin2

The Pololu A4988 driver uses the same chip as the BIgEasydriver and "claims" it can manage up to 2 amps with adequate cooling. according to the Allegro datasheet the absolute max is "about" 2 amps. I think Pololu has another board that can provide a bit more current. The problem is that the drivers get a lot more expensive if you want to go beyond those current levels. If you already have (or have ordered) a BigEasydriver I would try that with the current suitably limited before buying another board. You would be only a tiny bit below the motor's capacity.

The reason I have been focusing on getting the harware right is because, without that, you can't tell whether you have a hardware or a software problem.

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

backbone

Robin,

I understand about the focusing on hardware.
But I cant relax waiting for..................... I hope you understand. ;-)
Not yet ordered an other driver.
But I think one of these babys would do the job in the future. Not on the limit.
[url][/http://www.ebay.nl/itm/TB6560-3A-Driver-Board-CNC-Router-Stepper-Motor-Drivers-1-Axis-Controller-/360919866303?pt=LH_DefaultDomain_0&hash=item5408801bbfurl]

Paco
Never to old to learn and I learn every day

backbone

I removed all encoder, coil enable and serial.prints code and this a quick test again.

As soon as I uncomment the trouble line of code

Code: [Select]
ForceValueTemp = (scale.read()/100);

the stepper goes into slow mode.
So this is step one to solve.

Code: [Select]
#include <HX711.h>
#include <AccelStepper.h>

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

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

int LeftTurnUp = 0;
int RightTurnDown = 0;
int incomingByte = 0;   // for incoming serial data
int dirPin = 8;
int stepPin = 9;
int StepCounter =0;
boolean stepperPuls = 0;
long ForceValueTemp = 0;
long ForceValueTempOld = 0;
boolean Start = 0;
boolean Recording = 0;

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

void setup()
{
  Serial.begin(9600);
  StepCounter = 200;
  stepper.setMaxSpeed(1000);
  stepper.setSpeed(1000);
  stepper.setAcceleration(800); // do not remove!
}

void loop()
{

  ForceValueTemp = (scale.read()/100); // problem code line!!!!!!!!!!!!!!!!!!!!!!!!

  if (Serial.available() > 0)
  {
    incomingByte = Serial.read();
    {
      if (incomingByte == '1') // move motor Up
      {
        LeftTurnUp = 1;
        RightTurnDown = 0;
      }

      if (incomingByte == '2') //move motor Down
      {
        RightTurnDown = 1;
        LeftTurnUp = 0;
      }

      if (incomingByte == '3') //stop motor and disable coils
      {
        LeftTurnUp = 0;
        RightTurnDown = 0;
        stepper.moveTo(0);
      }

      if (incomingByte == '4') // Start motor turn downwards
      {
        ForceValueTempOld = ForceValueTemp;
        Start = 1;
        RightTurnDown = 1;
        LeftTurnUp = 0;
      }

    }
  }

  if (LeftTurnUp == 1)  //left turn
  {
    stepper.moveTo(100); //move many steps - more then mechanical needed
    stepper.run();
  }

  if (RightTurnDown == 1)  //right turn
  {
    stepper.moveTo(-100); //move many steps - more then mechanical needed
    stepper.run();
  }
Never to old to learn and I learn every day

Robin2

That stepper driver should be fine, and the price is good.

Is it necessary to read the scale between every step of the motor?

How much does it slow the motor? How slow is slow? Does slow really matter?

I know nothing about that scale-reading library. Maybe you could write your own code to read the scale without using the library.

Even if it is slow, is it stepping correctly?

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

backbone

With slow I mean it is just ticking.
if I have to describe it, it looks like 1 microstep inside 1 second.
A full turn would take one hour............ :-)
If needed I make a video of it what the slow speed is....
looks like the loop is blocked by the HX711.lib and release the stepper.run only once in every second.

As explained I need to measure the change in force as soon as the spring starts to compress.
That is the key point to start all.
Before the spring is compressed the value stays the same but when it rises I need to do an action which is start to record the values. Then I can measure in sync with the 1mm steps.

Writing my own code is out of my knowledge.
I can ask the lib writer to have a look at it.

paco

Never to old to learn and I learn every day

Robin2

#24
May 27, 2014, 11:30 am Last Edit: May 27, 2014, 11:32 am by Robin2 Reason: 1
If it was my project I would write a short sketch (that doesn't use any stepper code) to measure the time (millis()) needed to do 100 or 1000 scale readings just to see how long it actually takes. But that may provide information without providing a solution. It would be very useful to discover that reading the scale does NOT cause a delay.

I guess you could use separate Arduinos for reading the scale and driving the stepper motor - but that seems a bit of a bodge.

Looking at your latest post again, I'm not sure what you mean by 1 microstep every second. Earlier you said you are using full steps. Are you back to a problem of not driving the motor properly rather than a software problem? Also, accelstepper has to do a lot more work to drive a stepper through an L298 chip than if it just has to produce step and direction signals.

If you had a "proper" stepper motor driver board I would suggest writing your own code to step the motor in case there is some strange conflict between accelstepper and the scale libraries.

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

backbone

#25
May 27, 2014, 12:56 pm Last Edit: May 27, 2014, 02:01 pm by backbone Reason: 1
Quote
Looking at your latest post again, I'm not sure what you mean by 1 microstep every second. Earlier you said you are using full steps. Are you back to a problem of not driving the motor properly rather than a software problem?


No, the L298 does not allow microsteps.
This is a mechanicla behaviour I see happening  visual.
I drive the stepper with the same code the only exception is uncomment the line with the scale reading.
So it is code/software problem/conflict. I will make a video this evening so you see the thicking steps when the scale reading is active in the code.

Quote
If it was my project I would write a short sketch (that doesn't use any stepper code) to measure the time (millis()) needed to do 100 or 1000 scale readings just to see how long it actually takes. But that may provide information without providing a solution. It would be very useful to discover that reading the scale does NOT cause a delay


Good idea even if it does not solve the problem. Only current problem is "just writing a simple sketch":-)
Something like this you mean

Void loop()
{
Scalevalue = (scale.read()/100);
Serial.print(Scalevalue);
time = millis;
Serial.print(time-timeold);
timeold = time;
}

The HX711 is set to 10 Hz


Never to old to learn and I learn every day

wildbill

Quote
I had to raise the baudrate to 57600 too.


Why stop there? The arduino can handle twice that easily enough. Some people have reported getting substantially more working. If serial comms are causing you timing issues, at least step it up to 115200.

backbone

Wildbill,

Thanks for the info and concerns.
Somewhere in all the debugging  at 115200 bps setting at both sides there was no communication anymore.
Did not know the cause but logical the first thing I did was step down in bps level.
So I tried 57600 bps and that was the speed that worked.
Past days are done on 9600.
Will try once again this evening. Let you know the result.

Paco
Never to old to learn and I learn every day

Robin2

I am thinking of much simpler code

Code: [Select]
#include <HX711.h>

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

unsigned long startMillis = 0;
unsigned long endMillis = 0;

void setup() {
  Serial.begin(9600);
  startMillis = millis();
   for (int n = 0; n < 100; n++) {
      int s = scale.read();
   }
   endMillis = millis();
   Serial.println(startMillis - endMillis);
}

void loop() {

}


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

backbone

#29
May 27, 2014, 08:52 pm Last Edit: May 27, 2014, 09:42 pm by backbone Reason: 1
Just had time to test the timing code

Will now first make the video of the thicking

Paco
Never to old to learn and I learn every day

Go Up