cocktailyogi / EggDuino

Arduino Firmware for Spherebot / Eggbot integration in Inkscape
MIT License
91 stars 138 forks source link

How to use adafruit motor shield #15

Open krikz opened 8 years ago

krikz commented 8 years ago

Hi, I try use adafruit motor shield for eggduino, make some changes like this:

// two stepper motors one on each port AF_Stepper rotAFMotor(200, rotMotorNumber); AF_Stepper penAFMotor(200, penMotorNumber); ` // you can change these to DOUBLE or INTERLEAVE or MICROSTEP! // wrappers for the first motor! void forwardstepRot() { rotAFMotor.onestep(FORWARD, SINGLE); //rotAFMotor.step(1, FORWARD, SINGLE); } void backwardstepRot() { rotAFMotor.onestep(BACKWARD, SINGLE); //rotAFMotor.step(1, BACKWARD, SINGLE); } // wrappers for the second motor! void forwardstepPen() { penAFMotor.onestep(FORWARD, SINGLE); //penAFMotor.step(1, FORWARD, SINGLE); } void backwardstepPen() { penAFMotor.onestep(BACKWARD, SINGLE); //penAFMotor.step(1, BACKWARD, SINGLE); } //make Objects AccelStepper rotMotor(forwardstepRot, backwardstepRot); AccelStepper penMotor(forwardstepPen, backwardstepPen);`

but it move motor in one direction I remove abs in lines like that:

rotMotor.setSpeed( abs( (float)rotStepsEBB * (float)1000 / (float)duration ) );

and change motorsOn and motorsOff functions

void motorsOff() { rotAFMotor.release(); penAFMotor.release(); //digitalWrite(enableRotMotor, HIGH); //digitalWrite(enablePenMotor, HIGH); motorsEnabled = 0; } ` void motorsOn() { //digitalWrite(enableRotMotor, LOW) ; //digitalWrite(enablePenMotor, LOW) ; motorsEnabled = 1; }`

But it not work correctly, I looking to AccelStepper, how it work and I think motor rotation need deeply change for adafruit motor shield because pin mode and func mod is very different

// 0 pin step function (ie for functional usage) void AccelStepper::step0(long step) { if (_speed > 0) _forward(); else _backward(); } in this case _speed >0 allways true (need remove abs)

// 1 pin step function (ie for stepper drivers) // This is passed the current step number (0 to 7) // Subclasses can override void AccelStepper::step1(long step) { // _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 ` }`

So, do you have any ideas?

krikz commented 8 years ago

It's ready in fork https://github.com/elhernes/EggDuino

twstdpear commented 8 years ago

I had the same question and was happy to see this issue come up. That fork seems to be missing "functions.h" that's critical to compiling it.

Johnwulp commented 8 years ago

@krikz, @twstdpear did you found the functions.h file somewhere?

mnelson78 commented 8 years ago

I commented out the line #include "functions.h" so it looks like //#include "functions.h" and it now compiles without any errors. I don't have the motorshield yet though so I can't try it. Can someone give it a try and let me know?

Johnwulp commented 8 years ago

@mnelson78 ok, it send and receive stuff, but with the motor shield my stepper motors acting funny. Im going to re-check my step per revolutions etc. They make a lot of noise, and almost don't turn

Johnwulp commented 8 years ago

@mnelson78 its finally printing. the resolution is crap, but it works.

Johnwulp commented 8 years ago

Check out my first test print on a plastic egg. Motors still make a lot of noise, i see that it is microstep related. if i switch to interleave the pen goes way to fast. Also still shocky >> https://www.youtube.com/watch?v=RYX1ItsFG3s

elbowdonkey commented 8 years ago

If you're using the original V1 motorshield from Adafruit you probably won't have much luck with microstepping. To get microstepping to work for the L293D drivers requires adding external DAC chips and various supporting circuitry.

I have a similar shield (the Osepp motor shield) and it really only works when you do single stepping.