Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tickle me laser #923

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ __vm/
*.vcxproj.filters
*.suo
Grbl_Esp32.ino.cpp
/packages
/packages
4 changes: 2 additions & 2 deletions Grbl_Esp32/Grbl_Esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include "src/Grbl.h"

void setup() {
grbl_init();
grbl_init();
}

void loop() {
run_once();
run_once();
}
Binary file added Grbl_Esp32/Grbl_Esp32.ino.esp32.bin
Binary file not shown.
81 changes: 81 additions & 0 deletions Grbl_Esp32/src/Eeprom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Eeprom.cpp - Coordinate data stored in EEPROM
Part of Grbl
Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC

2018 - Bart Dring This file was modifed 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 <http://www.gnu.org/licenses/>.
*/

#include "Grbl.h"

void memcpy_to_eeprom_with_checksum(unsigned int destination, const char* source, unsigned int size) {
unsigned char checksum = 0;
for (; size > 0; size--) {
unsigned char data = static_cast<unsigned char>(*source++);
// Note: This checksum calculation is broken as described below.
checksum = (checksum << 1) || (checksum >> 7);
checksum += data;
EEPROM.write(destination++, *(source++));
}
EEPROM.write(destination, checksum);
EEPROM.commit();
}

int memcpy_from_eeprom_with_old_checksum(char* destination, unsigned int source, unsigned int size) {
unsigned char data, checksum = 0;
for (; size > 0; size--) {
data = EEPROM.read(source++);
// Note: This checksum calculation is broken - the || should be just | -
// thus making the checksum very weak.
// We leave it as-is so we can read old data after a firmware upgrade.
// The new storage format uses the tagged NVS mechanism, avoiding this bug.
checksum = (checksum << 1) || (checksum >> 7);
checksum += data;
*(destination++) = data;
}
return (checksum == EEPROM.read(source));
}
int memcpy_from_eeprom_with_checksum(char* destination, unsigned int source, unsigned int size) {
unsigned char data, checksum = 0;
for (; size > 0; size--) {
data = EEPROM.read(source++);
checksum = (checksum << 1) | (checksum >> 7);
checksum += data;
*(destination++) = data;
}
return (checksum == EEPROM.read(source));
}

// Read selected coordinate data from EEPROM. Updates pointed coord_data value.
// This is now a compatibility routine that is used to propagate coordinate data
// in the old EEPROM format to the new tagged NVS format.
bool old_settings_read_coord_data(uint8_t coord_select, float* coord_data) {
uint32_t addr = coord_select * (sizeof(float) * N_AXIS + 1) + EEPROM_ADDR_PARAMETERS;
if (!(memcpy_from_eeprom_with_old_checksum((char*)coord_data, addr, sizeof(float) * N_AXIS)) &&
!(memcpy_from_eeprom_with_checksum((char*)coord_data, addr, sizeof(float) * MAX_N_AXIS))) {
// Reset with default zero vector
clear_vector_float(coord_data);
// The old code used to rewrite the zeroed data but now that is done
// elsewhere, in a different format.
return false;
}
return true;
}

// Allow iteration over CoordIndex values
CoordIndex& operator ++ (CoordIndex& i) {
i = static_cast<CoordIndex>(static_cast<uint8_t>(i) + 1);
return i;
}
61 changes: 61 additions & 0 deletions Grbl_Esp32/src/Eeprom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

/*
Eeprom.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 modifed 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 <http://www.gnu.org/licenses/>.
*/

#include "Grbl.h"

// Define EEPROM memory address location values for saved coordinate data.
const int EEPROM_SIZE = 1024U;
const int EEPROM_ADDR_PARAMETERS = 512U;

//unsigned char eeprom_get_char(unsigned int addr);
//void eeprom_put_char(unsigned int addr, unsigned char new_value);
void memcpy_to_eeprom_with_checksum(unsigned int destination, const char* source, unsigned int size);
int memcpy_from_eeprom_with_checksum(char* destination, unsigned int source, unsigned int size);
int memcpy_from_eeprom_with_old_checksum(char* destination, unsigned int source, unsigned int size);

// Reads selected coordinate data from EEPROM
bool old_settings_read_coord_data(uint8_t coord_select, float* coord_data);

// Various places in the code access saved coordinate system data
// by a small integer index according to the values below.
enum CoordIndex : uint8_t{
Begin = 0,
G54 = Begin,
G55,
G56,
G57,
G58,
G59,
// To support 9 work coordinate systems it would be necessary to define
// the following 3 and modify GCode.cpp to support G59.1, G59.2, G59.3
// G59_1,
// G59_2,
// G59_3,
NWCSystems,
G28 = NWCSystems,
G30,
// G92_2,
// G92_3,
End,
};
// Allow iteration over CoordIndex values
CoordIndex& operator ++ (CoordIndex& i);
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// !!! For initial testing, start with test_drive.h which disables
// all I/O pins
// #include "Machines/atari_1020.h"
# include "Machines/test_drive.h"
# include "Machines/lmi.h"

// !!! For actual use, change the line above to select a board
// from Machines/, for example:
Expand Down
59 changes: 59 additions & 0 deletions Grbl_Esp32/src/Machines/3axis_rs485.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once
// clang-format off

/*
3axis_xyx.h
Part of Grbl_ESP32

This is a general XYZ-axis RS-485 CNC machine. The schematic is quite
easy, you basically need a MAX485 wired through a logic level converter
for the VFD, and a few pins wired through an ULN2803A to the external
stepper drivers. It's common to have a dual gantry for the Y axis.

Optional limit pins are slightly more difficult, as these require a
Schmitt trigger and optocouplers.

2020 - Stefan de Bruijn

Grbl_ESP32 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_ESP32. If not, see <http://www.gnu.org/licenses/>.
*/

