[Music Robot] how can i set the value in function?


#1

Hello~

I’m making a Music Robot.

I have a few question about it.

(Questions)

1.the step motor moves 1.8 degree/step. -> am I right?

2.how many micro-step is in one step (2H microstep driver)?
if… 360 degree / 1.8 degree -> only 200 step.
but… If I try “stepper.MoveTo(200)”, the step move does NOT do 1 rotation.

3.If I try the following code(“stepper.MoveTo(25000)”),

the step moter looks like 1 rotation.

in the code “stepper.MoveTo( xxxx )”,

how do i set the “xxxx” if I want one rotation?

I wanna know the machanism to calculate the “xxxx” for precise ONE rotation.

4.If I want 10 rotation, do I have to use function “stepper.move( yyy )”?

thx for reading.


#2

Hi @limegriin,

Yeah, the step motor does move 1.8 degree/step. But you need to modify the DIP switch by yourself on the 2H microstep driver,

For example, OFF ON OFF OFF OFF OFF ON (SW1-SW7, micro 8), it means 1600 pules/rev.

OFF OFF OFF OFF OFF OFF OFF, it means 200 pules/rev, much faster than the first one.

The SW5-SW7 are used to control the rotate speed.

In your case, it seems like the DIP has been switched to 128 micros, so it would be 128*200=25600 pulse/rev.


#3

thx @Johnny

but It is very strange.

I tried the following code( “moveTo(25600*10)”).

If 25600 is one rotation, I think it is rotate 10 times.

but It rotate 10 times and about 15 degree. ( 360 degree * 10 roatation + 15 degree(about) )

It is about 3665 degree ( moveTo(25600*10).

I thinkt that 25600 is more than one rotation.

u said that 25600 is one rotation, r u sure?

thx for reading Johnny again ^^.


#4

Hi @limegriin,

Can you try it in other cases? 8 micros and 16 micros? There might be out of step when the stepper motor is running. But I think the 15 degree is abnormal.

Thanks!


#5

Hi @Johnny.

I tested the stepper motor( 128 micro, 16 micro)


128 micro test url:

16 micro test url

src code(128 micro)------------------------------------------------------------------
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <AccelStepper.h>

long ONE_ROTATION = 25600; //128 micro

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 13, 12); // 13-PUL,12-DIR

void setup(){
//init Serial
Serial.begin(9600);
Serial.println("*.Setup routine…");

//init Stepper
stepper.setAcceleration(80000);
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(4000);    

}

void loop(){
if( Serial.available() ){
String line;
line += Serial.read();

    long MoveToValue = ONE_ROTATION * 10;
    Serial.println(MoveToValue);
    
    stepper.moveTo(MoveToValue);   
}

stepper.run();

}

src code(16 micro)------------------------------------------------------------------

#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <AccelStepper.h>

long ONE_ROTATION = 3200; //16 micro

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 13, 12); // 13-PUL,12-DIR

void setup(){
//init Serial
Serial.begin(9600);
Serial.println("*.Setup routine…");

//init Stepper
stepper.setAcceleration(80000);
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(4000);    

}

void loop(){
if( Serial.available() ){
String line;
line += Serial.read();

    long MoveToValue = ONE_ROTATION * 10;
    Serial.println(MoveToValue);
    
    stepper.moveTo(MoveToValue);   
}

stepper.run();

}


my stepper motor rotate too much…


#6

Hi @limegriin,

Please try the program. If it works, the stepper motor would move 10 laps. Please tell me the result after your test. :smile:

Thanks!

#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>

#define pulse 13
#define dir 12

void setup()
{
    pinMode(pulse, OUTPUT); 
     pinMode(dir, OUTPUT); 
  digitalWrite(pulse,LOW);  //control stepper motor driver pulse
  digitalWrite(dir,LOW);   //control stepper motor driver direction
}
long i;
void loop()
{
  for(i=0;i<32000;i++)   //16 micro
  {
  digitalWrite(pulse,LOW); 
  delayMicroseconds(1000);   //at least more than 100
  digitalWrite(pulse,HIGH);
  delayMicroseconds(1000);
  } 
  delay(2000); 
}

#7

Hi, @Johnny

ur code works fine. precisly 10 labs.thx. ^^

I think that my problem was acceleration stepper class.

too high acceleration and max speed.

I have **a few more questions about AccelStepper class.

sorry to bother u ^^;;;;**


AccelStepper class

1)method “setMaxSpeed(XXXX)” --> what is the “XXXX” value ? steps?

If I set the value “1000”, does it means that the 2h micro stepper driver generate 1000 pulse / 1 second ??

  1. method “**setAcceleration(**YYYY)” -> what is the “YYYY” value?

    If I set the value “1000”, does it mean that the time(“from 0 pulse/second to 1000 pulse/second”) is 1 second??

  2. about 2h micro stepper driver DIP

SW1(OFF) SW2(ON) SW3(OFF) -> peak 1.69

what it means the peak value?

if i set “OFF ON OFF”, does the driver control the current from 0 to 1.69 ?

if motor demand more current( for example 2.0 ), does the driver supply only 1.69?(because of the peak value DIP setting)


that’s all. I’m sincerely appreciate for ur help, Johnny.

I know that my question might be looked silly. I’m a beginner of this field ^^;;;


#8

Hi @limegriin,

Sorry for the lately reply, I was on a big holiday last two weeks.

The answer of your first two questions are right. As for the 3rd question, “peak” means the peak current is 1.69A. And RMS means the average current.

Generally, it depends on the model of stepper motor. And, higher load, higher current. If the current is higher than the peak current, the driver would shut down the power.


#9