ArduinoMega CNCshieldV3 — Arduino Mega simulation

An interactive Arduino Mega circuit simulation you can run free in your browser on Velxio, by leemcf.

Components

Sketch code

//NDT Ultrasonic Scanning CNC Code
//Made by: Lee McFarland
//[email protected]
//706.618.5896

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <AccelStepper.h>
#include <AccelStepperWithDistance.h>
#include <SD.h>
#include <SPI.h>
//#include <Forgetfulino.h>

File myFile;

const float circDist = 1; //maximum inches the bar surface can move between each pass, move from rotating the bar
const float accelDist = 1; // inches before and after scan to start or stop
const float pointScanWdth = 1; //inches before and after point scan (half point scan length)

const float rotstepSpeed = 1; //step per sec
const float gantrystepSpeed = 1; //step per sec
const float vertstepSpeed = 1; //step per sec
const float probestepSpeed = 1; //step per sec

const byte gantryEndstop = 10; //pin number
const byte vertEndstop = 11; //pin number
const byte probeEndstop = 9; //pin number
const byte EstopPin = 19; //pin number
const byte abortPin = 18; //pin number
const byte flawPin = 30; //pin number flaw detected from probe scan system
const boolean flawRead = HIGH; // flaw detected signal from probe scan system
const byte chipSelect = 53; //pin number for SD card CHIP SELECT

char scanorGo='A';

const byte rows = 4;
const byte cols = 4;

char keyNumber[4][4] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'},
};

byte rowsPin[rows] = {22,24,26,28};
byte colsPin[cols] = {30,32,34,36};

Keypad keypad = Keypad(makeKeymap(keyNumber), rowsPin, colsPin, rows, cols);
LiquidCrystal_I2C lcd(0x27,20,4);

AccelStepperWithDistance rotstep(AccelStepperWithDistance::DRIVER, 2, 5);
AccelStepperWithDistance gantrystep(AccelStepperWithDistance::DRIVER, 3, 6);
AccelStepperWithDistance vertstep(AccelStepperWithDistance::DRIVER, 4, 7);
AccelStepperWithDistance probestep(AccelStepperWithDistance::DRIVER, 12, 13);


void setup(){
  Serial.begin(9600);
  //Forgetfulino.begin();
  //Forgetfulino.dumpCompressed();

  pinMode(gantryEndstop, INPUT_PULLUP);//ENDSTOPS GANTRY internal pullup resistor (debouncing)
  pinMode(vertEndstop, INPUT_PULLUP);//ENDSTOPS VERT internal pullup resistor (debouncing)
  pinMode(probeEndstop, INPUT_PULLUP);//ENDSTOPS PROBE internal pullup resistor (debouncing)
  
  pinMode(EstopPin, INPUT_PULLUP);//ESTOP internal pullup resistor (debouncing)
  pinMode(abortPin, INPUT_PULLUP);//ABORT internal pullup resistor (debouncing)
  pinMode(flawPin, INPUT_PULLUP);//FLAW DETECTED internal pullup resistor (debouncing)

  delay(500);
  attachInterrupt(digitalPinToInterrupt(abortPin), aBort, HIGH);
  attachInterrupt(digitalPinToInterrupt(EstopPin), Estop, HIGH);

  lcd.init();
  lcd.backlight();
  lcd.clear();
  if (!SD.begin(chipSelect)) { //if there is no SD card - send message
    lcd.setCursor(0,0);// 1st row
    lcd.print("INSERT SD CARD");
    while (!SD.begin(chipSelect)) {
      delay(1000);
    }
  }
  lcd.clear();

  stepSetup();//setup 4-axis of stepper motors
    
  float barDia=0;
  float barLth=0;
  float probeDown=

More projects by leemcf