#define MACHINE_NAME "ESP32_XYZ_RS485"
#define X_STEP_PIN GPIO_NUM_4 // labeled X
#define X_DIRECTION_PIN GPIO_NUM_16 // labeled X
#define Y_STEP_PIN GPIO_NUM_17 // labeled Y
#define Y_DIRECTION_PIN GPIO_NUM_18 // labeled Y
#define Y2_STEP_PIN GPIO_NUM_19 // labeled Y2
#define Y2_DIRECTION_PIN GPIO_NUM_21 // labeled Y2
#define Z_STEP_PIN GPIO_NUM_22 // labeled Z
#define Z_DIRECTION_PIN GPIO_NUM_23 // labeled Z

#define SPINDLE_TYPE SpindleType::H2A
#define VFD_RS485_TXD_PIN GPIO_NUM_13 // RS485 TX
#define VFD_RS485_RTS_PIN GPIO_NUM_15 // RS485 RTS
#define VFD_RS485_RXD_PIN GPIO_NUM_2 // RS485 RX

#define X_LIMIT_PIN GPIO_NUM_33
#define Y_LIMIT_PIN GPIO_NUM_32
#define Y2_LIMIT_PIN GPIO_NUM_35
#define Z_LIMIT_PIN GPIO_NUM_34

// Set $Homing/Cycle0=X and $Homing/Cycle=XY

#define PROBE_PIN GPIO_NUM_14 // labeled Probe
#define CONTROL_RESET_PIN GPIO_NUM_27 // labeled Reset
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_26 // labeled Hold
#define CONTROL_CYCLE_START_PIN GPIO_NUM_25 // labeled Start

// #define VFD_DEBUG_MODE
126 changes: 126 additions & 0 deletions Grbl_Esp32/src/Machines/6_pack_stepstick_XYZ_v1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#pragma once
// clang-format off

/*
6_pack_stepstick_XYZ_v1.h

Covers all V1 versions V1p0, V1p1, etc

Part of Grbl_ESP32
Pin assignments for the ESP32 I2S 6-axis board
2018 - Bart Dring
2020 - Mitch Bradley
2020 - Michiyasu Odaki
Grbl_ESP32 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_ESP32. If not, see <http://www.gnu.org/licenses/>.
*/
#define MACHINE_NAME "6 Pack Controller StepStick XYZ"

#define N_AXIS 3

// === Special Features

// I2S (steppers & other output-only pins)
#define USE_I2S_OUT
#define USE_I2S_STEPS
//#define DEFAULT_STEPPER ST_I2S_STATIC
// === Default settings
#define DEFAULT_STEP_PULSE_MICROSECONDS I2S_OUT_USEC_PER_PULSE

#define USE_STEPSTICK // makes sure MS1,2,3 !reset and !sleep are set

#define I2S_OUT_BCK GPIO_NUM_22
#define I2S_OUT_WS GPIO_NUM_17
#define I2S_OUT_DATA GPIO_NUM_21


// Motor Socket #1
#define X_DISABLE_PIN I2SO(0)
#define X_DIRECTION_PIN I2SO(1)
#define X_STEP_PIN I2SO(2)
#define X_STEPPER_MS3 I2SO(3)

// Motor Socket #2
#define Y_DIRECTION_PIN I2SO(4)
#define Y_STEP_PIN I2SO(5)
#define Y_STEPPER_MS3 I2SO(6)
#define Y_DISABLE_PIN I2SO(7)

// Motor Socket #3
#define Z_DISABLE_PIN I2SO(8)
#define Z_DIRECTION_PIN I2SO(9)
#define Z_STEP_PIN I2SO(10)
#define Z_STEPPER_MS3 I2SO(11)

/*
Socket I/O reference
The list of modules is here...
https://github.com/bdring/6-Pack_CNC_Controller/wiki/CNC-I-O-Module-List
Click on each module to get example for using the modules in the sockets


Socket #1
#1 GPIO_NUM_33
#2 GPIO_NUM_32
#3 GPIO_NUM_35 (input only)
#4 GPIO_NUM_34 (input only)

Socket #2
#1 GPIO_NUM_2
#2 GPIO_NUM_25
#3 GPIO_NUM_39 (input only)
#4 GPIO_NUM_36 (input only)

Socket #3
#1 GPIO_NUM_26
#2 GPIO_NUM_4
#3 GPIO_NUM_16
#4 GPIO_NUM_27

Socket #4
#1 GPIO_NUM_14
#2 GPIO_NUM_13
#3 GPIO_NUM_15
#4 GPIO_NUM_12

Socket #5
#1 I2SO(24) (output only)
#2 I2SO(25) (output only)
#3 I2SO26) (output only)

*/


// 4x Input Module in Socket #1
// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
#define X_LIMIT_PIN GPIO_NUM_33
#define Y_LIMIT_PIN GPIO_NUM_32
#define Z_LIMIT_PIN GPIO_NUM_35


// // 4x Input Module in Socket #2
// // https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
// #define X_LIMIT_PIN GPIO_NUM_2
// #define Y_LIMIT_PIN GPIO_NUM_25
// #define Z_LIMIT_PIN GPIO_NUM_39

// // 4x Input Module in Socket #3
// // https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
// #define CONTROL_CYCLE_START_PIN GPIO_NUM_26
// #define CONTROL_FEED_HOLD_PIN GPIO_NUM_4
// #define CONTROL_RESET_PIN GPIO_NUM_16
// #define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_27
// //#define INVERT_CONTROL_PIN_MASK B0000

// ================= Setting Defaults ==========================
#define DEFAULT_X_STEPS_PER_MM 800
#define DEFAULT_Y_STEPS_PER_MM 800
#define DEFAULT_Z_STEPS_PER_MM 800
Loading