The Freetronics StepDuino is Arduino Uno compatible, uses the ATmega328P Microcontroller and works with most Arduino software. The StepDuino can be powered automatically by the USB connection or powered separately by your project via the DC jack, which also provides power to any connected stepper motors.




Software installation

1. Download the latest Arduino IDE for your operating system from www.arduino.cc/en/Main/Software and install it to suit. You'll also find more step-by-step guides for installation here: www.arduino.cc/en/Guide/HomePage

Windows users please note: The USB driver for the StepDuino must be downloaded and used for first-time installation of the StepDuino's USB port: www.freetronics.com/usbdriver

2. Once the Arduino IDE is installed, we're ready to do the initial board and port setup. You won't need to do this again unless the serial port number changes such as when using a different USB port on your computer.

3. In the Arduino IDE, select Tools > Board > Arduino Uno.

4. Before connecting your StepDuino to the USB port, have a look at the list of ports in Tools > Serial Port. That's where your StepDuino serial port is going to appear when you plug it in.

5. Connect your StepDuino to the computer USB port. We supply an appropriate USB cable with the StepDuino. After a short while if you look at Tools > Serial Port again you'll see a new port appear: that's the StepDuino ready to be used. Select that port now with Tools > Serial Port so there is a tick mark next to it

6. You're ready to go. The Arduino IDE now knows about your board and has a connection to it.

Compiling and uploading a sketch to the StepDuino

"Sketch" is the Arduino term for a program. To test uploading a simple sketch to your StepDuino:

1. Choose File > Examples > 01.Basics > AnalogReadSerial. You'll see the code open in the IDE.

2. Select Sketch > Verify/Compile, you've now built (compiled) the program ready to be loaded.

3. Lastly, to load the program into the StepDuino, select File > Upload to I/O Board. You'll see the red D13 LED flicker as the board is reset, then the green and yellow RX and TX LEDs will flash while the upload is in being done.

4. A few seconds later the RX and TX LEDs will go off, the board will reset, and the TX LED will appear to be on constantly.

5. In the IDE, select Tools > Serial Monitor. A new window will open. Check that the speed drop-down in the bottom right of the window is set to "9600 baud". You will then see a stream of numbers down the window showing readings from the analog inputs on the StepDuino.

Congratulations! You've now compiled and uploaded your first sketch to the StepDuino.

Using the microSD card slot

The microSD card slot is supported by a variety of libraries that implement different versions of the FAT filesystem commonly used on microSD cards. The Arduino IDE comes bundled with the "SD" library pre-installed including some example sketches, so look in File > Examples > SD to see how to communicate with a microSD card.

Note: the "select" line for the microSD slot on the StepDuino is D9, which is different to the examples bundled with the IDE. Ensure you change the select line setting in the sketch to pin 9.

Using the stepper motor outputs

Stepper motors do not simply spin like most motors you may be familiar with. They move in a series of steps (hence the name) with a defined angle of rotation per step. Stepper motors can be specified as having a certain number of steps per rotation, or as a number of degrees of rotation per step. Both numbers are just different ways of stating the same thing. For example, a typical hobby stepper motor may be said to have "200 steps/rev" (steps per revolution), or "1.8º/step" (degrees per step) which are really the same thing.

So if you drive a 200 steps/rev (or 1.8º/step) motor through 200 steps, it will rotate a complete 360º back to where it started.

Microstepping Settings

Stepper motors are specified in terms of how many steps they take per revolution, but a technique called "microstepping" allows controllers to drive motors in smaller increments. The StepDuino supports four levels or increments of microstepping: full-step, 1/2-step, 1/4-step, and 1/8-step. The default configuration is 1/8-step, which is set by leaving the pairs of solder bridges on the back of the PCB unconnected. That means you need to send 8 times as many step pulses as you may expect based on the specs of your motor, but it also gives you much finer control of the rotation of the motor.

You can adjust the microstep settings for both outputs independently by applying solder bridges across the positions labelled "MS0" and "MS1" for the relevant output.

MS0 MS1 Setting
Open Open 1/8 step (default)
Closed Open 1/4 step
Open Closed 1/2 step
Closed Closed  Full step

Motor Connections

The StepDuino has two independent 4-wire bipolar stepper motor outputs. Each output (labelled "STEPPER 1" and "STEPPER 2" on the PCB) uses two control lines: one line to determine the direction of rotation of the stepper motor, and one to trigger a step of the motor.

  • Stepper 1 direction: Arduino digital pin 2.
  • Stepper 1 step: Arduino digital pin 5.
  • Stepper 2 direction: Arduino digital pin 3.
  • Stepper 2 step: Arduino digital pin 6.

