Spark Core + AccelStepper Library problems

Hey.

I’m using the AccelStepper library to control my stepper motors and I notice some strange behavior.
When using the SparkCore and the Arduino without the AccelStepper library. Everything works fine like it is shown in this video:

When I use the Accelstepper Library the Spark Core is driving the motor really slow and not like expected:

You can see a real different behavior when compared to the Arduino setup altough they’re using the same code!
Any ideas?

Can you paste the link to the library? It might be the one i ported so i can take a look. :wink:

Hey!

The website was down for 2 days and came online just now. Here is an updated version from today (25.08.2015) http://www.airspayce.com/mikem/arduino/AccelStepper/

It would be awesome when you take a look! :slight_smile:

@newclear,

the improved library doesn’t look that complicated. Can you share with me how you compiled with the library for the Spark core?

if you have the code uploaded somewhere i can take a look too :wink:

Hey, do you mean the code that I was using?

You can find it here:
http://pastebin.com/4sdVWgpx

Ok so one difference between a Particle device and an Arduino device is that there are background processing ( :cloud: stuff) running at the background. That should match up with the “slowness” you observed.

Can you try adding SYSTEM_MODE(MANUAL); at the top to disable the :cloud: stuff and see if things are working like you would expect?

Well, it seems like it worked. Now when I use the AccelStepper library in fullstep mode, they are totally in sync! I need to try it when they use microstepping! …but the problem is, now they I’ve added SYSTEM_MODE(MANUAL); my Spark won’t connect to the wifi anymore. When I power the spark it is just breathing cyan. It doesnt look for wifi, no green blinking, no handshake… just breathing :frowning:

EDIT
Okay, I’ve read this artcile http://blog.particle.io/2014/08/06/control-the-connection/ and learned, that I have to connect my spark manually to the cloud. But I’m confused that If I don’t do this, that I cannot sync my spark through wifi anymore :o

Well, how do I need to change the code so the I can call Spark.process() at the least amount of time. What interval makes sense here?

So the library is working well? That’s good to know! Let me see how we can modify the code to do just that.

Yes it works perfectly now. I have to do a Factory reset after each Code adjustment. Kinda annoying but it works. If you can figure out a way that it works with System Mode AUTOMATIC or give me support on how to implement Spark.connect() that would be super awesome!!! :)))

Why is a factory reset required? I’m looking at some flag what we can use to know that the stepper has moved to the position before letting loop() iterate.

There are several ways (more and less verbose) to connect and there are multiple threads that show how to code it.

One way is shown here
Photon/P1 loop()/user code blocking in SEMI_AUTOMATIC mode

For your purpose to only connect for OTA flashing, you might want to put the connection logic into a function and trigger that fn via a button.

Well, thanks for all this help!

But in the long run, I want to control my steppers via a Webinterface to change its speed. How is this compatible with setting the SYSTEM MODE to Manual, since I require a steady wifi connection?

Which Library makes sense for this kind of project? Is it the HttpClient library?

@newclear, I had a good look at the AccelStepper library. It was clearly written for a platform that is dedicated to the stepper task. This is because all timing is done in software with no hardware interrupts (using a timer for example). This is why it will NOT work properly when anything injects a timing skew (ie WiFi and Cloud servicing). This is a known limitation of the AccelStepper code. Using timer interrupts has been tried by others (eg. on Teensy 3) with varying success. If you can find a suitable timer interrupt-driven stepper arduino library, I may be able to port it for you.

I suggest that if you want to use the AccelStepper library, you accept the fact that you cannot be connected to the Particle Cloud at the same time. You may be able to have wifi connected since it requires much less overhead. So stepping and connecting need to be mutually exclusive.

Another approach is to use a stepper controller breakout like these:



These boards do all the timing work, allowing the Core/Photon to do what you are looking for. :grinning:

Well I am using a driver for my stepper motor, which is the Pololu DRV8825. This is (amongst the members of the arduino forum) a state of the art driver…

Hm, but I guess I can give up on the AccelStepper library :frowning:

Hi @newclear

The Pololu DRV8825 uses a “smart” stepper motor controller so you don’t have to use a library like AccellStepper which is designed for a “dumb” motor driver.

The DRV8825 is really simple to use with step and direction inputs that you drive at 250kHz or less.

There is sample code here:

http://www.geeetech.com/wiki/index.php/DRV8825_Motor_Driver_Board#Arduino_Example_Code

1 Like

Hi,

Am am looking at the same problem, as accelstepper library is actually pretty useful when you have a large mass but also want some speed.
The main advantage of that library is the acceleration part. My motor has to move a pretty big gear. If I try to do it without acceleration I have to do it at low speed or it won’t have sufficient torque. The library has an acceleration function, which lets you build the speed up/down. This way you can achieve high speeds without skipping any steps (if you’re careful).
Right now my stepper motor can go between 20 -50 times faster with acceleration. if you only have to do 10-20 steps that is nothing, but if you have 2000 -5000 steps that is ok.
If anyone is curious, it is connected to a worm gear that is supposed to lift 5kg :slight_smile:
I’ve just ordered my photon but I basically want to do something similar. Control the position of the stepper from the internet.
I can move the stepper with the arduino no problem, but I want to be able to update the firmware remotely and also control it remotely.
Thanks and sorry for bumping an old thread but this suites exactly my needs :smile:

nobody has any alternatives to this? :frowning:

What exactly is your problem that is not already discussed in this thread?

Saying this, would read for me as: *"I haven't got my device yet, so I haven't actually been able to test it", but how would you then know whether you actually are looking at the same problem?

because I am looking into using the same library as the author. and here it was mentioned that the library is blocking.
I finally had a good look at the library, and while it has functions that are blocking (and are mentioned in the documentation that they block).
There are functions: run()/runspeed() that do not block, and every time they get called they pull the library to check if a step is due or not. So in a long program you should pull it as often as possible/needed but at least once in the main loop.

Hi, well the accelstepper is using non-blocking soft delays utilizing millis(). However my problem was that I was achieving rather LOW speeds with the core/photon. The solution was using the MANUAL system mode, canceling the permanent connection to the particle cloud, which slows the core/photon extremely down… so this is something you want to try aswell, when you are aiming for very fast speeds, since the speed is dependent how often the run() function can be called.

Just to please my curiosity, which Stepper motor and which driver are you using?