Firefly Open Source Community

   Login   |   Register   |
New_Topic
Print Previous Topic Next Topic

Fireduino and AccelStepper Stepper motors

37

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
37

Fireduino and AccelStepper Stepper motors

Posted at 6/9/2017 00:59:07      View:3293 | 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 :
  1. #define STEP_PIN 5

  2. void setup() {
  3.     pinMode(STEP_PIN, OUTPUT);  
  4. }

  5. void step(long stepDelay) {
  6.     digitalWrite(STEP_PIN, HIGH);
  7.     delayMicroseconds(stepDelay);
  8.     digitalWrite(STEP_PIN, LOW);
  9.     delayMicroseconds(stepDelay);
  10. }

  11. void loop() {
  12.     // rotate by 100 steps.
  13.     for (int i = 0; i < 100; i++) {
  14.         step(140); //140 seems to be the fastest rate for my motors. (ST5918L2008-A)
  15.     }
  16. }
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 :
  1. #include <AccelStepper.h>


  2. // Define two steppers and the pins they will use

  3. AccelStepper stepper1(1, 3, 2); // pin 3 = step, pin 2 = direction
  4. AccelStepper stepper2(1, 5, 4); // pin 5 = step, pin 4 = direction
  5. AccelStepper stepper3(1, 7, 6); // pin 7 = step, pin 6 = direction


  6. int pos1 = 1000;
  7. int pos2 = 0;
  8. int pos3 = 0;


  9. void setup()

  10. {  

  11. Serial.begin (115200);
  12.   

  13.   stepper1.setMaxSpeed(16000);
  14.   stepper1.setAcceleration(1000);

  15.   stepper2.setMaxSpeed(16000);
  16.   stepper2.setAcceleration(1000);
  17.   
  18.   stepper3.setMaxSpeed(16000);
  19.   stepper3.setAcceleration(1000);

  20. }


  21. void loop()

  22. {

  23.   if (stepper1.distanceToGo() == 0)
  24.   {
  25.     pos1 = -pos1;
  26.     stepper1.moveTo(pos1);
  27.   }

  28.   if (stepper2.distanceToGo() == 0)
  29.   {
  30.     pos2 = -pos2;
  31.     stepper2.moveTo(pos2);
  32.   }
  33.   
  34.    if (stepper3.distanceToGo() == 0)
  35.   {
  36.     pos3 = -pos3;
  37.     stepper3.moveTo(pos3);
  38.   }

  39.   stepper1.run();
  40.   stepper2.run();
  41.   stepper3.run();
  42.   
  43.   Serial.print("A");
  44.   Serial.println(stepper1.currentPosition());
  45.   
  46.   //Serial.print("B");
  47.   //Serial.println(stepper2.currentPosition());
  48.   
  49.   //Serial.print("C");
  50.   //Serial.println(stepper3.currentPosition());

  51.   

  52.       


  53. }

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" :
  1. void AccelStepper::step1(long step)
  2. {
  3.     (void)(step); // Unused

  4.     // _pin[0] is step, _pin[1] is direction
  5.     setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
  6.     setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
  7.     // Caution 200ns setup time
  8.     // Delay the minimum allowed pulse width
  9.     delayMicroseconds(_minPulseWidth);
  10.     setOutputPins(_direction ? 0b10 : 0b00); // step LOW
  11. }
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)


Reply

Use props Report

37

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
37
Posted at 6/9/2017 01:14:46        Only Author  2#
Last edited by satolas In 6/9/2017 01:16 Editor

:-)
By the way the sample from stepper.cpp

  1. void Stepper::stepMotor(int thisStep)
  2. {
  3.   if (this->pin_count == 2) {
  4.     switch (thisStep) {
  5.       case 0:  // 01
  6.         digitalWrite(motor_pin_1, LOW);
  7.         digitalWrite(motor_pin_2, HIGH);
  8.       break;
  9.       case 1:  // 11
  10.         digitalWrite(motor_pin_1, HIGH);
  11.         digitalWrite(motor_pin_2, HIGH);
  12.       break;
  13.       case 2:  // 10
  14.         digitalWrite(motor_pin_1, HIGH);
  15.         digitalWrite(motor_pin_2, LOW);
  16.       break;
  17.       case 3:  // 00
  18.         digitalWrite(motor_pin_1, LOW);
  19.         digitalWrite(motor_pin_2, LOW);
  20.       break;
  21.     }
Copy the code


Also not working
Reply

Use props Report

37

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
37
Posted at 6/10/2017 20:58:28        Only Author  3#
Any idea ? :-/
Reply

Use props Report

37

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
37
Posted at 7/7/2017 02:52:06        Only Author  4#
Okay :-)
Just to don't let that post without solution :

kind of weird, but adding that does the trick:
pinMode(_pin[0], OUTPUT);
pinMode(_pin[1], OUTPUT);

We are just repeating the pinMode status to output. Then it happening something finally :-)
By the way on a DUE, the code without that two lines its working...so maybe developpement boards have their own sensibility at the end

so instead of :
  1. void AccelStepper::step1(long step)
  2. {
  3.     (void)(step); // Unused

  4.     // _pin[0] is step, _pin[1] is direction
  5.     setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
  6.     setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
  7.     // Caution 200ns setup time
  8.     // Delay the minimum allowed pulse width
  9.     delayMicroseconds(_minPulseWidth);
  10.     setOutputPins(_direction ? 0b10 : 0b00); // step LOW
  11. }
Copy the code


Write that :
  1. void AccelStepper::step1(long step)
  2. {
  3.     (void)(step); // Unused

  4.         pinMode(_pin[0], OUTPUT);
  5.         pinMode(_pin[1], OUTPUT);

  6.     // _pin[0] is step, _pin[1] is direction
  7.     setOutputPins(_direction ? 0b10 : 0b00); // Set direction first else get rogue pulses
  8.     setOutputPins(_direction ? 0b11 : 0b01); // step HIGH
  9.     // Caution 200ns setup time
  10.     // Delay the minimum allowed pulse width
  11.     delayMicroseconds(_minPulseWidth);
  12.     setOutputPins(_direction ? 0b10 : 0b00); // step LOW
  13. }
Copy the code
Reply

Use props Report

You need to log in before you can reply Login | Register

This forum Credits Rules

Quick Reply Back to top Back to list