Hi friends,
A while ago, i just managed to get up my homemade coilwinder done. For the first runs i only used to halfautomatically handwind them, but smaller coils need more precision, therefore a second motor needs to get into the game.
The setup consits of the following:
- Bigeasydriver for driving the main motor
- Adafruit motorshield V2 for the wire guide.
- Arduino Uno
- both motors are 200 steps / 1.8 deg per step
so far, everything works fine, but with one discrepancy:
When controlling the speed of the two motors simultaniously via a potentiometer,
they do not run, with the intended speed (RPM) . Before going deeper here is the code:
(its a patchwork of schamlzhaus, and adafruit example code to run the motors):
// Example5 code for Brian Schmalz's Easy Driver Example page
// http://www.schmalzhaus.com/EasyDriver/EasyDriverExamples.html
// Modified by Ste_Trat
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x60);
Adafruit_StepperMotor *mystepper2 = AFMS.getStepper(200, 2);
// Define our three input button pins
#define LEFT_PIN 4
#define STOP_PIN 3
#define RIGHT_PIN 2
// Define our analog pot input pin
#define SPEED_PIN 1
// Define our maximum and minimum speed in steps per second (scale pot to these)
#define MAX_SPEED 1000
#define MIN_SPEED 0.1
void forwardstep1() {
mystepper2->onestep(FORWARD, SINGLE);
}
void backwardstep1() {
mystepper2->onestep(BACKWARD, SINGLE);
}
AccelStepper Astepper2(forwardstep1, backwardstep1);
// Define the stepper and the pins it will use
AccelStepper stepper1(AccelStepper::DRIVER, 9, 8);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
AFMS.begin(); // create with the default frequency 1.6KHz
// AFMS.begin(1000); // OR with a different frequency, say 1KHz
//stepper2.setSpeed(1000.0); // default is 10 rpm
stepper1.setMaxSpeed(1000.0);
//stepper1.setAcceleration(100.0);
Astepper2.setMaxSpeed(1000.0);
//stepper2.setAcceleration(100.0);
// The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go
// Set up the three button inputs, with pullups
pinMode(LEFT_PIN, INPUT_PULLUP);
pinMode(STOP_PIN, INPUT_PULLUP);
pinMode(RIGHT_PIN, INPUT_PULLUP);
}
void loop() {
static float current_speed = 0.0; // Holds current motor speed in steps/second
static int analog_read_counter = 1000; // Counts down to 0 to fire analog read
static char sign = 0; // Holds -1, 1 or 0 to turn the motor on/off and control direction
static int analog_value = 0; // Holds raw analog value.
// If a switch is pushed down (low), set the sign value appropriately
if (digitalRead(LEFT_PIN) == 0) {
sign = 1;
}
else if (digitalRead(RIGHT_PIN) == 0) {
sign = -1;
}
else if (digitalRead(STOP_PIN) == 0) {
sign = 0;
}
// We only want to read the pot every so often (because it takes a long time we don't
// want to do it every time through the main loop).
if (analog_read_counter > 0) {
analog_read_counter--;
}
else {
analog_read_counter = 3000;
// Now read the pot (from 0 to 1023)
analog_value = analogRead(SPEED_PIN);
// Give the stepper a chance to step if it needs to
Serial.println(analog_value);
stepper1.runSpeed();
Astepper2.runSpeed();
// And scale the pot's value from min to max speeds
current_speed = sign * (((analog_value / 1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED);
// Serial.println(current_speed);
// Update the stepper to run at this new speed
stepper1.setSpeed(current_speed);
Astepper2.setSpeed(current_speed);
}
// This will run the stepper at a constant speed
stepper1.runSpeed();
Astepper2.runSpeed();
}
The original code is from (Example #5. Changing motor speed)
What really concerns me, is:
When running the motors with the original example codes, everything is fine (Controlling speed, and direction with the intended RPM). But putting them together, everything is messed up. They work but, not with the defined speed. It seems like the smaller motor throttles the speed of the bigger motor.
i want
SpeedMotorBig (RPM) = SpeedMotorSmall (RPM)
but i got
SpeedMotorBig (RPM) < SpeedMotorSmall (RPM)
I need to get this stage working, before taking the diameter of the wire, and the pitch of the linear rod into account.
What happened? Anyone an idea ?
The last solution should be buying another Big-EasyDriver.
Greetings from Austria