Kramick Saha
Published © GPL3+

Linear Motion Plotter

A CNC pen plotter with linear motion sensing.

AdvancedWork in progress6,046
Linear Motion Plotter

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Stepper motor driver board A4988
SparkFun Stepper motor driver board A4988
×1
V3 Engraver 3D Printer CNC Shield Expansion Board A4988 Driver
×1
Servo Motor
×1
PS2 mouse
×1
Stepper motor
×1

Software apps and online services

Windows 10
Microsoft Windows 10
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
PCB BOARD & MALE-FEMALE BERG STRIP
REES52 Breadboard Jumper Cables Kit, Set of 120 (Multicolor)
Photron Precision Magnetic ScrewDriver 31 in 1 Repairing Tool Set Kit Replaceable Straight Screw-Driver MultiTool Hand Tool

Story

Read more

Custom parts and enclosures

Custom Built PCB

Custom Built PCB to hold the arduino and CNC shield together

Schematics

Overall circuit diagram

Communication of all components with arduino

Motion Sensing Pen

Extracting the PS2 mouse circuit and incorporate it to a pen

Code

Project_CODE

Arduino
We can also introduce any of the curve smoothing algorithm to smooth the curve.As I am using the Arduino UNO so I did't use the mentioned method.We have to use Arduino Mega to implement that for more processing power.
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <PS2Mouse.h>
#include <Servo.h> 

// for the Arduino Uno + CNC shield V3
#define MOTOR_A_ENABLE_PIN 8
#define MOTOR_A_STEP_PIN 2
#define MOTOR_A_DIR_PIN 5

#define MOTOR_B_ENABLE_PIN 8
#define MOTOR_B_STEP_PIN 3
#define MOTOR_B_DIR_PIN 6

#define MDATA 10
#define MCLK 9

PS2Mouse mouse(MCLK,MDATA,STREAM);

AccelStepper stepper1(1, MOTOR_A_STEP_PIN, MOTOR_A_DIR_PIN); 
AccelStepper stepper2(1, MOTOR_B_STEP_PIN, MOTOR_B_DIR_PIN); 

Servo myservo;  
int servo_pos = 0;    

MultiStepper xy;
int x=0,y=0,posx=0,posy=0;
void setup() 
{
  Serial.begin(9600);
  myservo.attach(12);  
  stepper1.setEnablePin(MOTOR_A_ENABLE_PIN);
  stepper1.setPinsInverted(false, false, true);
  stepper2.setEnablePin(MOTOR_B_ENABLE_PIN);
  stepper2.setPinsInverted(false, false, true);
  // Configure each stepper
  stepper1.setMaxSpeed(100);
  stepper2.setMaxSpeed(100);
  // Then give them to MultiStepper to manage
  xy.addStepper(stepper1);
  xy.addStepper(stepper2);
  stepper1.enableOutputs();
  stepper2.enableOutputs();
  
  mouse.initialize();
}

void loop() 
{
   int data[3];
   long position[2];
    
    mouse.report(data);
  
   // x+=Filter.run(data[1]);
      x+=data[1];
    //y+=Filter.run(data[2]);
      y+=data[2];
   
    if(x>6000)
      x=6000;
    else if(x<-6000)
      x=-6000;
    else if(y>6000)
      y=6000;
    else if(y<-6000)
      y=-6000;  
    else
    {
        position[0]=-x/7;
        position[1]=-y/7;
     /*---------------------------------------------*/
              Serial.print(data[0]);//status byte
              Serial.print(":");
              Serial.print( position[0]);//X value
              Serial.print(",");
              Serial.print( position[1]);//Y value
              Serial.println();
    /*---------------------------------------------*/ 
        if(data[0]==9 || data[0]==25 || data[0]==41 || data[0]==57)
          myservo.write(170);//pen down
        else if(data[0]==8 || data[0]==40 || data[0]==24 || data[0]==56)
          myservo.write(90);//pen up  
        xy.moveTo(position);
        xy.runSpeedToPosition();
      //  posx=x;
      //  posy=y;
    }
    //delay(100);
}

Credits

Kramick Saha

Kramick Saha

1 project • 5 followers

Comments