# Accelstepper

For work I’ve been designing a 5 axis laser cutter and since all machines deserve a name I deemed the machine to be called The Mighty Max Its from one of those shows I used to watch and buy toys from as a child where I’m not sure if the accompanying toys came before or after the show. Anyways. We’ve basically completely finished the C axis…which is the rotational axis around the Z axis in a Cartesian coordinate system like so:

And we’d like to start testing initial designs to ensure we’ve actually got something going on here. So I decided to break out the arduino and some other little hardware bits to see if I can get something going and here’s my experience doing it.

So like a good little science person, one should have an idea to follow.

What do we want to do?

• Test stepper motors
• Count steps
• be able to send requests for steps
• Adjust speed and or acceleration
• must be usable with any kind of step/dir driver

So the easiest way to do any of this is really using an arduino and someone elses stepper library. Which thankfully one exists! The Accelstepper library which supports all sorts of banana things, but most interestingly is that it right off the bat crosses off three things off the wanted list.

• Test stepper motors
• Count steps
• be able to send requests for steps
• Adjust speed and or acceleration
• must be usable with any kind of step/dir driver

The other two things I want are just arduino things. I have an arduino M0 at home, which is a 32bit Uno shape/style board

So those are gone to.

This is my code for the arduino m0…We include the Accelstepper library set it’s max speed, accel and set the serial speed aswell (since the m0 is so super fast, we can easily afford to bump the baudrate…

```#include AccelStepper.h; // Define a stepper and the pins it will use AccelStepper stepper(1, 9, 8); long steps = 0; void setup() { stepper.setMaxSpeed(51200); //steps per second stepper.setAcceleration(8000); // stepper.setSpeed(9600); SerialUSB.begin(115200); } void loop() { if (SerialUSB.available() > 0) { steps = SerialUSB.parseInt(); SerialUSB.println(steps); stepper.moveTo(steps); while (stepper.distanceToGo() != 0) { // Serial.println(stepper.currentPosition()); stepper.run(); } } //Serial.write("hello"); }```

This will let me with arduinos Serial monitor in the IDE send a command at how many steps I want to move in one direction or another, count them, move with accel in that direction and then let me go back to 0 and hopefully go back to its original position. (it does)

Here’s a video and some pictures on the breadboard