gStepper - a simple Stepper Motor Controller (... or Telescope Focuser ...)

This describes a little project to build a simple and 
multipurpose Stepper Motor controller based on an Arduino, a stepper driver and a Bluetooth transceiver, all cheap and easy to build. The original purpose was mainly to make a simple electronical assisted focuser for astronomical instrument, controlled by the PC via Bluetooth and also as a stand-alone handheld device. I already build a focuser some time ago, the MyFocuserPro2 by Robert Brown, but it was overblown with respect to my target and somewhat difficult regarding utilisation.  So, here is my simple GStepper controller.

The Electronics

Main components


The idea was to build a device with the following features:
  1. handheld as a stand-alone controller or
  2. remote and wireless controlled from the PC/laptop and
  3. configurable, on the basis of various user and hardware (stepper motor) needs/characteristics
Two stage activation levers.
I decided to use lever micro switches as motion button because they can be easily mounted side by side and, if the levers are long enough, the actuator levers 
extremities are partially overlapping so it is possible to activate them in sequence by only pressing the top one (image at left).
I wanted to build a controller able to drive a stepper motor at three different speeds, in both directions so, togheter with the previously mentioned lever switches pairs, I added a third button (placed in the center) to activate the third speed. So, if you press one of the paired lever slightly you drive the stepper at first speed and if you press the same lever more deeply you'll have the stepper moving at the second speed. Finally and optionally, pressing the center lever while the first is completely pressed will activate the stepper at third speed value.


The PCB was designed in Fritzing, exported as Gerber files and manufactured by EasyEDA online PCB service (fast and cheap, picture at right). Gerber files are available at the bottom of this page (v1.1, slightly optimized with respect to the shown here v1).

