Go Down

Topic: Generate sine wave from movement of stepper motor? (Read 414 times) previous topic - next topic

Somark

How would I go about producing a readable sine wave from the movement of a stepper motor?

I have a stepper motor and I'm using the accelstepper library to accelerate and decellerate the motor so that it mimics the abnormal sine wave of a heartbeat or reading from an EKG. That's all fine and dandy. I want to now also take an output of this abnormal sine wave to use in data collection. I really need the reading in either the abnormal sine wave or an electronic signal that matches the abnormal sine wave in amplitude/intensity.

https://www.sainsmart.com/products/0-50khz-dds-function-signal-generator-module-custom-arbitrary-waveform?variant=45101644692&gclid=Cj0KCQjw-JvaBRDGARIsAFjqkkpcnhhSnImFs3f9XnyFKuaeJAVRZTn9gOKj19F6oSvm-PMwU35zDmsaAnqREALw_wcB

https://www.sainsmart.com/products/udb1002s-function-signal-generator-source-frequency-counter-dds-module-wave-2mhz?nosto=customers-also-bought

I found those two devices but it seems that it's not what I'm looking for. They produce signals but they seem to require manual input to change the output and not reliant on the arduino for production of signals. Any help would be appreciated, thank you

jremington

How does one "read a sine wave from the movement of a stepper motor"?

Somark

I honestly have no idea. I was thinking of using a button and using how long it is pressed and depressed to generate the sine wave by attaching a cam lobe to the shaft of the stepper motor and using the radius of said cam lobe to determine a set amplitude. How would I go about producing a sine wave from the button depression timings?

MorganS

Perhaps you mean Sinus Rhythym? A sine wave is a mathematical ideal that is nothing to do with an EKG or ECG.

You have the stepper and you have a working program to drive the stepper? Then show us that program.

Since you have the data somehow already in the program, so it can drive the stepper, why would you need to get the data from the stepper? It's just a dumb motor with two coils of wire. There's no data in there.

Where is this 'data' going? You want the stepper to move a cam, so maybe you want a physical thing bouncing up and down in time with the ECG? That's weird.
"The problem is in the code you didn't post."

Somark

Code: [Select]
#include <AccelStepper.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

AccelStepper stepper1(AccelStepper::FULL2WIRE, 10, 11);
AccelStepper stepper2(AccelStepper::FULL2WIRE, 12, 13);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int spd = 1000;    // The current speed in steps/second
int sign = 1;      // Either 1, or 0. Can use to change to reverse if sign= -1
String RPM=("RPM");
String Steps=("Steps per Second");
String disp=("Running at:"); //A display string so user knows input will be performed
String disp2=("Steps per Second:"); //Secondary Display String
int input=0;

void setup()

  Serial.begin(9600);
  lcd.begin(20,4);

  lcd.setCursor(0,0);

  stepper1.setMaxSpeed(64000); //Setting max speed of 240 RPM if Steps are 400 On Off On
  stepper1.setAcceleration(6400); //Max acceleration
  stepper1.setSpeed(3200);    //Initial Starting Speed, not important 3200=120 RPM only for stepper1();
                              //Because of Step Rate of stepper1(); driver

  stepper2.setMaxSpeed(100000); //Setting max speed of 240 RPM if Steps are 400 On Off On
  stepper2.setAcceleration(6400); //Max acceleration
  stepper2.setSpeed(4266);    //Initial Starting Speed, not important, 2133=20 RPM only for stepper2();
                              //because of Step Rate of stepper1(); driver
 
  lcd.print("Enter RPM for");
  lcd.setCursor(0,1);
  lcd.print("Stepper 1 (120 RPM)");
  lcd.setCursor(0,2);
  lcd.print("Add 1000 to RPM to");
  lcd.setCursor(0,3);
  lcd.print("change Stepper 2 20");
}

