Things used in this project

Custom parts and enclosures

fty8akaivo3t4x1_u1xz65PyoT.dxf
Coral Draw Vector
fzuawwrivo3t4wz_PdKRLpvu3f.cdr

Schematics

Schematic 1
Fyjwhj4ivo4a8r7 large omvsql1ikq

Code

code.inoC/C++
/*
 * Simple demo, should work with any driver board
 *
 * Connect STEP, DIR as indicated
 *
 * Copyright (C)2015 Laurentiu Badea
 *
 * This file may be redistributed under the terms of the MIT license.
 * A copy of this license has been included with this distribution in the file LICENSE.
 */
 /*
  * Edited as found from the StepperDriver library by Ernest E Garner
  * Date: 20-Nov-2016
  * 
  * Code Description:
  *    Used to control a basic x/y gantry for the zen table created by Ernest James Garner for Instructables.com
  */
#include <Arduino.h>
#include "BasicStepperDriver.h"

//#define DEBUG

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define X_MOTOR_STEPS 200
#define Y_MOTOR_STEPS 200

//Motor direction to home
//    options 1 (forward)
//            -1(reverse)
#define STEP_FORWARD 1
#define STEP_REVERSE -1
#define X_DIR_HOME STEP_FORWARD
#define Y_DIR_HOME STEP_FORWARD

// All the wires needed for full functionality
#define X_MAX_PIN 6
#define X_HOME_PIN 7 //home pin.
#define X_DIR_PIN 8
#define X_STEP_PIN 9
#define X_ANALOG_PIN A0

#define Y_MAX_PIN 5
#define Y_HOME_PIN 10
#define Y_DIR_PIN 11
#define Y_STEP_PIN 12
#define Y_ANALOG_PIN A2

// Since microstepping is set externally, make sure this matches the selected mode
// 1=full step, 2=half step etc.
#define MICROSTEPS 1

// 2-wire basic config, microstepping is hardwired on the driver
BasicStepperDriver x_stepper(X_MOTOR_STEPS, X_DIR_PIN, X_STEP_PIN, X_HOME_PIN, X_MAX_PIN);
BasicStepperDriver y_stepper(Y_MOTOR_STEPS, Y_DIR_PIN, Y_STEP_PIN, Y_HOME_PIN, Y_MAX_PIN);

int x_position = 0;
int x_analog;
int y_position = 0;
int y_analog;

void setup() {
  #ifdef DEBUG
   Serial.begin(9600);
  #endif
    /*
     * Set target motor RPM.
     * These motors can do up to about 200rpm.
     * Too high will result in a high pitched whine and the motor does not move.
     * 
     * We want these motors to move slowly.
     */
    x_stepper.setRPM(100);
    y_stepper.setRPM(100);    
    
    /*
     * Tell the driver the microstep level we selected.
     * If mismatched, the motor will move at a different RPM than chosen.
     */
    x_stepper.setMicrostep(MICROSTEPS);
    y_stepper.setMicrostep(MICROSTEPS);
}

void loop() {

    /*
     * Moving motor one full revolution using the degree notation
     */
     // 1024/2 = 512
     // 512 - 40 = 472
     // 512 + 40 = 552
     x_analog = analogRead(X_ANALOG_PIN);
     // Joystick pulled to reverse and HOME not pressed
     //if ((x_analog < 472) && (digitalRead(X_HOME_PIN)==HIGH)) {
      if ((x_analog < 472)) {
       x_stepper.move(-40);
      } else if ((x_analog > 552)) {
       x_stepper.move(40);
     }
     #ifdef DEBUG
       Serial.print("X: "); Serial.print(x_analog);  //Serial.print(x_stepper.getDirection());
     #endif
     
     y_analog = analogRead(Y_ANALOG_PIN);
     
     //if ((y_analog < 472) && (digitalRead(Y_HOME_PIN)==HIGH)) {
     if ((y_analog < 472)) {
       y_stepper.move(-40);
      } else if ((y_analog > 552)) {
       y_stepper.move(40);
     }
     #ifdef DEBUG
      Serial.print("  Y: "); Serial.println(y_analog);  //Serial.getDirection(y_stepper.
     #endif

}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Arduino on Internal Oscillator Crystal as Clock Source
Intermediate
  • 670
  • 46

Protip

Want to make an Arduino having only an ATmega328 chip and nothing else? Not even the crystal oscillator!

Reducing Arduino Power Consumption
Intermediate
  • 1,097
  • 74

Protip

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

Distance Measurement Vehicle via Websocket
Intermediate
  • 2,676
  • 21

Full instructions

A vehicle measures distance with an encoder on its wheel. It is remotely controlled and transmits the distance via Websocket.

Pi Zero Speaker - DIY Audio HAT and Audio Player
Intermediate
  • 385
  • 6

Work in progress

Convert an old speaker into something cool powered by Pi Zero.

Barbot: Cocktail Mixing Robot
Intermediate
  • 4,093
  • 29

Full instructions

Barbot is an open source Arduino cocktail mixing robot controlled with the hybrid mobile app via Bluetooth.

RING PONG
Intermediate
  • 1,332
  • 6

A simple Ping Pong game played on a NeoPixel Ring with Arduino.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login