|
Fireduino and AccelStepper Stepper motors
Posted at 6/9/2017 00:59:07
View:3283
|
Replies:3
Print
Only Author
[Copy Link]
1#
Hello :-)
Specs :
- I have a Fireduino bought few month ago
- I use ArduinoIDE-1.8.0_for_Fireduino_1.3.1
- Windows 10 Pro N
- On a MacbookPro 2015 (15")
I 'm trying to drive stepper motors with the Fireduino.
Compared to an Arduino DUE the Fireduino is way faster for that task !!! really nice to see an "arduino like" board driving steppers motors so fast.
The problem :
So with that kind of very simple code it seems to work :
Working code :
- #define STEP_PIN 5
- void setup() {
- pinMode(STEP_PIN, OUTPUT);
- }
- void step(long stepDelay) {
- digitalWrite(STEP_PIN, HIGH);
- delayMicroseconds(stepDelay);
- digitalWrite(STEP_PIN, LOW);
- delayMicroseconds(stepDelay);
- }
- void loop() {
- // rotate by 100 steps.
- for (int i = 0; i < 100; i++) {
- step(140); //140 seems to be the fastest rate for my motors. (ST5918L2008-A)
- }
- }
Copy the code
But when I try to use a code with the Accelstepper library, nothing seems to move anymore...
For exemple that one :
Not working code :- #include <AccelStepper.h>
- // Define two steppers and the pins they will use
- AccelStepper stepper1(1, 3, 2); // pin 3 = step, pin 2 = direction
- AccelStepper stepper2(1, 5, 4); // pin 5 = step, pin 4 = direction
- AccelStepper stepper3(1, 7, 6); // pin 7 = step, pin 6 = direction
- int pos1 = 1000;
- int pos2 = 0;
- int pos3 = 0;
- void setup()
- {
- Serial.begin (115200);
-
- stepper1.setMaxSpeed(16000);
- stepper1.setAcceleration(1000);
- stepper2.setMaxSpeed(16000);
- stepper2.setAcceleration(1000);
-
- stepper3.setMaxSpeed(16000);
- stepper3.setAcceleration(1000);
- }
- void loop()
- {
- if (stepper1.distanceToGo() == 0)
- {
- pos1 = -pos1;
- stepper1.moveTo(pos1);
- }
- if (stepper2.distanceToGo() == 0)
- {
- pos2 = -pos2;
- stepper2.moveTo(pos2);
- }
-
- if (stepper3.distanceToGo() == 0)
- {
- pos3 = -pos3;
- stepper3.moveTo(pos3);
- }
- stepper1.run();
- stepper2.run();
- stepper3.run();
-
- Serial.print("A");
- Serial.println(stepper1.currentPosition());
-
- //Serial.print("B");
- //Serial.println(stepper2.currentPosition());
-
- //Serial.print("C");
- //Serial.println(stepper3.currentPosition());
-
-
- }
Copy the code It moves clockwise/anti-clockwise as expected with the Arduino Due and Arduino UNO.
But with the Fireduino nothing happens :-/
Is there any incompatibility beetween AccelStepper and the fireduino ?
Seems strange because the file AccelStepper.cpp seems to use a similar command to move the stepper motors as the first sketch that I gaved here :
AccelStepper.cpp (Just a sample that seems to do the "pulse" job for the stepper) :
AccelStepper.cpp "step1" :- void AccelStepper::step1(long step)
- {
- (void)(step); // Unused
- // _pin[0] is step, _pin[1] is direction
- setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
- setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
- // Caution 200ns setup time
- // Delay the minimum allowed pulse width
- delayMicroseconds(_minPulseWidth);
- setOutputPins(_direction ? 0b10 : 0b00); // step LOW
- }
Copy the code
I don't really understand why the motors don't move at all with the same code on the Fireduino :-/
Thanks for your attention.
Regards,
satolas
PS : stepper.h (included with the arduino and Fireduino library don't work either)
|
|