These assignments are also printed on the bottom of the StepDuino in case you need to look them up.

To connect your 4-wire bipolar stepper motor, you first need to determine the coil connections using the datasheet of your particular motor. The very common NEMA-17 stepper motors used in many hobby projects such as 3D printers can generally be connected using the colour codes as shown below, using (left to right) red, green, yellow, blue:

 

Otherwise, the general coil wiring for your stepper should match this (there should be a similar diagram in the datasheet for your stepper):

 

 

 

Stepper motors cannot be powered from the USB port because they generally require a higher voltage and more current than USB can provide. Connect an external power source suitable for your stepper motors (often 12Vdc) to the DC IN jack in the top left of your StepDuino as shown above.

Example Sketch

The example sketch below sets up the output pins for both Stepper 1 and Stepper 2, and then drives the Stepper 1 channel through a total of 1600 steps (ie: one complete rotation for a 200 steps/rev motor using 1/8th microstepping: 200 x 8 = 1600) then pauses for one second, then does the same thing in reverse, then repeats. You'll see in the sketch there are also unused example functions for running Stepper 2 forward and for "braking" both motors so the controller holds them in place and resists rotation.

 

/**
 * StepDuino example
 */

const int Stepper1Step      = 5;
const int Stepper1Direction = 2;
const int StepsPerRev1      = 1600;

const int Stepper2Step      = 6;
const int Stepper2Direction = 3;
const int StepsPerRev2      = 1600;

/**
 * Set pin assignments
 */
void setup() {
  pinMode(Stepper1Step,      OUTPUT);
  pinMode(Stepper1Direction, OUTPUT);
  
  pinMode(Stepper2Step,      OUTPUT);
  pinMode(Stepper2Direction, OUTPUT);
}

/**
 * Main loop
 */
void loop() {
  for(int i = 0; i < StepsPerRev1; i++)
  {
    stepper1Forward();
  }
  delay( 1000 );
  
  for(int i = 0; i < StepsPerRev1; i++)
  {
    stepper1Reverse();
  }
  delay( 1000 );
}

/**
 * Rotate stepper 1 forward by 1 step
 */
void stepper1Forward()
{
  digitalWrite(Stepper1Direction, HIGH);
  digitalWrite(Stepper1Step, HIGH);
  delayMicroseconds(2); // 1uS minimum pulse duration for DRV8811
  digitalWrite(Stepper1Step, LOW);
  delayMicroseconds(100);
}

/**
 * Rotate stepper 1 backwards by 1 step
 */
void stepper1Reverse()
{
  digitalWrite(Stepper1Direction, LOW);
  digitalWrite(Stepper1Step, HIGH);
  delayMicroseconds(2);
  digitalWrite(Stepper1Step, LOW);
  delayMicroseconds(100);
}

/**
 * Rotate stepper 1 forward by 1 step
 */
void stepper2Forward()
{
  digitalWrite(Stepper2Direction, HIGH);
  digitalWrite(Stepper2Step, HIGH);
  delayMicroseconds(2); // 1uS minimum pulse duration for DRV8811
  digitalWrite(Stepper2Step, LOW);
  delayMicroseconds(100);
}

/**
 * Lock both steppers in place
 */
void applyBrakes()
{
  digitalWrite(Stepper1Direction, LOW);
  digitalWrite(Stepper1Step, LOW);
  digitalWrite(Stepper2Direction, LOW);
  digitalWrite(Stepper2Step, LOW);
  delayMicroseconds(50);
} 

Using the servo outputs

A servo is a device that contains a small electric motor that can be commanded to rotate to a specific angular position. For example you might use a servo to move the part of a robotic arm, or lift a stylus from a two-axis plotter. Your StepDuino easily allows for the connection of two servos at the same time.

To connect your servos, observe the colour of the wires between the servo and end plug. The darkest wire will match the GND pin on the SERVO port of your StepDuino, as shown in the example image below:

However if you are unsure, check with the supplier of the servo to ascertain which wire is GND, 5V and signal. Controlling your servos is equally simple, and the Servo library included by default with the Arduino IDE will suffice. Consider the following sketch:

#include <Servo.h> 
 
Servo left; // assign objects to the Servo library
Servo right;