Basically, the sequence of operations to perform in order to have the stepper controller fully functional is the following:
  1. Install the TclTk interpreter (optional, if don't want want to use the stand-alone executable, see section below) 
  2. Upload the firmware (see section below for instructions) in the Pro Mini board using the Arduino IDE
  3. Configure the Arduino pins' assignment using the TclTk application
  4. Place the Pro Mini board into the controller
  5. Run the TclTk application and use it to connect, configure and test the controller's features
  6. Close the TclTk application and try the controller as stand alone (or continue with the TclTk app as remote controller)

 

Prototype's gallery

 

Final controller's gallery



The software

Arduino code

I'm not an expert programmer so if you want to correct/optimize/implement my code, feel free to do any changes but please, send me an email if you like, thanks.
The code is written with the board hardware in mind as you can see it in the previous chapter. There are several loop's controls on the available buttons actions to (almost) ensure that the stepper motor is activated and used as smooth as possible and with great precision. 
Upload the EEPROM init script (gStepper_EEPROM-init folder), before uploading the main firmware (gStepper folder), in order to configure the Arduino's EEPROM correctly (see 'Basic steps' list below).
The main limitation is the number and usage sequence of the motion buttons. You have to build the board with five buttons and four of them (two pais) have to be physically (mechanical) linked togheter, as shown in the 'hardware' chapter above.

The Arduino code is available for download at the bottom of this page.

/*////////////////////////////////////////////////////////////////////////////////////////////////////////
//  gStepper                                                                                            //
//                                                                                                      //
//  A sketch to drive an Arduino based Stepper motor controller via serial comm.                        //
//  CODE CREDIT: http://reallysmall.github.io/Stackduino/                                               //
//  (gStepper) Code by GigiG, May 2017                                                                  //
//                                                                                                      //
//  KEY HARDWARE:                                                                                       //
//  Arduino Nano/Uno/ProMini (ATMega328)                                                                //
//  EasyDriver/A4988/DRV8825 stepper driver                                                             //
//  Bipolar stepper motor                                                                               //
//                                                                                                      //
//  Arduino pushbuttons wiring: https://www.arduino.cc/en/tutorial/pushbutton                           //
////////////////////////////////////////////////////////////////////////////////////////////////////////*/

#include <EEPROM.h>

/*////////////////////////////////////////////////////////////////////////////////////////////////////////
//  ARDUINO PIN DEFINITION (see pinsInit func for assignment)                                           //
////////////////////////////////////////////////////////////////////////////////////////////////////////*/

int pin_step;
int pin_dir;
int pin_enable;
int pin_MS1;
int pin_MS2;
int pin_MS3;
int pin_SW1; // pushbutton v1 fwd
int pin_SW2; // pushbutton v2 fwd (follow SW1)
int pin_SW3; // pushbutton v1 bwd
int pin_SW4; // pushbutton v2 bwd (follow SW3)
int pin_SW5; // pushbutton v3 fwd/bwd (follow SW2/SW4)
...
...

Basic steps (Arduino)
  1. run the Arduino IDE by double clicking on the gStepper_EEPROM-init.ino file (gStepper_EEPROM-init folder)
  2. open the Arduino's Serial Monitor
  3. upload the code as usual by clicking on Upload, the script will configure the board's EEPROM using gStepper defaults values
  4. open the gStepper.ino file (gStepper folder) in the Arduino IDE and upload
  5. close the Serial Monitor
  6. run the TclTk application (see below)
  7. connect the board, configure the Arduino pins (Menu>Configure) and save in EEPROM (Configure window, Apply and save)
  8. disconnect the board, close the TclTk and mount the Arduino module in your gStepper controller board
The Arduino code is available for download at the bottom of this page.

TclTk application

https://picasaweb.google.com/110161483001058852427/6461117704164574881#6467162204909812194

I wrote a small TclTk application which allow to connect the gStepper controller device with the PC via Bluetooth (HC-06 module).
Once connected, the user can test the stepper motor, configure the controller, store the parameters in the Arduino's EEPROM and eventually using files on the PC.
The main commands are available on the left pane while on the right is the Log (messages) window. There is a scale widget (motion jog, at the top of the GUI, below the 'Menu' button) and six buttons for stepper motion operations. Sliding the scale widget to the left or to the right will allow you to start the stepper rotation for each of the predefined and configured speed values (same action by pressing the 1, 2 and 3 buttons). Three grey menubuttons (microsteps) allow the selection of the microstepping value for each speed (depends on the type of stepper driver you are using). The steps delay fields sets the delay in microseconds that Arduino uses to change the speed of rotation of the stepper motor (actually is the delay between each single step of the motor), the higher is this value the slower is the rotation speed. Set the delay values with the spinbuttons or the scales placed below the value fields.

Now click on the yellow select field. A list of the available COM ports will appear then choose the one that is linked to your HC-06 module.
Once the connection is established, the field becomes green and some messages will be written in the log window. Here below is the common messages that will be presented when the controller has been correctly configured.

To disconnect, click again on the (now green) field and select Disconnect.




If this is the first time you use the controller, the on board Arduino Pro Mini is not yet configured and its EEPROM is void, so the following message will appear.
You can now test the controller, set values and store them in the Arduino EEPROM.









Now take a look at the Menu.

The Configure window allow you to set the limits of the three speed delays scales and the Arduino pins assignment. Depending on the board you built, you can re-assign pins to the related functions. The available Arduino pins are digital pin 2 to digital pin 12 and the functions that can be associated are the five hardware switches of the board and the ENABLE, STEP, DIR, togheter with the three microstepping pins of the driver (MS1, MS2, MS3)














There are several options available in the Menu. Disable stepper driver, if active, will power off the motor during stand-by or any other situation when the motor is not moving, in order to save power and reduce vibrations. Enable internal LED allow the Arduino LED (pin 13) to turn on and off with respect to motor commands.


Stepper driver type
lists the three supported driver modules (DRV8825, A4988 and EasyDriver) so the microsteps settings will takes into account the corresponding board's pins. The DRV8825 allow up to 32 microsteps while the A4988 up to 16 and the EasyDriver up to 8.
Under Parameters you will find several options to manage parameter files (save and load), load defaults value as well as current values stored in Arduino EEPROM.
The Acceleration delay is a time delay (in milliseconds) used between each speed change encountered during motion buttons actions so that, for example, if you press the button labeled with 3 and the Acceleration delay is 200, the stepper will rotate at speed 1 for 0.2s then at speed 2 for further 0.2s and finally at speed 3 until you release the button.


Basic steps (TclTk application)
  1. run the TclTk application
  2. connect the Arduino using the HC-06 COM port
  3. check the Arduino pins in Configure Window
  4. check/set the microstepping values for each of the three speeds (test the stepper motor)
  5. check/set the desired speeds values (modifying steps delay and test the stepper motor)
  6. Save in EEPROM
Done. Now you are ready to use the controller as stand alone device as well as wirelessly with the PC.

The TclTk code is available for download at the bottom of this page. You need to install the Tcl interpreter, available for free here.
If you don't want to install the interpreter, a standalone wrapped executable for Windows (built with freeWrap) is also available here below.



January 2018

ċ
gStepper.zip
(6k)
Gigi Giorgi,
Feb 7, 2018, 3:27 AM
ċ
gStepper05d5-v1.1-gerber.zip
(119k)
Gigi Giorgi,
Feb 7, 2018, 10:00 AM
ċ
gStepper_EEPROM-init.zip
(2k)
Gigi Giorgi,
Feb 7, 2018, 3:27 AM
ċ
gStepper_TclTk_exe.zip
(6511k)
Gigi Giorgi,
Feb 7, 2018, 3:29 AM
ċ
gStepper_TclTk_src.zip
(18k)
Gigi Giorgi,
Apr 16, 2018, 3:10 AM