NeoSteamLabs
Published © CC BY-SA

Project #12: Robotics - EasyDriver - Mk01

Arduino UNO, Display, EasyDriver, Stepper Motor, Etc...

IntermediateProtip1 hour2,705
Project #12: Robotics - EasyDriver - Mk01

Things used in this project

Hardware components

Adafruit RGB LCD Shield 16×2 Character Display
×1
Arduino UNO
Arduino UNO
×1
ProtoScrewShield
SparkFun ProtoScrewShield
×1
SparkFun EasyDriver - Stepper Motor Driver
×2
SparkFun Small Stepper Motor
×2
Pololu Mounting
×2
Adafruit Jumper Wires 3 M/M
×4
Adafruit Jumper Wires 6 M/M
×10
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
SparkFun Cerberus USB Cable - 6ft
SparkFun Cerberus USB Cable - 6ft
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Code

DL1911Mk04.ino

Arduino
// ***** Don Luc Electronics © *****
// Software Version Information
// Project #12: Robotics - EasyDriver - Mk01
// 11-04
// DL1911Mk04p.ino 12-01
// Arduino UNO
// Screw Shield
// Adafruit RGB LCD Shield
// 2 x Small Stepper Motor
// 2 x EasyDriver

// include the library code:
#include <Adafruit_RGBLCDShield.h>

// Adafruit RGB LCD Shield
Adafruit_RGBLCDShield RGBLCDShield = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

// Momentary Button
int yy = 0;
uint8_t momentaryButton = 0;

// 2 x EasyDriver
int dirPinR = 2;                           // EasyDriver Right
int stepPinR = 3;                          // stepPin Right
int dirPinL = 4;                           // EasyDriver Left
int stepPinL = 5;                          // stepPin Left
int i = 0;

void loop() {

  // Clear
  RGBLCDShield.clear();
   
  // Momentary Button
  momentaryButton = RGBLCDShield.readButtons();

  switch ( yy ) {
    case 1:
    
      // Up
      isSwitch1();
      
      break;
    case 2:
    
      // Down
      isSwitch2();
      
      break;
    case 3:

      // Right
      isSwitch3();
      
      break;
    case 4:

      // Left
      isSwitch4();
      
      break;
    case 5:

      // Stop
      isSwitch5();
      
      break;
    default:

      // Stop
      yy = 5;
      RGBLCDShield.setBacklight(RED);
      isSwitch5();

   }
   
   if ( momentaryButton ) {
    
    if ( momentaryButton & BUTTON_UP ) {
      
      yy = 1;
      // Up
      RGBLCDShield.setBacklight(GREEN);
      
    }
    
    if ( momentaryButton & BUTTON_DOWN ) {
      
      yy = 2;
      // Down
      RGBLCDShield.setBacklight(VIOLET);
      
    }
    
    if ( momentaryButton & BUTTON_LEFT ) {
      
      yy = 3;
      // Right
      RGBLCDShield.setBacklight(TEAL);
      
    }
    
    if ( momentaryButton & BUTTON_RIGHT ) {

      yy = 4;
      // Left
      RGBLCDShield.setBacklight(YELLOW);
    }
    
    if ( momentaryButton & BUTTON_SELECT ) {

      yy = 5;
      // Stop
      RGBLCDShield.setBacklight(RED);
   
    }
    
  }
  
}

getSwitch.ino

