diff --git a/.gitignore b/.gitignore index 0bea06f8..81e5096f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ Thumbs.db *.orig embedded/node_modules embedded/dist +*~ diff --git a/Grbl_Esp32/Grbl_Esp32.ino b/Grbl_Esp32/Grbl_Esp32.ino index 7890dfae..c761a647 100644 --- a/Grbl_Esp32/Grbl_Esp32.ino +++ b/Grbl_Esp32/Grbl_Esp32.ino @@ -47,8 +47,8 @@ void setup() { grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Compiled with ESP32 SDK:%s", ESP.getSdkVersion()); // print the SDK version - #ifdef CPU_MAP_NAME // show the map name at startup - grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Using cpu_map:%s", CPU_MAP_NAME); + #ifdef MACHINE_NAME // show the map name at startup + grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Using cpu_map:%s", MACHINE_NAME); #endif settings_init(); // Load Grbl settings from EEPROM diff --git a/Grbl_Esp32/Machines/3x_esc_spindle.h b/Grbl_Esp32/Machines/3x_esc_spindle.h new file mode 100644 index 00000000..65f6b189 --- /dev/null +++ b/Grbl_Esp32/Machines/3x_esc_spindle.h @@ -0,0 +1,33 @@ +// This is an example of using a Brushless DC Hobby motor as +// a spindle motor. See this wiki page for more info +// https://github.com/bdring/Grbl_Esp32/wiki/BESC-Spindle-Feature +// +// To use this file you must first include another machine file +// that defines the pin assignments, such as Machines/3x_v4.h + +#define SHOW_EXTENDED_SETTINGS + +#define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit recommended for ESC (don't change) + +/* + Important ESC Settings + $33=50 // Hz this is the typical good frequency for an ESC + #define DEFAULT_SPINDLE_FREQ 5000.0 // $33 Hz (extended set) + + Determine the typical min and max pulse length of your ESC + min_pulse is typically 1ms (0.001 sec) or less + max_pulse is typically 2ms (0.002 sec) or more + + determine PWM_period. It is (1/freq) if freq = 50...period = 0.02 + + determine pulse length for min_pulse and max_pulse in percent. + + (pulse / PWM_period) + min_pulse = (0.001 / 0.02) = 0.05 = 5% so ... $34 and $35 = 5.0 + max_pulse = (0.002 / .02) = 0.1 = 10% so ... $36=10 +*/ + +#define DEFAULT_SPINDLE_FREQ 50.0 +#define DEFAULT_SPINDLE_OFF_VALUE 5.0 +#define DEFAULT_SPINDLE_MIN_VALUE 5.0 +#define DEFAULT_SPINDLE_MAX_VALUE 10.0 diff --git a/Grbl_Esp32/Machines/3x_v3.h b/Grbl_Esp32/Machines/3x_v3.h new file mode 100644 index 00000000..c8c6fa37 --- /dev/null +++ b/Grbl_Esp32/Machines/3x_v3.h @@ -0,0 +1,31 @@ +// Pin assignments for the ESP32 Development Controller, v3.5. +// https://github.com/bdring/Grbl_ESP32_Development_Controller +// https://www.tindie.com/products/33366583/grbl_esp32-cnc-development-board-v35/ + +#define MACHINE_NAME "MACHINE_ESP32_V3.5" + +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_26 +#define Y_STEP_PIN GPIO_NUM_14 +#define Y_DIRECTION_PIN GPIO_NUM_25 +#define Z_STEP_PIN GPIO_NUM_27 +#define Z_DIRECTION_PIN GPIO_NUM_33 + +#define LIMIT_MASK B111 +#define X_AXIS_LIMIT_PIN GPIO_NUM_2 // labeled X Limit +#define Y_AXIS_LIMIT_PIN GPIO_NUM_4 // labeled Y Limit +#define Y_AXIS_LIMIT_PIN GPIO_NUM_15 // labeled Z Limit + +// OK to comment out to use pin for other features +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + +#define SPINDLE_PWM_PIN GPIO_NUM_17 // labeled SpinPWM +#define SPINDLE_ENABLE_PIN GPIO_NUM_22 // labeled SpinEnbl +#define MIST_PIN GPIO_NUM_21 // labeled Mist +#define FLOOD_PIN GPIO_NUM_16 // labeled Flood +#define PROBE_PIN GPIO_NUM_32 // labeled Probe + +#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // labeled Door, needs external pullup +#define CONTROL_RESET_PIN GPIO_NUM_34 // labeled Reset, needs external pullup +#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // labeled Hold, needs external pullup +#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // labeled Start, needs external pullup diff --git a/Grbl_Esp32/Machines/3x_v4.h b/Grbl_Esp32/Machines/3x_v4.h new file mode 100644 index 00000000..642e85d3 --- /dev/null +++ b/Grbl_Esp32/Machines/3x_v4.h @@ -0,0 +1,31 @@ +// Pin assignments for the ESP32 Development Controller, v4.1 and later. +// https://github.com/bdring/Grbl_ESP32_Development_Controller +// https://www.tindie.com/products/33366583/grbl_esp32-cnc-development-board-v35/ + +#define MACHINE_NAME "MACHINE_ESP32_V4" + +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_14 +#define Y_STEP_PIN GPIO_NUM_26 +#define Y_DIRECTION_PIN GPIO_NUM_15 +#define Z_STEP_PIN GPIO_NUM_27 +#define Z_DIRECTION_PIN GPIO_NUM_33 + +#define LIMIT_MASK B111 +#define X_AXIS_LIMIT_PIN GPIO_NUM_17 +#define Y_AXIS_LIMIT_PIN GPIO_NUM_4 +#define Z_AXIS_LIMIT_PIN GPIO_NUM_16 + +// OK to comment out to use pin for other features +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + +#define SPINDLE_PWM_PIN GPIO_NUM_2 // labeled SpinPWM +#define SPINDLE_ENABLE_PIN GPIO_NUM_22 // labeled SpinEnbl +#define MIST_PIN GPIO_NUM_21 // labeled Mist +#define FLOOD_PIN GPIO_NUM_25 // labeled Flood +#define PROBE_PIN GPIO_NUM_32 // labeled Probe + +#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // labeled Door, needs external pullup +#define CONTROL_RESET_PIN GPIO_NUM_34 // labeled Reset, needs external pullup +#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // labeled Hold, needs external pullup +#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // labeled Start, needs external pullup diff --git a/Grbl_Esp32/Machines/3x_xyx.h b/Grbl_Esp32/Machines/3x_xyx.h new file mode 100644 index 00000000..ca44c239 --- /dev/null +++ b/Grbl_Esp32/Machines/3x_xyx.h @@ -0,0 +1,35 @@ +// This is the CPU Map for the ESP32 Development Controller +// used to drive a dual motor gantry where the drivers +// labeled X, Y and Z drive the machine axes X, Y and X. +// https://github.com/bdring/Grbl_ESP32_Development_Controller +// https://www.tindie.com/products/33366583/grbl_esp32-cnc-development-board-v35/ + +#define MACHINE_NAME "MACHINE_ESP32_V4_XYX" +#define X_STEP_PIN GPIO_NUM_26 /* labeled Y */ +#define X_DIRECTION_PIN GPIO_NUM_15 /* labeled Y */ +#define Y_STEP_PIN GPIO_NUM_12 /* labeled X */ +#define Y_DIRECTION_PIN GPIO_NUM_14 /* labeled X */ +#define Y2_STEP_PIN GPIO_NUM_27 /* labeled Z */ +#define Y2_DIRECTION_PIN GPIO_NUM_33 /* labeled Z */ + +#define SPINDLE_PWM_PIN GPIO_NUM_2 + +#define LIMIT_MASK B11 +#define X_LIMIT_PIN GPIO_NUM_17 +#define Y_LIMIT_PIN GPIO_NUM_4 +// #define Z_LIMIT_PIN GPIO_NUM_16 + +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + +#define COOLANT_MIST_PIN_1 GPIO_NUM_21 +#define COOLANT_FLOOE_PIN_2 GPIO_NUM_25 + +#define SPINDLE_ENABLE_PIN GPIO_NUM_22 + +// see versions for X and Z +#define PROBE_PIN GPIO_NUM_32 + +#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // needs external pullup +#define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup +#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup +#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup diff --git a/Grbl_Esp32/Machines/atari_1020.h b/Grbl_Esp32/Machines/atari_1020.h new file mode 100644 index 00000000..2042573f --- /dev/null +++ b/Grbl_Esp32/Machines/atari_1020.h @@ -0,0 +1,166 @@ +/* + atari_1020.h + Part of Grbl_ESP32 + + copyright (c) 2018 - Bart Dring This file was modified for use on the ESP32 + CPU. Do not use this with Grbl for atMega328P + + Grbl 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. + + Grbl 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 Grbl. If not, see . + + This contains all the special features required to control an + Atari 1010 Pen Plotter +*/ + +#define MACHINE_NAME "MACHINE_ATARI_1020" + +// ================== CPU MAP ====================== +#define USE_UNIPOLAR + +#define X_UNIPOLAR +#define X_PIN_PHASE_0 GPIO_NUM_13 +#define X_PIN_PHASE_1 GPIO_NUM_21 +#define X_PIN_PHASE_2 GPIO_NUM_16 +#define X_PIN_PHASE_3 GPIO_NUM_22 + +#define Y_UNIPOLAR +#define Y_PIN_PHASE_0 GPIO_NUM_25 +#define Y_PIN_PHASE_1 GPIO_NUM_27 +#define Y_PIN_PHASE_2 GPIO_NUM_26 +#define Y_PIN_PHASE_3 GPIO_NUM_32 + + +#define SOLENOID_DIRECTION_PIN GPIO_NUM_4 +#define SOLENOID_PEN_PIN GPIO_NUM_2 +#define SOLENOID_CHANNEL_NUM 6 + +#ifdef HOMING_CYCLE_0 + #undef HOMING_CYCLE_0 +#endif +#define HOMING_CYCLE_0 (1<. + + ==================================================================== + + See custom_machine_templete.cpp for getting started creating custom + machines +*/ + +// =============== MACHINE NAME ======================== +// Change "MACHINE_CUSTOM", replacing "CUSTOM" with your chosen name + +// #define MACHINE_NAME "MACHINE_CUSTOM" + +// ================ config.h overrides ==================================== +// If you want to make some changes to config.h, it is best to do it here +// if possible so all your changes are in your files. Many of the #defines +// in config.h are only applied if the symbol is not already defined in +// a machine definition file. Example: + +// #define N_AXIS 4 + +// =============== MACHINE CONFIGURATION ======================== +// Look at the other files in the Machines/ directory +// for all the things that can go here + +// Assign CPU pins to machine functions, for example: +// #define X_STEP_PIN GPIO_NUM_12 +// #define X_DIRECTION_PIN GPIO_NUM_26 +// #define X_AXIS_LIMIT_PIN GPIO_NUM_2 + +// #define SPINDLE_PWM_PIN GPIO_NUM_17 + +// #define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 + +// Set the number of bits to the number of limit switches +// #define LIMIT_MASK B111 + +// ============== Enable custom features ======================= + +// There are several customization functions that the code only +// calls if the symbols below are defined. To use such a function, +// you must define the symbol herein, and define the function in +// your my_machine.cpp file. + +// #define USE_MACHINE_INIT // Enables use of custom machine_init() +// #define USE_CUSTOM_HOMING // Enables use of user_defined_homing() +// #define USE_KINEMATICS // Enables use of inverse_kinematics(), kinematics_pre_homing(), and kinematics_post_homing() +// #define USE_FWD_KINEMATIC // Enables use of forward_kinematics() +// #define USE_TOOL_CHANGE // Enables use off user_tool_change() +// #define USE_M30 // Enables use of user_m30() +// #define USE_TRIAMINIC // Enables use of functions shown in grbl_triaminic.h +// #define USE_MACHINE_TRINAMIC_INIT // Enables use of machine_triaminic_setup() + +// ===================== $$ Defaults ========================================== +// defaults.h defines default values for the $$ settings that will be +// applied when you upload new firmware or if you reset them with $RST=$. +// You can override individual defaults by defining them here. Examples: + +// #define DEFAULT_SPINDLE_FREQ 2000.0 +// #define DEFAULT_X_MAX_TRAVEL 100.0 + diff --git a/Grbl_Esp32/Machines/espduino.h b/Grbl_Esp32/Machines/espduino.h new file mode 100644 index 00000000..681de94b --- /dev/null +++ b/Grbl_Esp32/Machines/espduino.h @@ -0,0 +1,38 @@ +// Pin assignments for ESPDUINO-32 Boards and Protoneer V3 boards +// Note: Probe pin is mapped, but will require a 10k external pullup to 3.3V to work. + +// Rebooting...See this issue https://github.com/bdring/Grbl_Esp32/issues/314 +// !!!! Experimental Untested !!!!! + + +#define MACHINE_NAME "MACHINE_ESPDUINO_32" + +#define X_STEP_PIN GPIO_NUM_26 +#define X_DIRECTION_PIN GPIO_NUM_16 + +#define Y_STEP_PIN GPIO_NUM_25 +#define Y_DIRECTION_PIN GPIO_NUM_27 + +#define Z_STEP_PIN GPIO_NUM_17 +#define Z_DIRECTION_PIN GPIO_NUM_14 + +// OK to comment out to use pin for other features +#define STEPPERS_DISABLE_PIN GPIO_NUM_12 + +#define SPINDLE_PWM_PIN GPIO_NUM_19 +#define SPINDLE_DIR_PIN GPIO_NUM_18 + +#define COOLANT_FLOOD_PIN GPIO_NUM_34 +#define COOLANT_MIST_PIN GPIO_NUM_36 + +#define X_LIMIT_PIN GPIO_NUM_13 +#define Y_LIMIT_PIN GPIO_NUM_5 +#define Z_LIMIT_PIN GPIO_NUM_19 +#define LIMIT_MASK B111 + +#define PROBE_PIN GPIO_NUM_39 + +// comment out #define IGNORE_CONTROL_PINS in config.h to use control pins +#define CONTROL_RESET_PIN GPIO_NUM_2 +#define CONTROL_FEED_HOLD_PIN GPIO_NUM_4 +#define CONTROL_CYCLE_START_PIN GPIO_NUM_35 // ESP32 needs external pullup diff --git a/Grbl_Esp32/Machines/external_driver_4x.h b/Grbl_Esp32/Machines/external_driver_4x.h new file mode 100644 index 00000000..05289e3d --- /dev/null +++ b/Grbl_Esp32/Machines/external_driver_4x.h @@ -0,0 +1,40 @@ +// Pin assignments for the buildlog.net 4-axis external driver board + +#define MACHINE_NAME "External Driver Board V1.1" + +#ifdef N_AXIS + #undef N_AXIS +#endif +#define N_AXIS 4 + +#define X_STEP_PIN GPIO_NUM_0 +#define X_DIRECTION_PIN GPIO_NUM_2 +#define Y_STEP_PIN GPIO_NUM_26 +#define Y_DIRECTION_PIN GPIO_NUM_15 +#define Z_STEP_PIN GPIO_NUM_27 +#define Z_DIRECTION_PIN GPIO_NUM_33 +#define A_STEP_PIN GPIO_NUM_14 +#define A_DIRECTION_PIN GPIO_NUM_12 +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + + +#define SPINDLE_PWM_PIN GPIO_NUM_25 +#define SPINDLE_ENABLE_PIN GPIO_NUM_22 + +#define MODBUS_TX GPIO_NUM_17 +#define MODBUS_RX GPIO_NUM_4 +#define MODBUS_CTRL GPIO_NUM_16 + +#define X_LIMIT_PIN GPIO_NUM_34 +#define Y_LIMIT_PIN GPIO_NUM_35 +#define Z_LIMIT_PIN GPIO_NUM_36 + +#if (N_AXIS == 3) + #define LIMIT_MASK B0111 +#else + #define A_LIMIT_PIN GPIO_NUM_39 + #define LIMIT_MASK B1111 +#endif + +#define PROBE_PIN GPIO_NUM_32 +#define COOLANT_MIST_PIN GPIO_NUM_21 diff --git a/Grbl_Esp32/Machines/foo_6x.h b/Grbl_Esp32/Machines/foo_6x.h new file mode 100644 index 00000000..127d2f50 --- /dev/null +++ b/Grbl_Esp32/Machines/foo_6x.h @@ -0,0 +1,139 @@ +// Pin assignments for 6-axis system + +#define MACHINE_NAME "MACHINE_FOO_6X" + +// Be sure to change to N_AXIS 6 in nuts_bolts.h +#ifdef N_AXIS +#undef N_AXIS +#endif +#define N_AXIS 6 + +// stepper motors +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_26 + +#define Y_STEP_PIN GPIO_NUM_14 +#define Y_DIRECTION_PIN GPIO_NUM_25 + +// Z is a servo + +#define A_STEP_PIN GPIO_NUM_27 +#define A_DIRECTION_PIN GPIO_NUM_33 + +#define B_STEP_PIN GPIO_NUM_15 +#define B_DIRECTION_PIN GPIO_NUM_32 + +// C is a servo + +// servos +#define USE_SERVO_AXES +#define SERVO_Z_PIN GPIO_NUM_22 +#define SERVO_Z_CHANNEL_NUM 6 +#define SERVO_Z_RANGE_MIN 0.0 +#define SERVO_Z_RANGE_MAX 5.0 +#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value +#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing +#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates + +#define SERVO_C_PIN GPIO_NUM_2 +#define SERVO_C_CHANNEL_NUM 7 +#define SERVO_C_RANGE_MIN 0.0 +#define SERVO_C_RANGE_MAX 5.0 +#define SERVO_C_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value +#define SERVO_C_HOME_POS SERVO_C_RANGE_MAX // move to max during homing +#define SERVO_C_MPOS false // will not use mpos, uses work coordinates + +// limit switches +#define X_LIMIT_PIN GPIO_NUM_21 +#define Y_LIMIT_PIN GPIO_NUM_17 +#define A_LIMIT_PIN GPIO_NUM_16 +#define B_LIMIT_PIN GPIO_NUM_4 +#define LIMIT_MASK B11011 + +// OK to comment out to use pin for other features +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + +#ifdef HOMING_CYCLE_0 // undefine from config.h + #undef HOMING_CYCLE_0 +#endif +//#define HOMING_CYCLE_0 (1<. -*/ +// This must be defined so that polar_coaster.cpp is not skipped +#define MACHINE_POLAR_COASTER #define RADIUS_AXIS 0 #define POLAR_AXIS 1 #define SEGMENT_LENGTH 0.5 // segment length in mm #define USE_KINEMATICS -#define USE_FWD_KINEMATIC // report in cartesian +#define USE_FWD_KINEMATIC // report in cartesian #define USE_M30 -// ============= Begin CPU MAP ================ -#define CPU_MAP_NAME "CPU_MAP_POLAR_COASTER" +#define X_STEP_PIN GPIO_NUM_15 +#define Y_STEP_PIN GPIO_NUM_2 +#define X_DIRECTION_PIN GPIO_NUM_25 +#define Y_DIRECTION_PIN GPIO_NUM_26 -#define USE_RMT_STEPS - -#define X_STEP_PIN GPIO_NUM_15 -#define Y_STEP_PIN GPIO_NUM_2 -#define X_DIRECTION_PIN GPIO_NUM_25 -#define Y_DIRECTION_PIN GPIO_NUM_26 - -#define STEPPERS_DISABLE_PIN GPIO_NUM_17 +#define STEPPERS_DISABLE_PIN GPIO_NUM_17 #ifndef USE_SERVO_AXES // maybe set in config.h #define USE_SERVO_AXES #endif -#define SERVO_Z_PIN GPIO_NUM_16 -#define SERVO_Z_CHANNEL_NUM 5 -#define SERVO_Z_RANGE_MIN 0.0 -#define SERVO_Z_RANGE_MAX 5.0 -#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value -#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing -#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates - -#define X_LIMIT_PIN GPIO_NUM_4 -#define LIMIT_MASK B1 +#define SERVO_Z_PIN GPIO_NUM_16 +#define SERVO_Z_CHANNEL_NUM 5 +#define SERVO_Z_RANGE_MIN 0.0 +#define SERVO_Z_RANGE_MAX 5.0 +#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value +#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing +#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates + +#define X_LIMIT_PIN GPIO_NUM_4 +#define LIMIT_MASK B1 #ifdef IGNORE_CONTROL_PINS // maybe set in config.h #undef IGNORE_CONTROL_PINS @@ -70,12 +52,12 @@ #ifdef INVERT_CONTROL_PIN_MASK #undef INVERT_CONTROL_PIN_MASK #endif -#define INVERT_CONTROL_PIN_MASK B11111111 +#define INVERT_CONTROL_PIN_MASK B11111111 + +#define MACRO_BUTTON_0_PIN GPIO_NUM_13 +#define MACRO_BUTTON_1_PIN GPIO_NUM_12 +#define MACRO_BUTTON_2_PIN GPIO_NUM_14 -#define MACRO_BUTTON_0_PIN GPIO_NUM_13 -#define MACRO_BUTTON_1_PIN GPIO_NUM_12 -#define MACRO_BUTTON_2_PIN GPIO_NUM_14 - // redefine some stuff from config.h #ifdef HOMING_CYCLE_0 #undef HOMING_CYCLE_0 @@ -86,19 +68,19 @@ #endif #ifdef HOMING_CYCLE_2 #undef HOMING_CYCLE_2 -#endif - +#endif + // ============= End CPU MAP ================== // ============= Begin Default Settings ================ -#define DEFAULT_STEP_PULSE_MICROSECONDS 3 +#define DEFAULT_STEP_PULSE_MICROSECONDS 3 #define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // stay on #define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t #define DEFAULT_DIRECTION_INVERT_MASK 2 // uint8_t #define DEFAULT_INVERT_ST_ENABLE 0 // boolean #define DEFAULT_INVERT_LIMIT_PINS 1 // boolean -#define DEFAULT_INVERT_PROBE_PIN 0 // boolean +#define DEFAULT_INVERT_PROBE_PIN 0 // boolean #define DEFAULT_STATUS_REPORT_MASK 2 // MPos enabled @@ -109,7 +91,7 @@ #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false #define DEFAULT_HARD_LIMIT_ENABLE 0 // false -#define DEFAULT_HOMING_ENABLE 1 +#define DEFAULT_HOMING_ENABLE 1 #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir Z, negative X,Y #define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min #define DEFAULT_HOMING_SEEK_RATE 1000.0 // mm/min @@ -131,26 +113,8 @@ #define DEFAULT_X_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Y_ACCELERATION (200.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 -#define DEFAULT_Z_ACCELERATION (50.0*60*60) +#define DEFAULT_Z_ACCELERATION (50.0*60*60) #define DEFAULT_X_MAX_TRAVEL 50.0 // mm NOTE: Must be a positive value. #define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. #define DEFAULT_Z_MAX_TRAVEL 100.0 // This is percent in servo mode -// ============= End Default Settings ================== - -#ifndef kinematics_h - #define kinematics_h - - #include "grbl.h" - -bool kinematics_pre_homing(uint8_t cycle_mask); -void kinematics_post_homing(); -void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *position); -void calc_polar(float *target_xyz, float *polar, float last_angle); -float abs_angle(float ang); -void user_defined_macro(uint8_t index); - -void forward_kinematics(float *position); -void user_m30(); - -#endif \ No newline at end of file diff --git a/Grbl_Esp32/Machines/servo_axis.h b/Grbl_Esp32/Machines/servo_axis.h new file mode 100644 index 00000000..4c0d9ea4 --- /dev/null +++ b/Grbl_Esp32/Machines/servo_axis.h @@ -0,0 +1,101 @@ +// Pin assignments for the Buildlog.net pen laser controller V1 +// using servos. + +// For pen mode be sure to uncomment #define USE_PEN_SERVO in config.h +// For solenoid mode be sure to uncomment #define USE_PEN_SERVO in config.h +// For laser mode, you do not need to change anything +// Note: You can use all 3 modes at the same time if you want + +#define MACHINE_NAME "MACHINE_SERVO_AXIS" + +// Pick a board version +//#define PEN_LASER_V1 +#define PEN_LASER_V2 + +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_26 + +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + +#ifdef PEN_LASER_V1 +#define X_LIMIT_PIN GPIO_NUM_2 +#endif + +#ifdef PEN_LASER_V2 +#define X_LIMIT_PIN GPIO_NUM_15 +#endif + +#define Y_LIMIT_PIN GPIO_NUM_4 +#define LIMIT_MASK B11 + +// If SPINDLE_PWM_PIN is commented out, this frees up the pin, but Grbl will still +// use a virtual spindle. Do not comment out the other parameters for the spindle. +#define SPINDLE_PWM_PIN GPIO_NUM_17 // Laser PWM +// PWM Generator is based on 80,000,000 Hz counter +// Therefor the freq determines the resolution +// 80,000,000 / freq = max resolution +// For 5000 that is 80,000,000 / 5000 = 16000 +// round down to nearest bit count for SPINDLE_PWM_MAX_VALUE +//#define SPINDLE_PWM_BASE_FREQ 5000 // Hz +#define SPINDLE_PWM_OFF_VALUE 0 + +#ifndef SPINDLE_PWM_MIN_VALUE +#define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. +#endif + +#define SERVO_Y_PIN GPIO_NUM_14 +#define SERVO_Y_CHANNEL_NUM 6 +#define SERVO_Y_RANGE_MIN 0.0 +#define SERVO_Y_RANGE_MAX 30.0 + +#define SERVO_Z_PIN GPIO_NUM_27 +#define SERVO_Z_CHANNEL_NUM 5 +#define SERVO_Z_RANGE_MIN 0.0 +#define SERVO_Z_RANGE_MAX 20.0 + +// defaults +#define DEFAULT_STEP_PULSE_MICROSECONDS 3 +#define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // stay on + +#define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t +#define DEFAULT_DIRECTION_INVERT_MASK 0 // uint8_t +#define DEFAULT_INVERT_ST_ENABLE 0 // boolean +#define DEFAULT_INVERT_LIMIT_PINS 1 // boolean +#define DEFAULT_INVERT_PROBE_PIN 0 // boolean + +#define DEFAULT_STATUS_REPORT_MASK 1 + +#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm +#define DEFAULT_ARC_TOLERANCE 0.002 // mm +#define DEFAULT_REPORT_INCHES 0 // false + +#define DEFAULT_SOFT_LIMIT_ENABLE 0 // false +#define DEFAULT_HARD_LIMIT_ENABLE 0 // false + +#define DEFAULT_HOMING_ENABLE 0 +#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir Z, negative X,Y +#define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min +#define DEFAULT_HOMING_SEEK_RATE 1000.0 // mm/min +#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) +#define DEFAULT_HOMING_PULLOFF 3.0 // mm + +#define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm +#define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm + +#define DEFAULT_LASER_MODE 0 // false + +#define DEFAULT_X_STEPS_PER_MM 40 // half turn on a stepper +#define DEFAULT_Y_STEPS_PER_MM 100.0 // default calibration value +#define DEFAULT_Z_STEPS_PER_MM 100.0 // default calibration value + +#define DEFAULT_X_MAX_RATE 2000.0 // mm/min +#define DEFAULT_Y_MAX_RATE 2000.0 // mm/min +#define DEFAULT_Z_MAX_RATE 2000.0 // mm/min + +#define DEFAULT_X_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#define DEFAULT_Y_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 +#define DEFAULT_Z_ACCELERATION (50.0*60*60) + +#define DEFAULT_X_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. +#define DEFAULT_Y_MAX_TRAVEL 100.0 // default calibration value +#define DEFAULT_Z_MAX_TRAVEL 100.0 // default calibration value diff --git a/Grbl_Esp32/Machines/spi_daisy_4x.h b/Grbl_Esp32/Machines/spi_daisy_4x.h new file mode 100644 index 00000000..065ef22a --- /dev/null +++ b/Grbl_Esp32/Machines/spi_daisy_4x.h @@ -0,0 +1,78 @@ +// Pin assignments for a 4-axis machine using Triaminic drivers +// in daisy-chained SPI mode. + +#define MACHINE_NAME "SPI_DAISY_4X" + +#ifdef N_AXIS + #undef N_AXIS +#endif +#define N_AXIS 3 // can be 3 or 4. (if 3 install bypass jumper next to the A driver) + +#define USE_TRINAMIC +#define TRINAMIC_DAISY_CHAIN + +// Use SPI enable instead of the enable pin +// The hardware enable pin is tied to ground +#define USE_TRINAMIC_ENABLE + +// allow two motors on an axis +#define USE_GANGED_AXES + +#define X_DRIVER_TMC2130 // Which Driver Type? +#define X_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_14 +#define X2_STEP_PIN GPIO_NUM_33 +#define X2_DIRECTION_PIN GPIO_NUM_32 +#define X_TRINAMIC // using SPI control +#define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin + +#define Y_DRIVER_TMC2130 // Which Driver Type? +#define Y_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 +#define Y_STEP_PIN GPIO_NUM_27 +#define Y_DIRECTION_PIN GPIO_NUM_26 +#define Y_TRINAMIC // using SPI control +#define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin + +#define Z_DRIVER_TMC2130 // Which Driver Type? +#define Z_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 +#define Z_STEP_PIN GPIO_NUM_15 +#define Z_DIRECTION_PIN GPIO_NUM_2 +#define Z_TRINAMIC // using SPI control +#define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin + +#if (N_AXIS == 4) + #define A_DRIVER_TMC2130 // Which Driver Type? + #define A_RSENSE 0.11f // .11 Ohm...typical of 2130 type 0.075 typical for TMC5160 + #define A_STEP_PIN GPIO_NUM_33 + #define A_DIRECTION_PIN GPIO_NUM_32 + #define A_TRINAMIC // using SPI control + #define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin +#endif + +// Mist is a 3.3V output +// Turn on with M7 and off with M9 +#define COOLANT_MIST_PIN GPIO_NUM_21 + +#define SPINDLE_PWM_PIN GPIO_NUM_25 +#define SPINDLE_ENABLE_PIN GPIO_NUM_4 + +// Relay operation +// Install Jumper near relay +// For spindle Use max RPM of 1 +// For PWM remove jumper and set MAX RPM to something higher ($30 setting) +// Interlock jumper along top edge needs to be installed for both versions +#define DEFAULT_SPINDLE_RPM_MAX 1 // Should be 1 for relay operation + +#define PROBE_PIN GPIO_NUM_22 + +#define X_LIMIT_PIN GPIO_NUM_36 +#define Y_LIMIT_PIN GPIO_NUM_39 +#define Z_LIMIT_PIN GPIO_NUM_34 + +#if (N_AXIS == 4) + #define A_LIMIT_PIN GPIO_NUM_35 + #define LIMIT_MASK B1111 +#else + #define LIMIT_MASK B0111 +#endif diff --git a/Grbl_Esp32/Machines/test_drive.h b/Grbl_Esp32/Machines/test_drive.h new file mode 100644 index 00000000..7bb6ebc3 --- /dev/null +++ b/Grbl_Esp32/Machines/test_drive.h @@ -0,0 +1,17 @@ +// Pin assignments (or lack thereof) for testing Grbl_ESP32. + +// It creates a basic 3 axis machine without actually driving +// I/O pins. Grbl will report that axes are moving, but no physical +// motor motion will occur. + +// This can be uploaded to an unattached ESP32 or attached to +// unknown hardware with no risk of pins trying to output signals +// into a short, etc that could dmamge the ESP32 + +// It can also be used to get the basic program running so OTA +// (over the air) firmware loading can be done. + + +#define MACHINE_NAME "MACHINE_DEFAULT - Demo Only No I/O!" + +#define LIMIT_MASK 0 // no limit pins diff --git a/Grbl_Esp32/Machines/tmc2130_pen.h b/Grbl_Esp32/Machines/tmc2130_pen.h new file mode 100644 index 00000000..04a801c9 --- /dev/null +++ b/Grbl_Esp32/Machines/tmc2130_pen.h @@ -0,0 +1,55 @@ +// Pin assignments (or lack thereof) for a pen plotter +// using Triaminic TMC2130 drivers. + +// Select a version to match your PCB +//#define MACHINE_V1 // version 1 PCB +#define MACHINE_V2 // version 2 PCB + +#ifdef MACHINE_V1 + #define MACHINE_NAME "ESP32_TMC2130_PEN V1" + #define X_LIMIT_PIN GPIO_NUM_2 +#else + #define MACHINE_NAME "ESP32_TMC2130_PEN V2" + #define X_LIMIT_PIN GPIO_NUM_32 +#endif + +#define USE_TRINAMIC // Using at least 1 trinamic driver + +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_26 +#define X_TRINAMIC // using SPI control +#define X_DRIVER_TMC2130 // Which Driver Type? +#define X_CS_PIN GPIO_NUM_17 //chip select +#define X_RSENSE 0.11f // .11 Ohm + +#define Y_STEP_PIN GPIO_NUM_14 +#define Y_DIRECTION_PIN GPIO_NUM_25 +#define Y_TRINAMIC // using SPI control +#define Y_DRIVER_TMC2130 // Which Driver Type? +#define Y_CS_PIN GPIO_NUM_16 //chip select +#define Y_RSENSE 0.11f // .11 Ohm + +// OK to comment out to use pin for other features +#define STEPPERS_DISABLE_PIN GPIO_NUM_13 + +#ifndef USE_SERVO_AXES // may be set in config.h + #define USE_SERVO_AXES +#endif + +#define SERVO_Z_PIN GPIO_NUM_27 +#define SERVO_Z_CHANNEL_NUM 5 +#define SERVO_Z_RANGE_MIN 0.0 +#define SERVO_Z_RANGE_MAX 5.0 +#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value +#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing +#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates + + +// Comment out servo pin and uncomment spindle pwm pin to use the servo PWM to control a spindle +/* +#define SPINDLE_PWM_PIN GPIO_NUM_27 +*/ + +// #define X_LIMIT_PIN See version section +#define Y_LIMIT_PIN GPIO_NUM_4 +#define LIMIT_MASK B11 diff --git a/Grbl_Esp32/atari_1020.h b/Grbl_Esp32/atari_1020.h deleted file mode 100644 index 94c0af96..00000000 --- a/Grbl_Esp32/atari_1020.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - atari_1020.h - Part of Grbl_ESP32 - - copyright (c) 2018 - Bart Dring This file was modified for use on the ESP32 - CPU. Do not use this with Grbl for atMega328P - - Grbl 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. - - Grbl 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 Grbl. If not, see . - - This contains all the special features required to control an - Atari 1010 Pen Plotter -*/ - -#define CPU_MAP_NAME "CPU_MAP_ATARI_1020" - -// ================== CPU MAP ====================== - #define USE_UNIPOLAR - - #define X_UNIPOLAR - #define X_PIN_PHASE_0 GPIO_NUM_13 - #define X_PIN_PHASE_1 GPIO_NUM_21 - #define X_PIN_PHASE_2 GPIO_NUM_16 - #define X_PIN_PHASE_3 GPIO_NUM_22 - - #define Y_UNIPOLAR - #define Y_PIN_PHASE_0 GPIO_NUM_25 - #define Y_PIN_PHASE_1 GPIO_NUM_27 - #define Y_PIN_PHASE_2 GPIO_NUM_26 - #define Y_PIN_PHASE_3 GPIO_NUM_32 - - - #define SOLENOID_DIRECTION_PIN GPIO_NUM_4 - #define SOLENOID_PEN_PIN GPIO_NUM_2 - #define SOLENOID_CHANNEL_NUM 6 - - #ifdef HOMING_CYCLE_0 - #undef HOMING_CYCLE_0 - #endif - #define HOMING_CYCLE_0 (1< -// !!!! Most Important Configuration Item !!!! -// #define the CPU map you want to use -// The CPU map is the main definition of the machine/controller you want to use -// These are typically found in the cpu_map.h file. -// See Github repo wiki for more details -#define CPU_MAP_TEST_DRIVE // these are defined in cpu_map.h +// It is no longer necessary to edit this file to choose +// a machine configuration; edit machine.h instead +#include "machine.h" + +// machine_common.h contains settings that do not change +#include "machine_common.h" // Number of axes defined (steppers, servos, etc) (valid range: 3 to 6) // Even if your machine only uses less than the minimum of 3, you should select 3 +#ifndef N_AXIS #define N_AXIS 3 +#endif #define VERBOSE_HELP // Currently this doesn't do anything #define GRBL_MSG_LEVEL MSG_LEVEL_INFO // what level of [MSG:....] do you want to see 0=all off @@ -62,7 +64,7 @@ Some features should not be changed. See notes below. //#define CONNECT_TO_SSID "your SSID" //#define SSID_PASSWORD "your SSID password" -#define ENABLE_BLUETOOTH // enable bluetooth +#define ENABLE_BLUETOOTH // enable bluetooth #define ENABLE_SD_CARD // enable use of SD Card to run jobs @@ -173,7 +175,7 @@ Some features should not be changed. See notes below. // Meaning that this allows for users with non-standard Cartesian machines, such as a lathe (x then z, // with no y), to configure the homing cycle behavior to their needs. // NOTE: The homing cycle is designed to allow sharing of limit pins, if the axes are not in the same -// cycle, but this requires some pin settings changes in cpu_map.h file. For example, the default homing +// cycle, but this requires some pin settings changes in the machine definition file. For example, the default homing // cycle can share the Z limit pin with either X or Y limit pins, since they are on different cycles. // By sharing a pin, this frees up a precious IO pin for other purposes. In theory, all axes limit pins // may be reduced to one pin, if all axes are homed with separate cycles, or vice versa, all three axes @@ -251,7 +253,7 @@ Some features should not be changed. See notes below. // analog pin 4. Only use this option if you require a second coolant control pin. // NOTE: The M8 flood coolant control pin on analog pin 3 will still be functional regardless. // ESP32 NOTE! This is here for reference only. You enable both M7 and M8 by assigning them a GPIO Pin -// in cpu_map.h +// in the machine definition file. //#define ENABLE_M7 // Don't uncomment...see above! // This option causes the feed hold input to act as a safety door switch. A safety door, when triggered, @@ -275,10 +277,10 @@ Some features should not be changed. See notes below. // #define COREXY // Default disabled. Uncomment to enable. // Enable using a servo for the Z axis on a pen type machine. -// You typically should not define a pin for the Z axis in cpu_map.h +// You typically should not define a pin for the Z axis in the machine definition file // You should configure your settings in servo_pen.h // #define USE_SERVO_AXES // the new method -// define your servo pin here or in cpu_map.h +// define your servo pin here or in the machine definition file //#define SERVO_PEN_PIN GPIO_NUM_27 // Enable using a solenoid for the Z axis on a pen type machine @@ -600,7 +602,7 @@ Some features should not be changed. See notes below. // Additional settings have been added to the original set that you see with the $$ command // Some senders may not be able to parse anything different from the original set // You can still set these like $33=5000, but you cannot read them back. -// Default is off to limit support issues...you can enable here or in your cpu_map +// Default is off to limit support issues...you can enable here or in your machine definition file // #define SHOW_EXTENDED_SETTINGS // Enable the '$I=(string)' build info write command. If disabled, any existing build info data must @@ -716,19 +718,4 @@ Some features should not be changed. See notes below. #define RPM_LINE_A3 9.528342e-03 #define RPM_LINE_B3 3.306286e+01 - -/* --------------------------------------------------------------------------------------- - OEM Single File Configuration Option - - Instructions: Paste the cpu_map and default setting definitions below without an enclosing - #ifdef. Comment out the CPU_MAP_xxx and DEFAULT_xxx defines at the top of this file, and - the compiler will ignore the contents of defaults.h and cpu_map.h and use the definitions - below. -*/ - -// Paste CPU_MAP definitions here. - -// Paste default settings definitions here. - - #endif diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h deleted file mode 100644 index 255c83d8..00000000 --- a/Grbl_Esp32/cpu_map.h +++ /dev/null @@ -1,1190 +0,0 @@ -/* - cpu_map.h - Header for system level commands and real-time processes - Part of Grbl - Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC - - 2018 - Bart Dring This file was modified for use on the ESP32 - CPU. Do not use this with Grbl for atMega328P - - Grbl 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. - Grbl 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 Grbl. If not, see . -*/ - -#ifndef cpu_map_h -//#define cpu_map_h - - /* - Not all pins can can work for all functions. - Check features like pull-ups, pwm, etc before - re-assigning numbers - - (gpio34-39) are inputs only and don't have software pullup/down functions - You MUST use external pull-ups or noise WILL cause problems. - - Unlike the AVR version certain pins are not forced into the same port. - Therefore, bit masks are not use the same way and typically should not be - changed. They are just preserved right now to make it easy to stay in sync - with AVR grbl - - */ - -//Set your pin definition -//let -1 to use default board pin -#define GRBL_SPI_SS -1 -#define GRBL_SPI_MOSI -1 -#define GRBL_SPI_MISO -1 -#define GRBL_SPI_SCK -1 -//Set your frequency -#define GRBL_SPI_FREQ 4000000 - -#ifdef CPU_MAP_TEST_DRIVE - /* - This is just a demo CPU_MAP for test driving. It creates a basic 3 axis machine, but - no actual i/o is used. It will appear that axes are moving, but they are virtual - - This can be uploaded to an unattached ESP32 or attached to unknown hardware. There is no risk - pins trying to output signals into a short, etc that could dmamge the ESP32 - - Assuming no changes have been made to the config.h file it is also a way to get he basic program - running so OTA (over the air) firmware loading can be done. - - */ - #define CPU_MAP_NAME "CPU_MAP_DEFAULT - Demo Only No I/O!" - - #define LIMIT_MASK 0 // no limit pins -#endif - -#ifdef CPU_MAP_ESP32 - // This is the CPU Map for the ESP32 Development Controller - // https://github.com/bdring/Grbl_ESP32_Development_Controller - // https://www.tindie.com/products/33366583/grbl_esp32-cnc-development-board-v35/ - - // Select the version (uncomment one of them) - //#define CPU_MAP_V3p5 // version 3.5 and earlier - #define CPU_MAP_V4 // version 4 or higher (in developement) - - #define USE_RMT_STEPS - - // It is OK to comment out any step and direction pins. This - // won't affect operation except that there will be no output - // form the pins. Grbl will virtually move the axis. This could - // be handy if you are using a servo, etc. for another axis. - #if (defined CPU_MAP_V4) - #define CPU_MAP_NAME "CPU_MAP_ESP32_V4" - #define X_DIRECTION_PIN GPIO_NUM_14 - #define Y_STEP_PIN GPIO_NUM_26 - #define Y_DIRECTION_PIN GPIO_NUM_15 - //#define COOLANT_FLOOD_PIN GPIO_NUM_25 - #define SPINDLE_PWM_PIN GPIO_NUM_2 - #define X_LIMIT_PIN GPIO_NUM_17 - #define Z_LIMIT_PIN GPIO_NUM_16 - #elif (defined CPU_MAP_V3p5) - #define CPU_MAP_NAME "CPU_MAP_ESP32_V3.5" - #define X_DIRECTION_PIN GPIO_NUM_26 - #define Y_STEP_PIN GPIO_NUM_14 - #define Y_DIRECTION_PIN GPIO_NUM_25 - //#define COOLANT_FLOOD_PIN GPIO_NUM_16 - #define SPINDLE_PWM_PIN GPIO_NUM_17 - #define X_LIMIT_PIN GPIO_NUM_2 - #define Z_LIMIT_PIN GPIO_NUM_15 - #endif - - #define X_STEP_PIN GPIO_NUM_12 - - #define Z_STEP_PIN GPIO_NUM_27 - #define Z_DIRECTION_PIN GPIO_NUM_33 - - // OK to comment out to use pin for other features - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 - - //#define COOLANT_MIST_PIN GPIO_NUM_21 - #define USER_DIGITAL_PIN_1 GPIO_NUM_21 - #define USER_DIGITAL_PIN_2 GPIO_NUM_25 - - - #define SPINDLE_PWM_CHANNEL 0 - #define SPINDLE_PWM_BIT_PRECISION 8 - #define SPINDLE_ENABLE_PIN GPIO_NUM_22 - - // see versions for X and Z - #define Y_LIMIT_PIN GPIO_NUM_4 - #define LIMIT_MASK B111 - - #define PROBE_PIN GPIO_NUM_32 - - #define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // needs external pullup - #define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup - #define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup - #define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup -#endif - -#ifdef CPU_MAP_ESPDUINO_32 - // !!!! Experimental Untested !!!!! - // This is a CPU MAP for ESPDUINO-32 Boards and Protoneer V3 boards - // Note: Probe pin is mapped, but will require a 10k external pullup to 3.3V to work. - - // Rebooting...See this issue https://github.com/bdring/Grbl_Esp32/issues/314 - - #define CPU_MAP_NAME "CPU_MAP_ESPDUINO_32" - - #define USE_RMT_STEPS - - #define X_STEP_PIN GPIO_NUM_26 - #define X_DIRECTION_PIN GPIO_NUM_16 - - #define Y_STEP_PIN GPIO_NUM_25 - #define Y_DIRECTION_PIN GPIO_NUM_27 - - #define Z_STEP_PIN GPIO_NUM_17 - #define Z_DIRECTION_PIN GPIO_NUM_14 - - // OK to comment out to use pin for other features - #define STEPPERS_DISABLE_PIN GPIO_NUM_12 - - #define SPINDLE_PWM_PIN GPIO_NUM_19 - #define SPINDLE_PWM_CHANNEL 0 - #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - #define SPINDLE_DIR_PIN GPIO_NUM_18 - - #define COOLANT_FLOOD_PIN GPIO_NUM_34 - #define COOLANT_MIST_PIN GPIO_NUM_36 - - #define X_LIMIT_PIN GPIO_NUM_13 - #define Y_LIMIT_PIN GPIO_NUM_5 - #define Z_LIMIT_PIN GPIO_NUM_19 - #define LIMIT_MASK B111 - - #define PROBE_PIN GPIO_NUM_39 - - // comment out #define IGNORE_CONTROL_PINS in config.h to use control pins - #define CONTROL_RESET_PIN GPIO_NUM_2 - #define CONTROL_FEED_HOLD_PIN GPIO_NUM_4 - #define CONTROL_CYCLE_START_PIN GPIO_NUM_35 // ESP32 needs external pullup -#endif - -#ifdef CPU_MAP_ESP32_ESC_SPINDLE - // This is an example of using a Brushless DC Hobby motor as - // a spindle motor - // See this wiki page for more info - // https://github.com/bdring/Grbl_Esp32/wiki/BESC-Spindle-Feature - - #define CPU_MAP_NAME "CPU_MAP_ESP32_ESC_SPINDLE" - - #define SHOW_EXTENDED_SETTINGS - - #define USE_RMT_STEPS - - #define X_STEP_PIN GPIO_NUM_12 - #define X_DIRECTION_PIN GPIO_NUM_14 - - #define Y_STEP_PIN GPIO_NUM_26 - #define Y_DIRECTION_PIN GPIO_NUM_15// #define Y_STEP_PIN (see versions above) - - #define Z_STEP_PIN GPIO_NUM_27 - #define Z_DIRECTION_PIN GPIO_NUM_33 - - // OK to comment out to use pin for other features - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 - - #define SPINDLE_PWM_PIN GPIO_NUM_2 - #define SPINDLE_ENABLE_PIN GPIO_NUM_22 - #define SPINDLE_PWM_CHANNEL 0 - - // Begin RC ESC Based Spindle Information ====================== - #define SPINDLE_PWM_BIT_PRECISION 16 // 16 bit recommended for ESC (don't change) - - - /* - Important ESC Settings - $33=50 // Hz this is the typical good frequency for an ESC - #define DEFAULT_SPINDLE_FREQ 5000.0 // $33 Hz (extended set) - - Determine the typical min and max pulse length of your ESC - min_pulse is typically 1ms (0.001 sec) or less - max_pulse is typically 2ms (0.002 sec) or more - - determine PWM_period. It is (1/freq) if freq = 50...period = 0.02 - - determine pulse length for min_pulse and max_pulse in percent. - - (pulse / PWM_period) - - min_pulse = (0.001 / 0.02) = 0.05 = 5% so ... $34 and $35 = 5.0 - max_pulse = (0.002 / .02) = 0.1 = 10% so ... $36=10 - - */ - #define DEFAULT_SPINDLE_FREQ 50.0 - #define DEFAULT_SPINDLE_OFF_VALUE 5.0 - #define DEFAULT_SPINDLE_MIN_VALUE 5.0 - #define DEFAULT_SPINDLE_MAX_VALUE 10.0 - - - - - // End RC ESC Based Spindle #defines =========================== - - #define X_LIMIT_PIN GPIO_NUM_17 - #define Y_LIMIT_PIN GPIO_NUM_4 - #define Z_LIMIT_PIN GPIO_NUM_16 - #define LIMIT_MASK B111 - - #define PROBE_PIN GPIO_NUM_32 - - #define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // needs external pullup - #define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup - #define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup - #define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup -#endif - -#ifdef CPU_MAP_PEN_LASER // The Buildlog.net pen laser controller V1 & V2 - - // For pen mode be sure to uncomment #define USE_PEN_SERVO in config.h - // For solenoid mode be sure to uncomment #define USE_PEN_SERVO in config.h - // For laser mode, you do not need to change anything - // Note: You can use all 3 modes at the same time if you want - - #define CPU_MAP_NAME "CPU_MAP_PEN_LASER" - - #define USE_RMT_STEPS - - // Pick a board version - //#define PEN_LASER_V1 - #define PEN_LASER_V2 - - #define X_STEP_PIN GPIO_NUM_12 - #define X_DIRECTION_PIN GPIO_NUM_26 - - #define Y_STEP_PIN GPIO_NUM_14 - #define Y_DIRECTION_PIN GPIO_NUM_25 - - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 - - #ifdef PEN_LASER_V1 - #define X_LIMIT_PIN GPIO_NUM_2 - #endif - #ifdef PEN_LASER_V2 - #define X_LIMIT_PIN GPIO_NUM_15 - #endif - #define Y_LIMIT_PIN GPIO_NUM_4 - #define LIMIT_MASK B11 - - // If SPINDLE_PWM_PIN is commented out, this frees up the pin, but Grbl will still - // use a virtual spindle. Do not comment out the other parameters for the spindle. - #define SPINDLE_PWM_PIN GPIO_NUM_17 // Laser PWM - #define SPINDLE_PWM_CHANNEL 0 - #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - - - #define USING_SERVO // uncomment to use this feature - //#define USING_SOLENOID // uncomment to use this feature - - #ifdef USING_SERVO - #define USE_SERVO_AXES - #define SERVO_Z_PIN GPIO_NUM_27 - #define SERVO_Z_CHANNEL_NUM 3 - #define SERVO_Z_RANGE_MIN 0 - #define SERVO_Z_RANGE_MAX 10 - #endif - - #ifdef USING_SOLENOID - #define USE_PEN_SOLENOID - #define SOLENOID_PEN_PIN GPIO_NUM_16 - #define SOLENOID_CHANNEL_NUM 6 - #endif - - - // defaults - #define DEFAULT_STEP_PULSE_MICROSECONDS 3 - #define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // stay on - - #define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t - #define DEFAULT_DIRECTION_INVERT_MASK 0 // uint8_t - #define DEFAULT_INVERT_ST_ENABLE 0 // boolean - #define DEFAULT_INVERT_LIMIT_PINS 1 // boolean - #define DEFAULT_INVERT_PROBE_PIN 0 // boolean - - #define DEFAULT_STATUS_REPORT_MASK 1 - - #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm - #define DEFAULT_ARC_TOLERANCE 0.002 // mm - #define DEFAULT_REPORT_INCHES 0 // false - - #define DEFAULT_SOFT_LIMIT_ENABLE 0 // false - #define DEFAULT_HARD_LIMIT_ENABLE 0 // false - - #define DEFAULT_HOMING_ENABLE 0 - #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir Z, negative X,Y - #define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min - #define DEFAULT_HOMING_SEEK_RATE 1000.0 // mm/min - #define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k) - #define DEFAULT_HOMING_PULLOFF 3.0 // mm - - #define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm - #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm - - #define DEFAULT_LASER_MODE 0 // false - - #define DEFAULT_X_STEPS_PER_MM 80 - #define DEFAULT_Y_STEPS_PER_MM 80 - #define DEFAULT_Z_STEPS_PER_MM 100.0 // This is percent in servo mode...used for calibration - - #define DEFAULT_X_MAX_RATE 5000.0 // mm/min - #define DEFAULT_Y_MAX_RATE 5000.0 // mm/min - #define DEFAULT_Z_MAX_RATE 5000.0 // mm/min - - #define DEFAULT_X_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_Y_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 - #define DEFAULT_Z_ACCELERATION (50.0*60*60) - - #define DEFAULT_X_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. - #define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value. - #define DEFAULT_Z_MAX_TRAVEL 100.0 // This is percent in servo mode...used for calibration - - -#endif - -#ifdef CPU_MAP_MIDTBOT // Buildlog.net midtbot - - #define CPU_MAP_NAME "CPU_MAP_MIDTBOT" - - #define USE_RMT_STEPS - - #define X_STEP_PIN GPIO_NUM_12 - #define Y_STEP_PIN GPIO_NUM_14 - - #define X_DIRECTION_PIN GPIO_NUM_26 - #define Y_DIRECTION_PIN GPIO_NUM_25 - - #ifndef COREXY // maybe set in config.h - #define COREXY - #endif - - #define STEPPERS_DISABLE_PIN GPIO_NUM_13 - - #define X_LIMIT_PIN GPIO_NUM_2 - #define Y_LIMIT_PIN GPIO_NUM_4 - #define LIMIT_MASK B11 - - #ifndef USE_SERVO_AXES // maybe set in config.h - #define USE_SERVO_AXES - #endif - - #define SERVO_Z_PIN GPIO_NUM_27 - #define SERVO_Z_CHANNEL_NUM 5 - #define SERVO_Z_RANGE_MIN 0.0 - #define SERVO_Z_RANGE_MAX 5.0 - #define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value - #define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing - #define SERVO_Z_MPOS false // will not use mpos, uses work coordinates - - #ifndef IGNORE_CONTROL_PINS // maybe set in config.h - #define IGNORE_CONTROL_PINS - #endif - - - - // redefine some stuff from config.h - #ifdef HOMING_CYCLE_0 - #undef HOMING_CYCLE_0 - #endif - #define HOMING_CYCLE_0 (1<. - - ==================================================================== - - See custom_machine_templete.cpp for getting started creating custom - machines - -*/ - -// ================ config.h overrides ======================================== -/* - -If you want to make some changes to config.h, it might be easier to do it here -so all your changes are in your files. - -example to change baud rate -#ifdef BAUD_RATE - #undef BAUDRATE -#endif -#define BAUD_RATE 9600 - -example to change the number of axes -#idef N_AXIS - #undef N_AXIS -#endif -#define N_AXIS 4 - - -*/ - - -// =============== CPU MAP ======================== -// Look at cpu_map.h for all the things that can go here - - -#define CPU_MAP_NAME "CPU_MAP_MY_MACHINE" - -#define LIMIT_MASK B111 // you need this with as many switches you are using - -// ============== Enable custom features ======================= - -// #define #USE_MACHINE_INIT -// #define USE_CUSTOM_HOMING -// #define USE_KINEMATICS -// #define USE_FWD_KINEMATIC -// #define USE_TOOL_CHANGE -// #define USE_M30 -// #define USE_MACHINE_TRINAMIC_INIT - -// ===================== $$ Defaults ========================================== -/* These are default values for any of the $$ settings. - This will automatically set them when you upload new firmware or if you - reset them with $RST=$. - All default values are set in the defaults.h file. You would only need to - put values here that are different from those values - Below are a few examples -*/ -#define DEFAULT_SPINDLE_FREQ 2000.0 -#define DEFAULT_X_MAX_TRAVEL 100.0 - -#ifndef custom_machine_template_h // !!!!!!!!!!!!!!! Change this to your file !!!!!!!!!!!!! - #define custom_machine_template_h // !!! here too !!!! - - #include "grbl.h" - - // ================ Function Prototypes ================ - void machine_init(); - bool user_defined_homing(); - void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *position); - void forward_kinematics(float *position); - void kinematics_post_homing(); - void user_tool_change(uint8_t new_tool); - void user_defined_macro(uint8_t index); - void user_m30(); - void machine_trinamic_setup(); - -#endif - diff --git a/Grbl_Esp32/gcode.cpp b/Grbl_Esp32/gcode.cpp index c318b825..03a3b113 100644 --- a/Grbl_Esp32/gcode.cpp +++ b/Grbl_Esp32/gcode.cpp @@ -344,11 +344,11 @@ uint8_t gc_execute_line(char *line, uint8_t client) break; } break; - case 6: // too change + case 6: // tool change word_bit = MODAL_GROUP_M6; gc_block.modal.tool_change = TOOL_CHANGE; #ifdef USE_TOOL_CHANGE - //tool_change(gc_state.tool); + //user_tool_change(gc_state.tool); #endif break; case 7: diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index 37e6bbcd..5a6b1729 100644 --- a/Grbl_Esp32/grbl.h +++ b/Grbl_Esp32/grbl.h @@ -34,7 +34,6 @@ // Define the Grbl system include files. NOTE: Do not alter organization. #include "config.h" #include "nuts_bolts.h" -#include "cpu_map.h" #include "tdef.h" #include "defaults.h" @@ -92,3 +91,25 @@ #include "grbl_unipolar.h" #endif +// Called if USE_MACHINE_INIT is defined +void machine_init(); + +// Called if USE_CUSTOM_HOMING is defined +bool user_defined_homing(); + +// Called if USE_KINEMATICS is defined +void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *position); +bool kinematics_pre_homing(uint8_t cycle_mask); +void kinematics_post_homing(); + +// Called if USE_FWD_KINEMATIC is defined +void forward_kinematics(float *position); + +// Called if MACRO_BUTTON_0_PIN or MACRO_BUTTON_1_PIN or MACRO_BUTTON_2_PIN is defined +void user_defined_macro(uint8_t index); + +// Called if USE_M30 is defined +void user_m30(); + +// Called if USE_TOOL_CHANGE is defined +void user_tool_change(uint8_t new_tool); diff --git a/Grbl_Esp32/grbl_trinamic.cpp b/Grbl_Esp32/grbl_trinamic.cpp index c9fde27f..00d09217 100644 --- a/Grbl_Esp32/grbl_trinamic.cpp +++ b/Grbl_Esp32/grbl_trinamic.cpp @@ -27,7 +27,7 @@ The PCB must be designed for this, with SDO pins being coonect to the next driver's SDI pin. The final SDO goes back to the controller. - This is setup in cpu_map. + This is setup in the machine definition file (Machines/*.h). add #define TRINAMIC_DAISY_CHAIN to your map Make every axis CS_PIN definition be for the same pin like this... #define X_CS_PIN GPIO_NUM_17 @@ -302,4 +302,4 @@ void trinamic_stepper_enable(bool enable) { } -#endif \ No newline at end of file +#endif diff --git a/Grbl_Esp32/grbl_trinamic.h b/Grbl_Esp32/grbl_trinamic.h index 871c77db..7f6f7f73 100644 --- a/Grbl_Esp32/grbl_trinamic.h +++ b/Grbl_Esp32/grbl_trinamic.h @@ -31,6 +31,9 @@ void trinamic_change_settings(); void trinamic_test_response(uint8_t result, const char *axis); void trinamic_stepper_enable(bool enable); + #ifdef USE_MACHINE_TRINAMIC_INIT + void machine_trinamic_setup(); + #endif #endif -#endif \ No newline at end of file +#endif // GRBL_TRIAMINIC_h diff --git a/Grbl_Esp32/machine.h b/Grbl_Esp32/machine.h new file mode 100644 index 00000000..f4a56517 --- /dev/null +++ b/Grbl_Esp32/machine.h @@ -0,0 +1,34 @@ +// Configure for a specific machine by including one or more +// machine definition files as described below. Machine +// definition files assign CPU pins to machine functions +// according to the wiring of interface boards. + +#ifndef _machine_h +#define _machine_h + +// For initial testing, start with this one which disables all I/O pins +// #include "Machines/test_drive.h" + +// For actual use, select the appropriate board from Machines/, +// or create your own, for example: +// #include "Machines/3x_v4.h" +#include "Machines/spi_daisy_4x.h" + +// Some configurations use two files, the first assigning pins +// and the second providing additional customization, for example: +// #include "Machines/3x_v4.h" +// #include "Machines/3x_esc_spindle.h" + + +/* --------------------------------------------------------------------------------------- + OEM Single File Configuration Option + + Instructions: Comment out all #include's above and paste the machine definition and + any default settings that you wish to override below. +*/ + +// Paste machine definitions here. + +// Paste default settings override definitions here. + +#endif _machine_h diff --git a/Grbl_Esp32/machine_common.h b/Grbl_Esp32/machine_common.h new file mode 100644 index 00000000..f35c3a69 --- /dev/null +++ b/Grbl_Esp32/machine_common.h @@ -0,0 +1,65 @@ +#ifndef _machine_common_h +#define _machine_common_h + +#define USE_RMT_STEPS + +#ifndef SPINDLE_PWM_BIT_PRECISION +#define SPINDLE_PWM_BIT_PRECISION 8 +#endif + +#define SPINDLE_PWM_MAX_VALUE ((1<