void loop()
{
 
  String input_String; //String for receving Serial.read(); and converting to int value_RPM
  String num; //A display string so user knows input will be performed at num RPM
  int key=kpd.getKey();
 
  if(key != NO_KEY){ //Making sure key is available before taking any action
    if(key == '#'){
    lcd.setCursor(0,2);
    lcd.print("Received:"); //Letting user know input was received
    lcd.setCursor(0,3);
    lcd.print(input);  //Printing what int we got
   
    if(input==9999){
      stepper1.setSpeed(0);
      stepper2.setSpeed(0);
      lcd.clear();
      lcd.print("All motion stopped");
      lcd.setCursor(0,1);
      lcd.print("Press reset button:");
      lcd.setCursor(0,2);
      lcd.print("Resume Motion or");
      lcd.setCursor(0,3);
      lcd.print("Turn off power");
    }
    else if (input >= 1000 && input <= 2000){ //This if only for stepper 2, makes sure that the input is over 1000 so we know
                        //User wants to modify stepper 2. Add 1000 to whatever RPM value you desire to control stepper 2
      lcd.clear();
      lcd.print("Modifying speed of Stepper 2");
      input = input-1000; //Once confirmed that stepper 2 is being controlled, reduce to normal values and function normally
     
      if (input == 1) {  // Rotates forward, useless for now but if you want to add reverse functionality it is useful
      disp=("Rotating Forward");
      sign = 1;
     
      }
   
    else if (input == 0){  // stop. Once stopped, it will not restart
     
      disp=("Rotation Stopping \n");
      spd = 0;
      num= "0";
      lcd.clear();
      lcd.print("You have stopped the motor. To resume motion, reupload the program");
   
      }
   
    else{
     
      spd=input/0.0046875; //Ratio for OFF ON OFF S1 S2 S3 steps. Don't question it, this is different for
                        //stepper1(); as the steps/rev are different
      num=(spd);        //Convert spd back to string to display and manipulate easier
   
      }
   
    stepper2.setSpeed(sign * spd); //Keep this for future reverse functionality
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(disp + input + " " + RPM); //Final confirmation of action Arduino is taking
    lcd.setCursor(0,1);
    lcd.print(disp2); //Displayed in steps per second
    lcd.setCursor(0,2);
    lcd.print(num + " For Stepper 2");
    lcd.setCursor(0,3);
    lcd.print("Ready for RPM change");
    }

   
   else if(input<1000){ //This else for only stepper 1
    lcd.clear();
    lcd.print("Modifying speed of Stepper 1");
    if (input == 1) {  // Rotates forward, useless for now but if you want to add reverse functionality it is useful
      disp=("Rotating Forward: ");
      sign = 1;
   
    }
   
      else if (input == 0){  // stop. Once stopped, it will not restart
     
        disp=("Rotation Stopping \n");
        spd = 0;
        num= "0";
        lcd.clear();
        lcd.print("You have stopped the motor. To resume motion, reupload the program");
     
      }
   
    else{
   
      spd=input/0.0375; //Ratio for ON OFF ON S1 S2 S3 steps. Don't question it, this is different for
                        //The second motor as the steps/rev are different
      num=(spd);        //Convert spd back to string to display and manipulate easier
   
      }
   
      stepper1.setSpeed(sign * spd); //Keep this for future reverse functionality
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(disp + input + " " + RPM); //Final confirmation of action Arduino is taking
      lcd.setCursor(0,1);
      lcd.print(disp2); //Displayed in steps per second
      lcd.setCursor(0,2);
      lcd.print(num + " For Stepper 1");
      lcd.setCursor(0,3);
      lcd.print("Ready for RPM change");
      }
   
    input=0;
   
  }
  else{
    input = input*10;
    input = input + key - '0';
    lcd.clear();
    lcd.print(input);
   
  }
  }
  stepper1.runSpeed(); //Running arduino at desired speed
  stepper2.runSpeed();
}


That's the main code I'm using.

This code right here:
Code: [Select]
#include <AccelStepper.h>
AccelStepper stepper1(AccelStepper::FULL2WIRE, 2, 5); // for a driver with step and direction

void setup()
{
  Serial.begin(9600);
    stepper1.setMaxSpeed(12800);
    stepper1.setAcceleration(11000);
}
void loop()
{
    stepper1.runToNewPosition(1600);
    stepper1.setCurrentPosition(0);
}


Was just a small proof of concept to show I could attempt to simulate the abnormal sine wave of the sinus rhythm. Basically I need the simulated sinus rhythm replicated as data that a machine can use to synchronize itself to the rotation of the stepper motor. This machine only takes inputs from an ECG/EKG so I need to convert the rotation of the stepper motor into a similar output of that of an ECG/EKG so I'm turning it into an abnormal sine wave. I don't want it to move with the ECG, I want the machine using the ECG reading to synchronize itself to the movement of the stepper motor so it knows where to look at each position of the stepper motor's movement. The reason I want the cam lobe is because I thought I could recreate such an output using the depression to recreate such a thing.