Arduino
// Switch
// Switch 1
void isSwitch1(){

   // Up
   yy = 1;

   // set the cursor to column 0, line 0
   RGBLCDShield.setCursor(0,0);
   RGBLCDShield.print("EasyDriver");        // EasyDriver  
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Up");

   // 2 x EasyDriver
   digitalWrite(dirPinR, LOW);              // Set the direction.
   delay(100);
   digitalWrite(dirPinL, LOW);              // Set the direction.
   delay(100);

   for (i = 0; i<1000; i++)                 // Iterate for 1000 microsteps.
   { 
     digitalWrite(stepPinR, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinR, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
     digitalWrite(stepPinL, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinL, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
   }  

}
// Switch 2
void isSwitch2(){

   // Down
   yy = 2;

   // set the cursor to column 0, line 0
   RGBLCDShield.setCursor(0,0);
   RGBLCDShield.print("EasyDriver");         // EasyDriver  
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Down");

   // 2 x EasyDriver
   digitalWrite(dirPinR, HIGH);              // Set the direction.
   delay(100);
   digitalWrite(dirPinL, HIGH);              // Set the direction.
   delay(100);

   for (i = 0; i<1000; i++)                 // Iterate for 1000 microsteps.
   {
     digitalWrite(stepPinR, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinR, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
     digitalWrite(stepPinL, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinL, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
   } 

}
// Switch 3
void isSwitch3(){

   // Right
   yy = 3;

   // set the cursor to column 0, line 0
   RGBLCDShield.setCursor(0,0);
   RGBLCDShield.print("EasyDriver");        // EasyDriver  
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Hight");

   // 2 x EasyDriver
   digitalWrite(dirPinR, LOW);               // Set the direction.
   delay(100);
   digitalWrite(dirPinL, HIGH);              // Set the direction.
   delay(100);

   for (i = 0; i<1000; i++)                 // Iterate for 1000 microsteps.
   {
     digitalWrite(stepPinR, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinR, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
     digitalWrite(stepPinL, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinL, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
   }    
  
}
// Switch 4
void isSwitch4(){

   // Left
   yy = 4;

   // set the cursor to column 0, line 0
   RGBLCDShield.setCursor(0,0);
   RGBLCDShield.print("EasyDriver");        // EasyDriver  
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Left");

   // 2 x EasyDriver
   digitalWrite(dirPinR, HIGH);             // Set the direction.
   delay(100);
   digitalWrite(dirPinL, LOW);              // Set the direction.
   delay(100);

   for (i = 0; i<1000; i++)                 // Iterate for 1000 microsteps.
   {
     digitalWrite(stepPinR, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinR, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
     digitalWrite(stepPinL, LOW);           // This LOW to HIGH change is what creates the
     digitalWrite(stepPinL, HIGH);          // "Rising Edge" so the easydriver knows to when to step.
     delayMicroseconds(170);                // This delay time is close to top speed.
   }    
    
}
// Switch 5
void isSwitch5(){

   // Stop
   yy = 5;

   // set the cursor to column 0, line 0
   RGBLCDShield.setCursor(0,0);
   RGBLCDShield.print("EasyDriver");        // EasyDriver  
   RGBLCDShield.setCursor(0,1);    
   RGBLCDShield.print("Stop");

   delay( 1000 );

   // 2 x EasyDriver
   digitalWrite(dirPinR, LOW);              // Set the direction.
   delay(100);
   digitalWrite(dirPinL, LOW);              // Set the direction.
   delay(100);
   digitalWrite(stepPinR, LOW);             // This LOW to HIGH change is what creates the
   digitalWrite(stepPinL, LOW);             // This LOW to HIGH change is what creates the 
    
}

setup.ino

Arduino
// Setup
void setup() {

  // Adafruit RGB LCD Shield
  // Set up the LCD's number of columns and rows: 
  RGBLCDShield.begin(16, 2);
  RGBLCDShield.setBacklight(GREEN);
  
  // Display
  // Set the cursor to column 0, line 0  
  RGBLCDShield.setCursor(0,0);  
  RGBLCDShield.print("Don Luc Electron");         // Don luc Electron
  // Set the cursor to column 0, line 1
  RGBLCDShield.setCursor(0, 1);
  RGBLCDShield.print("EasyDriver");               // EasyDriver

  delay(5000);

  // Clear
  RGBLCDShield.clear();

  // 2 x EasyDriver
  pinMode(dirPinR, OUTPUT);
  pinMode(stepPinR, OUTPUT);
  pinMode(dirPinL, OUTPUT);
  pinMode(stepPinL, OUTPUT);

}

Credits

NeoSteamLabs

NeoSteamLabs

30 projects • 12 followers
IT consultant with over 36 years of experience Instructor: Arduino, Raspberry Pi, Espressif, Robotics, Unmanned Vehicles, etc...

Comments