int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  left.attach(10);  // one servo connected to D10 
  right.attach(11); // the other to D11
} 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  
 // goes from 0 degrees to 180 degrees in steps of 1 degree 
  {
   // tell servos to go to position in variable 'pos' 
    left.write(pos);               
    right.write(pos);
   // wait 15ms for the servos to reach the position
    delay(15);                        
  } 
  for(pos = 180; pos>=1; pos-=1)    
  // and reverse
  {                                
    left.write(pos);                
    right.write(pos);
    delay(15);                      
  } 
} 
This will sweep both servos across a 180 degree range and back again. Once the two servos have been activated in lines two and three, and assigned to the StepDuino's digital output pins for servos - you can simply use the required .write function to control each servo. 

Using the LCD

The 20x4 LCD is controlled using a shift register, which saves some I/O pins on the microcontroller and allows them to be used for other purposes. This means the regular LiquidCrystal library included with the Arduino IDE can't drive it directly, so you need to use Marc Merlin's version of the "NewLiquidCrystal" library.

To do so, visit github.com/marcmerlin/NewLiquidCrystal and click the "Download ZIP" button on the right-hand side of the page. Once the .zip file has completed downloading, open the .zip file and copy the folder labelled "NewLiquidCrystal-master" into your Arduino IDE libraries folder. Finally, rename the folder to "NewLiquidCrystal". For detailed instructions on library installation please see our tutorial "How To Install Arduino Libraries".

Once you have the library installed and your IDE has been restarted, create a new sketch and paste the following code into it:

 

/**
 * Demo of writing to the StepDuino LCD
 */
#include <Wire.h>
#include <LiquidCrystal_SR_LCD3.h>

const int PIN_LCD_STROBE         =  4;  // Out: LCD IC4094 shift-register strobe
const int PIN_LCD_DATA           =  7;  // Out: LCD IC4094 shift-register data
const int PIN_LCD_CLOCK          =  8;  // Out: LCD IC4094 shift-register clock

LiquidCrystal_SR_LCD3 lcd(PIN_LCD_DATA, PIN_LCD_CLOCK, PIN_LCD_STROBE);

/**
 * Setup routine. Run once
 */
void setup(){
    lcd.begin( 20, 4 );               // Initialize the LCD 
    lcd.home ();                      // Go to the home location
    lcd.setCursor (0, 0);
    lcd.print(F("** Stepduino v1.1 **"));  
    lcd.setCursor (0, 1);
    lcd.print(F("Dual channel stepper"));
    lcd.setCursor (0, 2);
    lcd.print(F("motor +servo outputs"));
    lcd.setCursor (0, 3);
    lcd.print(F(" freetronics.com/sd"));
    delay( 2000 );
    lcd.setCursor( 0, 3 );
    lcd.print(F("                    "));
}

/**
 * Main loop. Run indefinitely
 */
void loop()
{
  // Set the cursor to column 0, line 1
  // (Note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 3);
  // Display the number of seconds since reset:
  lcd.print(millis()/1000);
}

Specifications

Microcontroller
MCU Type Atmel ATmega328P
Operating Voltage 5V
MCU Clock Speed 16 MHz
StepDuino
Input Voltage 7-28V DC recommended
5-40V DC maximum
Digital I/O pins 14 (6 provide PWM output)
Analog Input Pins 8 (analog input pins also support digital I/O,
giving 22 digital I/O total if required)
Analog Resolution 10 bits, 0-1023 at 5V AREF is approx 0.00488V; 4.88mV per step
Current Per I/O Pin 40 mA maximum
Total Current For All I/O Pins 200mA maximum
Current For 3.3V Output 50mA maximum
Memory
Flash Memory 32 KB Flash Memory, of which less than 1 KB is used by bootloader
SRAM, EEPROM 2 KB SRAM, 1 KB EEPROM
microSD microSD card slot with SPI interface. Uses pins D4 (select), D11, D12, D13
Communications
Serial 1 x hardware USART, SPI (Serial Peripheral Interface), I2C
Stepper Outputs 2 x Texas Instruments DRV8811 4-wire stepper motor controllers
Servo Outputs 2 x digital I/O pins broken out with GND and 5V connections to suit hobby servos
Display HD44780-compatible 20x4 backlit LCD with 3-wire shift register interface
Other Integrated USB programming and communication port. Many other one-wire, multi-wire, LCD and expansion devices supported by free code and libraries