From 7cf9e889959ee87a11699aa0aed4d23341481078 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 16 Nov 2023 15:42:54 +0100 Subject: [PATCH 01/11] add test stepper --- platformio.ini | 1 + src/main.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9724c56..590c0d3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -54,6 +54,7 @@ lib_deps = bblanchon/ArduinoJson@^6.21.3 ; JSON serializer et deserializer m5stack/M5Stack@^0.4.5 ; M5 Lib m5stack/M5GFX@^0.1.9 ; M5 Lib pour le LCD + m5stack/Module_GRBL_13.2@^0.0.3 ; M5 Lib pour Stepper (GRBL) ; example: ; erropix/ESP32 AnalogWrite@0.2 diff --git a/src/main.cpp b/src/main.cpp index bf9fbf6..bdd6c43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,85 @@ -#include "Program.h" -Program* program; +// #include "Program.h" +// Program* program; + +// void setup() { +// program = new Program(); +// } + +// void loop() { +// program->loop(); +// } + +#include + +#include +#include "Module_GRBL_13.2.h" + + +#define STEPMOTOR_I2C_ADDR 0x70 +// #define STEPMOTOR_I2C_ADDR 0x71 + +Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR); + +/** + * @brief initialise le GRBL pour le stepper + * + * @param speed vitesse par defaut du moteur + * @param pas nombre de pas par mm du moteur + * @param accel vitesse d'acceleration du mptuer (mm/sec²) + * @param mode mode de fonctionnement (defaut = distance) absolute + */ +void init(int speed, double pas, int accel ,String mode = "distance"){ + _GRBL.Init(&Wire); + _GRBL.setMode(mode); + Serial.print("3"); + char* s = ""; + Serial.print("4"); + printf(s,"$0=%d", pas); // step/mm + Serial.print("5"); + _GRBL.sendGcode(s); + printf(s,"$4=%f", speed); // speed + _GRBL.sendGcode(s); + printf(s,"$8=%d", pas); // acceleration, mm/sec^2 + _GRBL.sendGcode(s); +} void setup() { - program = new Program(); + M5.begin(); + M5.Power.begin(); + Wire.begin(21, 22); + Serial.begin(115200); + M5.Lcd.setTextColor(WHITE, BLACK); + M5.Lcd.setTextSize(3); + M5.lcd.setBrightness(100); + M5.Lcd.setCursor(80, 40); + M5.Lcd.println("GRBL 13.2"); + M5.Lcd.setCursor(50, 80); + M5.Lcd.println("Press Btn A/B"); + M5.Lcd.setCursor(50, 120); + delay(1000); + M5.Lcd.println("Control Motor"); + Serial.println("\n\n\n\n\n0"); + init(100, 755.906, 50); + Serial.println("\n\n\n\n\n000000000000000000"); } + + void loop() { - program->loop(); + if (M5.BtnA.wasPressed()) + { + Serial.print(_GRBL.readStatus()); + _GRBL.setMotor(5, 5, 5, 200); + _GRBL.setMotor(0, 0, 0, 200); + } + + if (M5.BtnB.wasPressed()) { + _GRBL.sendGcode("G1 X5Y5Z5"); + _GRBL.sendGcode("G1 X0Y0Z0"); + } + + if (M5.BtnC.wasReleased()) { + _GRBL.unLock(); + } + M5.update(); } From 8e8df97e685bced9fda61b54f7cd58b96ad3febf Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 16 Nov 2023 16:07:29 +0100 Subject: [PATCH 02/11] add init fonction --- src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bdd6c43..51ccc6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,9 +58,7 @@ void setup() { M5.Lcd.setCursor(50, 120); delay(1000); M5.Lcd.println("Control Motor"); - Serial.println("\n\n\n\n\n0"); init(100, 755.906, 50); - Serial.println("\n\n\n\n\n000000000000000000"); } From eb3a6426cd59335341fb756da44a15e80806bd0f Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 17 Nov 2023 11:14:26 +0100 Subject: [PATCH 03/11] add stepper config --- config.ini | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config.ini b/config.ini index dff2d75..564b40d 100644 --- a/config.ini +++ b/config.ini @@ -14,3 +14,10 @@ build_flags = -D MONITOR_SPEED=${config.monitor_speed} ; DO NOT TOUCH --- END -D WAITING_WIFI_DELAY=1000 + + ;;;;;;;;;;;;;;;;;;;;;; + ;;; stepper config ;;; + ;;;;;;;;;;;;;;;;;;;;;; + -D STEPER_ACC=50 + -D STEPER_PAS=755.906 + -D STEPER_SPEED=100 From 07528f75f29f33fb29c283667a1d3e68dae1d0a8 Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 17 Nov 2023 11:16:41 +0100 Subject: [PATCH 04/11] add file archi --- lib/Stepper/include/Stepper.h | 0 lib/Stepper/src/Stepper.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/Stepper/include/Stepper.h create mode 100644 lib/Stepper/src/Stepper.cpp diff --git a/lib/Stepper/include/Stepper.h b/lib/Stepper/include/Stepper.h new file mode 100644 index 0000000..e69de29 diff --git a/lib/Stepper/src/Stepper.cpp b/lib/Stepper/src/Stepper.cpp new file mode 100644 index 0000000..e69de29 From d077deb960697e2336fcc0d76d31e9772dd38f5e Mon Sep 17 00:00:00 2001 From: Clement Date: Fri, 17 Nov 2023 11:17:04 +0100 Subject: [PATCH 05/11] main test GRBL --- src/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 51ccc6e..1af44f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,10 +58,14 @@ void setup() { M5.Lcd.setCursor(50, 120); delay(1000); M5.Lcd.println("Control Motor"); - init(100, 755.906, 50); + init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); } - +void mouveForward(int mm = 5){ + char* s = ""; + printf(s, "G1 X%d", mm); + _GRBL.sendGcode(s); +} void loop() { if (M5.BtnA.wasPressed()) From 38415c2da5ba7865ff07fccc55947f6f84bd5031 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 23 Nov 2023 12:04:37 +0100 Subject: [PATCH 06/11] change config value --- config.ini | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config.ini b/config.ini index 564b40d..7a3a1c1 100644 --- a/config.ini +++ b/config.ini @@ -18,6 +18,7 @@ build_flags = ;;;;;;;;;;;;;;;;;;;;;; ;;; stepper config ;;; ;;;;;;;;;;;;;;;;;;;;;; - -D STEPER_ACC=50 - -D STEPER_PAS=755.906 - -D STEPER_SPEED=100 + -D STEPER_ACC=200 + ;-D STEPER_PAS=755.906 ; = 65mm + -D STEPER_PAS=58 ; = 5mm + -D STEPER_SPEED=12000 From 0a43f65ce2b74aed82337829069ecbd09b3c63f8 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 23 Nov 2023 12:05:01 +0100 Subject: [PATCH 07/11] gestion initialisation --- src/main.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1af44f2..21f9b7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,18 +29,26 @@ Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR); * @param mode mode de fonctionnement (defaut = distance) absolute */ void init(int speed, double pas, int accel ,String mode = "distance"){ + char s[1024]; + _GRBL.Init(&Wire); _GRBL.setMode(mode); - Serial.print("3"); - char* s = ""; - Serial.print("4"); - printf(s,"$0=%d", pas); // step/mm - Serial.print("5"); + + sprintf(s,"$0=%f", pas); // step/mm _GRBL.sendGcode(s); - printf(s,"$4=%f", speed); // speed + Serial.println(s); + + sprintf(s,"$4=%d", speed); // speed _GRBL.sendGcode(s); - printf(s,"$8=%d", pas); // acceleration, mm/sec^2 + Serial.println(s); + + sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2 _GRBL.sendGcode(s); + Serial.println(s); + + sprintf(s,"$3=%d", 500); // puse/µsec + _GRBL.sendGcode(s); + Serial.println(s); } void setup() { @@ -62,8 +70,8 @@ void setup() { } void mouveForward(int mm = 5){ - char* s = ""; - printf(s, "G1 X%d", mm); + char s[1024]; + sprintf(s, "G1 X%d", mm); _GRBL.sendGcode(s); } @@ -71,13 +79,11 @@ void loop() { if (M5.BtnA.wasPressed()) { Serial.print(_GRBL.readStatus()); - _GRBL.setMotor(5, 5, 5, 200); - _GRBL.setMotor(0, 0, 0, 200); + mouveForward(50); } if (M5.BtnB.wasPressed()) { - _GRBL.sendGcode("G1 X5Y5Z5"); - _GRBL.sendGcode("G1 X0Y0Z0"); + mouveForward(50); } if (M5.BtnC.wasReleased()) { From caa5b0ceb7ec33cee692828f8a0d21affa894433 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 23 Nov 2023 12:55:08 +0100 Subject: [PATCH 08/11] feat: gestion GRBL STEPPER --- lib/GRBL/include/GRBL.h | 22 ++++++++++++ lib/GRBL/src/GRBL.cpp | 34 ++++++++++++++++++ lib/Stepper/include/Stepper.h | 0 lib/Stepper/src/Stepper.cpp | 0 src/main.cpp | 65 +++++++++++++++++++---------------- 5 files changed, 92 insertions(+), 29 deletions(-) create mode 100644 lib/GRBL/include/GRBL.h create mode 100644 lib/GRBL/src/GRBL.cpp delete mode 100644 lib/Stepper/include/Stepper.h delete mode 100644 lib/Stepper/src/Stepper.cpp diff --git a/lib/GRBL/include/GRBL.h b/lib/GRBL/include/GRBL.h new file mode 100644 index 0000000..8837ca9 --- /dev/null +++ b/lib/GRBL/include/GRBL.h @@ -0,0 +1,22 @@ +#ifndef GRBL_H +#define GRBL_H + +#include +#include "Module_GRBL_13.2.h" + +class iGRBL{ +public: + virtual void init(int speed, double pas, int accel, String mode = "distance") = 0; + virtual void mouveForward(int mm = 5) = 0; +}; + +class GRBL : public iGRBL{ +public: + GRBL(int grblAddr); + void init(int speed, double pas, int accel, String mode = "distance") override; + void mouveForward(int mm = 5) override; +private: + Module_GRBL* grbl; +}; + +#endif diff --git a/lib/GRBL/src/GRBL.cpp b/lib/GRBL/src/GRBL.cpp new file mode 100644 index 0000000..a10807b --- /dev/null +++ b/lib/GRBL/src/GRBL.cpp @@ -0,0 +1,34 @@ +#include "../include/GRBL.h" + +GRBL::GRBL(int grblAddr){ + this->grbl = new Module_GRBL(grblAddr); +} + +void GRBL::init(int speed, double pas, int accel, String mode){ + char s[1024]; + + this->grbl->Init(&Wire); + this->grbl->setMode(mode); + + sprintf(s,"$0=%f", pas); // step/mm + this->grbl->sendGcode(s); + Serial.println(s); + + sprintf(s,"$4=%d", speed); // speed + this->grbl->sendGcode(s); + Serial.println(s); + + sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2 + this->grbl->sendGcode(s); + Serial.println(s); + + sprintf(s,"$3=%d", 500); // puse/µsec + this->grbl->sendGcode(s); + Serial.println(s); +} + +void GRBL::mouveForward(int mm = 5){ + char s[1024]; + sprintf(s, "G1 X%d", mm); + this->grbl->sendGcode(s); +} diff --git a/lib/Stepper/include/Stepper.h b/lib/Stepper/include/Stepper.h deleted file mode 100644 index e69de29..0000000 diff --git a/lib/Stepper/src/Stepper.cpp b/lib/Stepper/src/Stepper.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/main.cpp b/src/main.cpp index 21f9b7b..b27e527 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,13 +12,17 @@ #include #include -#include "Module_GRBL_13.2.h" +//#include "Module_GRBL_13.2.h" + +#include "GRBL.h" #define STEPMOTOR_I2C_ADDR 0x70 // #define STEPMOTOR_I2C_ADDR 0x71 -Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR); +//Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR); + + /** * @brief initialise le GRBL pour le stepper @@ -28,30 +32,33 @@ Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR); * @param accel vitesse d'acceleration du mptuer (mm/sec²) * @param mode mode de fonctionnement (defaut = distance) absolute */ -void init(int speed, double pas, int accel ,String mode = "distance"){ - char s[1024]; +// void init(int speed, double pas, int accel ,String mode = "distance"){ +// char s[1024]; - _GRBL.Init(&Wire); - _GRBL.setMode(mode); +// _GRBL.Init(&Wire); +// _GRBL.setMode(mode); - sprintf(s,"$0=%f", pas); // step/mm - _GRBL.sendGcode(s); - Serial.println(s); +// sprintf(s,"$0=%f", pas); // step/mm +// _GRBL.sendGcode(s); +// Serial.println(s); - sprintf(s,"$4=%d", speed); // speed - _GRBL.sendGcode(s); - Serial.println(s); +// sprintf(s,"$4=%d", speed); // speed +// _GRBL.sendGcode(s); +// Serial.println(s); - sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2 - _GRBL.sendGcode(s); - Serial.println(s); +// sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2 +// _GRBL.sendGcode(s); +// Serial.println(s); - sprintf(s,"$3=%d", 500); // puse/µsec - _GRBL.sendGcode(s); - Serial.println(s); -} +// sprintf(s,"$3=%d", 500); // puse/µsec +// _GRBL.sendGcode(s); +// Serial.println(s); +// } +GRBL* grbl; void setup() { + grbl = new GRBL(STEPMOTOR_I2C_ADDR); + M5.begin(); M5.Power.begin(); Wire.begin(21, 22); @@ -66,28 +73,28 @@ void setup() { M5.Lcd.setCursor(50, 120); delay(1000); M5.Lcd.println("Control Motor"); - init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); + grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); } -void mouveForward(int mm = 5){ - char s[1024]; - sprintf(s, "G1 X%d", mm); - _GRBL.sendGcode(s); -} +// void mouveForward(int mm = 5){ +// char s[1024]; +// sprintf(s, "G1 X%d", mm); +// _GRBL.sendGcode(s); +// } void loop() { if (M5.BtnA.wasPressed()) { - Serial.print(_GRBL.readStatus()); - mouveForward(50); + // Serial.print(_GRBL.readStatus()); + grbl->mouveForward(50); } if (M5.BtnB.wasPressed()) { - mouveForward(50); + grbl->mouveForward(50); } if (M5.BtnC.wasReleased()) { - _GRBL.unLock(); + // _GRBL.unLock(); } M5.update(); } From cfffa667b6761ada67c7346073056a9137809f66 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 15:01:41 +0100 Subject: [PATCH 09/11] fix grbl lib compile --- lib/GRBL/include/GRBL.h | 2 +- lib/GRBL/src/GRBL.cpp | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/GRBL/include/GRBL.h b/lib/GRBL/include/GRBL.h index 8837ca9..769cc14 100644 --- a/lib/GRBL/include/GRBL.h +++ b/lib/GRBL/include/GRBL.h @@ -7,7 +7,7 @@ class iGRBL{ public: virtual void init(int speed, double pas, int accel, String mode = "distance") = 0; - virtual void mouveForward(int mm = 5) = 0; + virtual void mouveForward(int mm) = 0; }; class GRBL : public iGRBL{ diff --git a/lib/GRBL/src/GRBL.cpp b/lib/GRBL/src/GRBL.cpp index a10807b..f71f61d 100644 --- a/lib/GRBL/src/GRBL.cpp +++ b/lib/GRBL/src/GRBL.cpp @@ -27,7 +27,7 @@ void GRBL::init(int speed, double pas, int accel, String mode){ Serial.println(s); } -void GRBL::mouveForward(int mm = 5){ +void GRBL::mouveForward(int mm){ char s[1024]; sprintf(s, "G1 X%d", mm); this->grbl->sendGcode(s); diff --git a/src/main.cpp b/src/main.cpp index b27e527..27c73f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,7 +90,7 @@ void loop() { } if (M5.BtnB.wasPressed()) { - grbl->mouveForward(50); + grbl->mouveForward(-50); } if (M5.BtnC.wasReleased()) { From a924d6c534d324243ceca36c9768220b97ee84cf Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 15:25:33 +0100 Subject: [PATCH 10/11] add stepper add config --- config.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.ini b/config.ini index 7a3a1c1..21dd53e 100644 --- a/config.ini +++ b/config.ini @@ -18,7 +18,8 @@ build_flags = ;;;;;;;;;;;;;;;;;;;;;; ;;; stepper config ;;; ;;;;;;;;;;;;;;;;;;;;;; + -D STEPMOTOR_I2C_ADDR=0x70 -D STEPER_ACC=200 ;-D STEPER_PAS=755.906 ; = 65mm -D STEPER_PAS=58 ; = 5mm - -D STEPER_SPEED=12000 + -D STEPER_SPEED=1000 ; 12000 From fe529b4f57722f31b75a24ddb2264add5fcfb585 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 18 Jan 2024 15:43:04 +0100 Subject: [PATCH 11/11] reset main to initial state --- src/main.cpp | 98 +++------------------------------------------------- 1 file changed, 4 insertions(+), 94 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 27c73f8..bf9fbf6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,100 +1,10 @@ -// #include "Program.h" -// Program* program; - -// void setup() { -// program = new Program(); -// } - -// void loop() { -// program->loop(); -// } - -#include - -#include -//#include "Module_GRBL_13.2.h" - -#include "GRBL.h" - - -#define STEPMOTOR_I2C_ADDR 0x70 -// #define STEPMOTOR_I2C_ADDR 0x71 - -//Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR); - - - -/** - * @brief initialise le GRBL pour le stepper - * - * @param speed vitesse par defaut du moteur - * @param pas nombre de pas par mm du moteur - * @param accel vitesse d'acceleration du mptuer (mm/sec²) - * @param mode mode de fonctionnement (defaut = distance) absolute - */ -// void init(int speed, double pas, int accel ,String mode = "distance"){ -// char s[1024]; - -// _GRBL.Init(&Wire); -// _GRBL.setMode(mode); - -// sprintf(s,"$0=%f", pas); // step/mm -// _GRBL.sendGcode(s); -// Serial.println(s); - -// sprintf(s,"$4=%d", speed); // speed -// _GRBL.sendGcode(s); -// Serial.println(s); - -// sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2 -// _GRBL.sendGcode(s); -// Serial.println(s); - -// sprintf(s,"$3=%d", 500); // puse/µsec -// _GRBL.sendGcode(s); -// Serial.println(s); -// } -GRBL* grbl; +#include "Program.h" +Program* program; void setup() { - grbl = new GRBL(STEPMOTOR_I2C_ADDR); - - M5.begin(); - M5.Power.begin(); - Wire.begin(21, 22); - Serial.begin(115200); - M5.Lcd.setTextColor(WHITE, BLACK); - M5.Lcd.setTextSize(3); - M5.lcd.setBrightness(100); - M5.Lcd.setCursor(80, 40); - M5.Lcd.println("GRBL 13.2"); - M5.Lcd.setCursor(50, 80); - M5.Lcd.println("Press Btn A/B"); - M5.Lcd.setCursor(50, 120); - delay(1000); - M5.Lcd.println("Control Motor"); - grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC); + program = new Program(); } -// void mouveForward(int mm = 5){ -// char s[1024]; -// sprintf(s, "G1 X%d", mm); -// _GRBL.sendGcode(s); -// } - void loop() { - if (M5.BtnA.wasPressed()) - { - // Serial.print(_GRBL.readStatus()); - grbl->mouveForward(50); - } - - if (M5.BtnB.wasPressed()) { - grbl->mouveForward(-50); - } - - if (M5.BtnC.wasReleased()) { - // _GRBL.unLock(); - } - M5.update(); + program->loop(); }