Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15427

Gcode files from SD card to steppermotor commands

$
0
0

Hi, Ive been trying to make an 2 axis stepper driven machine but I've ran into some problems with converting gcode into steppermotor commando's. I am using the A4988 driver and 2 nema 17 motors. (I have an Uno R3 and Mega 2560)
First i would like to read the gcode from an SD card and then convert it into steppercommands.
If that would eventually just work on its own, i will add an LCD to see wich file is being executed. And then with some buttons it would be nice to be able to select wich file I want from the sd card to execute and pause/restart when i want to.

This is my setup code, i hope its readable.
Thx in advance if anyone knows how to do this!

//Libraries
  #include <Arduino.h>
  #include <A4988.h>
  #include <Wire.h>
  #include <LiquidCrystal_I2C.h>
  #include <SD.h>

//Pin defines Steppers
  //StepperX
    int DirX = //Direction of stepper
    int StepX = //Steps of stepper
    int SleepX = //Sleep Control stepper
    int MS1X = 
    int MS2X = 
    int MS3X = 
  //StepperY
    int DirY = 
    int StepY = 
    int SleepY = 
    int MS1Y = 
    int MS2Y = 
    int MS3Y = 
  //Constants 
    const int spr = 200; //Steps per revolution
    int rpm = 100; //Rotations per minute
    int MicroSteps = 1 //Stepsize, 1 == full step; 2 == half step; 4 == quarter ....
  //Stepper setup
    A4988 StepperX(spr, DirX, MS1X, MS2X, MS3X); //Initialisatie stepper X
    A4988 StepperY(spr, DirY, MS1Y, MS2Y, MS3Y); //Initialisatie stepper Y

//Defines/bools buttons
  const int pauseButton = 
  const int startButton = 
  const int nextButton = 
  const int previousButton = 
  bool isPaused = false;
  
//LCD
  const int lcdBackLight = 
  LiquidCrystal lcd(0x27, 20, 4);// 0x27 = adres, 20 columns on 4 rows   

//SD
  File gcodeFile;
  const char* fileNames[] = {"pattern1.gcode", "pattern2.gcode", "pattern3.gcode", "pattern4.gcode", "cleanup.gcode"}; 
  int currentFileIndex = -1; // Current executed file
  
//Others 
  unsigned long lastFileStartTime = 0; //Variable for keeping time
  unsigned long lastButtonPressTime = 0; //Varibale for keeping time

void setup() 
{
  Serial.begin(9600);
  
  //Steppers
    //StepperX
      pinMode(DirX, OUTPUT);
      pinMode(StepX, OUTPUT);
      pinMode(SleepX, OUTPUT);
      digitalWrite(DirX, LOW);
      digitalWrite(StepX, LOW);
    //StepperY
      pinMode(DirY, OUTPUT);
      pinMode(StepY, OUTPUT);
      pinMode(SleepY, OUTPUT);
      digitalWrite(DirY, LOW);
      digitalWrite(StepY, LOW);
    //Steppers start
      StepperX.begin(rpm, MicroSteps);
      StepperY.begin(rpm, MicroSteps);

  //Buttons
    pinMode(pauseButton, INPUT_PULLUP);
    pinMode(startButton, INPUT_PULLUP);
    pinMode(nextButton, INPUT_PULLUP);
    pinMode(previousButton, INPUT_PULLUP);

  //LCD
    lcd.begin();
    lcd.backlight();
    pinMode(lcdBacklight, OUTPUT); 

  //SD
    if (!SD.begin(10)) // Use random pin for the sd card module
    {                   
      Serial.println("SD-card intialisation failed!");
      return;
    } 
}

void loop() 
{
  

}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15427

Trending Articles