Post by Admin on Feb 28, 2016 21:55:44 GMT
Foamcube code for the Arduino Mega is under development.
Currently the code is written by Pete Scheepens, forking off and building on to a 4-axis demo by Dan (marginallyclever)
The actual code consists of many tabs. Below is just a small intro as of 28-02-2016. Full code can be found in Foamcubes starting April 2016.
Currently the code is written by Pete Scheepens, forking off and building on to a 4-axis demo by Dan (marginallyclever)
The actual code consists of many tabs. Below is just a small intro as of 28-02-2016. Full code can be found in Foamcubes starting April 2016.
// 4 Axis CNC Demo - supports MEGA 2560 Arduino RAMPS 1.4
// dan@marginallyclever.com 2013-10-28
// Modified by Søren Vedel
// sorenvedel@gmail.com 2015-06-19
//
// enhanced to 5 axis CNC w. SD and LCD by Pete Scheepens
// via4321@gmail.com 2016-02-26
// http://foamcuttingcube.com
//
// Modified code for 5-axis Foamcutter CNC
// 25-02-2016 : blew up our test ramps due to polarity switch - yup happens to us too ;-)
//
//
//
//------------------------------------------------------------------------------
// Copyright at end of file.
// please see http://www.github.com/MarginallyClever/GcodeCNCDemo for more information.
#include "Config.h" // some initial config
//------------------------------------------------------------------------------
// SUPERGLOBALS
//------------------------------------------------------------------------------
int xco = 0; // x coordinate on screen tower 1
int yco = 0; // y coordinate
int zco = 0; // z coordinate - tower 2
int eco = 0; // e coordinate
int aco = 0; // a coordinate - rotation platform
int homing=0; // are we on autopilot back to 0,0,0,0,0 ?
int switchx=0;
char buffer[MAX_BUF]; // where we store the message until we get a ';'
int sofar; // how much is in the buffer
float fr=0; // human version speed
long step_delay; // machine version speed
float px,py,pz,pe,pa; // positions
char mode_abs=1; // absolute mode?
long line_number=0;
//------------------------------------------------------------------------------
// STRUCTS
//------------------------------------------------------------------------------
// for line()
typedef struct {
long delta; // number of steps to move
long absdelta;
long over; // for dx/dy bresenham calculations
}
Axis;
typedef struct {
int step_pin;
int dir_pin;
int enable_pin;
int limit_switch_pin;
}
Motor;
Axis a[NUM_AXIES]; // for line()
Axis atemp; // for line()
Motor motors[NUM_AXIES];
//------------------------------------------------------------------------------
// libraries
//------------------------------------------------------------------------------
#include <SD.h> // sd support library
Sd2Card card;
SdVolume volume;
SdFile root;
#include <U8glib.h> // LCD display support
#include "Pin.h" // some pinsettings
#include "functions.h" // where all the work is done
#include "lcddraw.h" // where we draw stuff on screen
void setup() { //First thing this machine does on startup. Runs only once.
Serial.begin(BAUD); // open coms
delay(1);
SD.begin(53); // go SD
pinMode(53, OUTPUT);
pinMode(48, OUTPUT);
digitalWrite(48,HIGH);
pinMode(SPI_MISO_PIN, INPUT);
pinMode(SPI_MOSI_PIN, OUTPUT);
pinMode(SPI_SCK_PIN, OUTPUT);
digitalWrite(SPI_MOSI_PIN,LOW);
digitalWrite(SPI_SCK_PIN,LOW);
digitalWrite(53,LOW);
u8g.setFont(u8g_font_unifont); // lcd display
u8g.setColorIndex(1); // Instructs the display to draw with a pixel on.
motor_setup(); // initialize motor pins and outputs
motor_disable(); // shut motors down - no need to idle
where(); // for debugging purposes
help(); // say hello
position(0,0,0,0,0); // set starting position
feedrate(1000); // set default speed
ready();
}
void loop() {
if (!card.init(SPI_FULL_SPEED, chipSelect)) { Serial.println("SD initialization failed.check:");return; } // check SD card
else { Serial.println("SD card initialized.");}
File dataFile = SD.open("datalog.txt"); // open selected file. only one file can be open at a time, so close this one before opening another.
if (dataFile) {
while (dataFile.available()) {
char c=dataFile.read(); // get it
Serial.print(c); // repeat it back so I know you got the message
if(sofar<MAX_BUF-1) buffer[sofar++]=c; // store it
if(c=='\n') { // entire message received
buffer[sofar]=0; // end the buffer so string functions work right
Serial.print(F("\r\n")); // echo a return character for humans
processCommand(); // parse the gcode
u8g.firstPage(); do {draw();} while( u8g.nextPage() ); // draw stuff on the lcd panel
ready();
}
}
dataFile.close();
}
else { Serial.println("error opening datalog.txt"); } // if the file isn't open, pop up an error:
delay(12000);
}
/**
* This file is part of GcodeCNCDemo.
*
* GcodeCNCDemo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GcodeCNCDemo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/