Anth's Computer Cave

AAIMI GPIO Tutorial Hub

AAIMI GPIO is a web-based control interface for the Raspberry Pi and Arduino. Check out the tutorials below.

AAIMI GPIO Stepper Motor

23rd November 2017

In this article I'll show you how to configure and control a 360 degree stepper motor with your Raspberry Pi using the AAIMI GPIO system.

Stepper motor basics

I've covered using stepper motors in other articles in the Cave. They are basically a motor that take a set amount of steps to turn a full rotation, meaning the controller can know exactly where the motor is at all times.

An assortment of stepper motors. Picture: Anthony Hartup

There is an article on identifying and using salvaged printer stepper motors that shows you how to wire and operate bi-polar steppers with an Arduino.

I also have an article on a 360 degree rotating sensor mast that uses a stepper motor controlled by a Raspberry Pi and Python.

Those two articles should tell you all you need to know about connecting your stepper and motor controller, so I'll only briefly cover the connection details here.


This is an example of a 4-wire stepper motor connected.

A wiring diagram to connect a stepper motor to a Raspberry Pi. Picture: Anthony Hartup

The first pair of motor wires go to OUT1 and OUT2 on the motor controller, and the second pair to OUT3 and OUT4. The signal wires connect to pins 18, 23, 24, and 8.

Configure pins

You configure the motor by pressing the button for the first motor pin in the AAIMI GPIO configuration window and clicking Change Setting.

The initial pin form will load.

Configuring a stepper motor with AAIMI GPIO. Picture: Anthony Hartup

I'll call my motor steppy and select Stepper Motor from the drop-down pin-type menu, then click Next.

In the Output Options section I've set the default state Low, or off, and chosen to manually switch the motor.

Configuring a stepper motor with AAIMI GPIO. Picture: Anthony Hartup

I've then entered the three other motor pin numbers.

In the Position section I've entered zero, which means the motor will face twelve o'clock or directly ahead.

Configuring a stepper motor with AAIMI GPIO. Picture: Anthony Hartup

I've entered -90 and 90 as the left and right stops, which equates to nine o'clock and three o'clock. These are the stopping positions if you set the motor to automatically oscillate.

In the rotation section I've set the pause btween steps (the speed of the motor) to six milliseconds. That seems to work best with small ebay stepper motors, you may need to adjust it for others. Lower is faster.

Configuring a stepper motor with AAIMI GPIO. Picture: Anthony Hartup

The multiplier value is to convert the steps of the motor into degrees of rotation. With the 40-28 gear ratio I have on my sensor mast I actually have exactly 360 full steps per rotation (Really lucky!), so I leave the multiplier as 1.0. You'll need to experiment to get you ratio right.

Lastly, select whether you wish to move the motor manually to position or set it to automatically oscillate when it is turned on. You can also overide this and start the motor oscillating from the control GUI.

I selected Move to position.

Click Next, then Back to return to the main configuration window.

You'll see your first motor pin is now in the default output color.

Run the motor

Now click the Run tab and you'll see your motor in the Control window. Click on the motor then click Change.

The motor-control window will open.

The stepper motor control center in AAIMI GPIO. Picture: Anthony Hartup

There are left, center, and right buttons to quickly move your motor to the stops you defined during setup. Below those is a slider to turn the motor anywhere from -180 to 180 degrees.

The motor will never turn more than 360 degrees. This is to stop damage to wires when you have another device rotating with the motor, such as the distance sensor that sits atop my mast.

To start the motor oscillating, click the Oscillate button. Click the button again to stop oiscillating, and the motor will return to its default position, in my case center.


In the next article we'll configure AAIMI GPIO to send email and HTTP notifications for pin events.



Previous: AAIMI GPIO PWM motors and leds

Next:Get notifications for pin events



Leave a comment on this article

Leave a comment on this article