MorganS

There's another recent post from someone trying to reproduce the electrical signals than an ECG is expecting. Are you two working together or in competition?

Do you know what voltage and current the ECG is expecting to get on its probes? Can you find out?

You can run the motor in a way that looks or sounds like a heartbeat but that's going to be very different to the electrical signal that the ECG is showing on its screen. Get the two parts running independently.
"The problem is in the code you didn't post."

Southpark

I have a stepper motor and I'm using the accelstepper library to accelerate and decellerate the motor so that it mimics the abnormal sine wave of a heartbeat or reading from an EKG.
Is there any link to documents that actually say that heartbeats have 'sinewave' movements?

Paul_KD7HB

#7
Jul 13, 2018, 04:57 am Last Edit: Jul 13, 2018, 04:58 am by Paul_KD7HB
Is there any link to documents that actually say that heartbeats have 'sinewave' movements?
Only on critters with a single chamber heart! And then it is a pulse.

Paul

Southpark

Only on critters with a single chamber heart! And then it is a pulse.

Paul
haha! Thanks Paul!

Somark

There's another recent post from someone trying to reproduce the electrical signals than an ECG is expecting. Are you two working together or in competition?

Do you know what voltage and current the ECG is expecting to get on its probes? Can you find out?

You can run the motor in a way that looks or sounds like a heartbeat but that's going to be very different to the electrical signal that the ECG is showing on its screen. Get the two parts running independently.
Would you mind sending me the link to his post? We're not working together but he might have some ideas that could help me

I will definitely find out the voltages and current.

Is there any link to documents that actually say that heartbeats have 'sinewave' movements?
Well basically how I thought it is: If i attach a cam lobe to the stepper motor shaft and start it at the bottom of its rotation, I can set that position as "zero" on the graph and accelerate the motor to its highest point or the peak of the graph and decellerate it back to zero or the lowest point on the stepper motor cam lobe which would create a uniform "pulse" at any rpm I set the motor to run at. So like a cosine graph basically.

Southpark

#10
Jul 13, 2018, 09:55 pm Last Edit: Jul 13, 2018, 09:56 pm by Southpark
Would you mind sending me the link to his post? We're not working together but he might have some ideas that could help me

I will definitely find out the voltages and current.
Well basically how I thought it is: If i attach a cam lobe to the stepper motor shaft and start it at the bottom of its rotation, I can set that position as "zero" on the graph and accelerate the motor to its highest point or the peak of the graph and decelerate it back to zero or the lowest point on the stepper motor cam lobe which would create a uniform "pulse" at any rpm I set the motor to run at. So like a cosine graph basically.
I see. Thanks for explaining that. Is using a motor and cam a strict requirement? Or would it be better to just use a digital to analog converter for generating the desired waveform --- without mechanical components?

Somark

No, using a motor and cam is not a strict requirement but I would like the generated signal to be in sync with the motor

MorganS

I'm still lost. What is the signal you want to generate?

A mathematical sine wave?

A mechanical equivalent of the electrical ECG signal?

Some other heartbeat motion?
"The problem is in the code you didn't post."

Somark

So you know how as a point on the stepper motor shaft rotates in a circle it would take the form of a sinewave if you mapped its position vs time? And how an electrical ecg signal is kind of like that in that you can mimic the electrical signal by mapping a different objects position vs time? Well I want to map one point on the stepper motor as it moves through its rotation and take this data, turn it into a graph/signal that a computer could read. I can move the stepper motor in a way that slightly resembles an ecg signal. Now I want to map it so that the graph produced by recording the movement of a single point on the motor shaft is readable by a computer and interpreted as an electrical signal

MorganS

In no way is this anything like a sine wave traced out by a rotating object...

(from https://en.wikipedia.org/wiki/Electrocardiography)

Computers are really good at reading digital inputs. Arduinos have an additional ability to read analog inputs so long as they are somewhere between zero and five volts. How does a point in space on a motor shaft get into the computer?

If you have the data in the computer, why rotate the motor at all?
"The problem is in the code you didn't post."

Go Up