diff --git a/.gitignore b/.gitignore index 80da7d3..75eebe4 100644 --- a/.gitignore +++ b/.gitignore @@ -216,3 +216,4 @@ pip-log.txt #Mr Developer .mr.developer.cfg src/credentials.h +platformio_override.ini diff --git a/README.md b/README.md index 3f216ba..533acc4 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,60 @@ -Eggduino -==== +# Der Sternenlabor EggBot +* Basiert auf EggDuino mit folgenden Anpassungen + * portiert auf ESP32 + * Bessere Stepper Library + * Einfache Bahnplanung (weniger Verzerrungen) + * Stift Servo mit Rampensteuerung + * Webinterface für Logging und Einstellungen (Anschlussbelegung) + * BLE Interface (http://Eggbot.app) + * Web Socket Interace (aktuell ungetestet) + * RS232 Kommunikation mit 115200 (zuvor 9600) +* Inkscape Plugin AxiDraw_395 (siehe GIT) + * Modifizierte ebb_serial.py zur Erkennung + * Modifizierte eggbot.py - entfernt Pausen zwischen Bewegungen +* Verwendung ohne Inkscape mittels http://EggBot.app -Arduino Firmware for Eggbot / Spherebot with Inkscape-Integration +Ohne angepasstes Inkscape Plugin kann keine Kommunikation zum EggBot aufgenommen werden. -Version 1.6a -tested with Inkscape Portable 0.91, Eggbot Extension and patched eggbot.py +# Materialliste -Regards: Eggduino-Firmware by Joachim Cerny, 2015 +Schrauben: +* Motor Welle Ei: M3x8 +* Motorbefestigung: 8x M3x10 +* Motor Welle Stift: M3x12 +* Klemme für Eihalterung: 2x M3x16 +* Spannschraube Stift: M3x25 +* Armgelenk: M3x30 +* Mutter: 4x M3 **vierkant!** +* Platine Schrauben: 4x M2.3x5 +* Schrauben für Feder: 2x M2.3x5 +* Scheiben für Feder: 2x M3x6x0.5 -Thanks for the nice libs ACCELSTEPPER and SERIALCOMMAND, which made this project much easier. Thanks to the Eggbot-Team for such a funny and enjoyable concept! Thanks to my wife and my daughter for their patience. :-) +Sonstiges: +* Zugfeder: 8x17 (entspannt) +* O-Ring: 3x 18x2 +* Kugellager: 608ZZ (8x22x7) -Features: +Elektronik: +* 2x Schrittmotor Nema 17 (200 Schritte/Umd.) +* 2x Anschlusskabel +* 1x Micro Servo +* 1x CNC Shield (z.B. AZDelivery) +* 2x Schrittmotor Treiber DRV8825 +* 1x ESP32 Arduino UNO Formfaktor +* 1x Netzteil 12V min. 1A +* 1x Micro USB Kabel -- Implemented Eggbot-Protocol-Version 2.1.0 -- Turn-on homing: switch-on position of pen will be taken as reference point. -- No collision-detection!! -- Supported Servos: At least one type ;-) I use Arduino Servo-Lib with TG9e- standard servo. -- Full Arduino-Compatible. I used an Arduino Uno -- Button-support (3 buttons) +3D-Druckteile: https://www.thingiverse.com/thing:3431363 (hoffentlich bald in unserem GIT) -Tested and fully functional with Inkscape. +# Elektronik +Damit der ESP32 mit angeschlossenem CNC Shield korrekt funktioniert. Muss zwischen Enable und GND ein 1k Widerstand eingelötet werden. + ![CNC Mod](res/cnc-shield-mod.png) -Installation: - -- Upload Eggduino.ino with Arduino-IDE or similar tool to your Arudino (i.e. Uno) -- Disable Autoreset on Arduinoboard (there are several ways to do this... Which one does not matter...) -- Install Inkscape Tools wit Eggbot extension. Detailed instructions: (You yust need to complete Steps 1 and 2) -http://wiki.evilmadscientist.com/Installing_software - -- Because of an bug in the Eggbot-extension (Function findEiBotBoards()), the Eggduino cannot be detected by default. - Hopefully, the guys will fix this later on. But we can fix it on our own. - It is quiete easy: - - - Go to your Inkscape-Installationfolder and navigate to subfolder .\App\Inkscape\share\extensions - - open File "eggbot.py" in texteditor and search for line: - "Try any devices which seem to have EBB boards attached" - - comment that block with "#" like this: - # Try any devices which seem to have EBB boards attached - # for strComPort in eggbot_scan.findEiBotBoards(): - # serialPort = self.testSerialPort( strComPort ) - # if serialPort: - # self.svgSerialPort = strComPort - # return serialPort - - In my version lines 1355-1360 - - -## Setup -Add credentials.h file with content like this: - - const char *kWifiSsid = "MySSID"; - const char *kWifiPassword = "MySecret"; - -To disable Wifi: - - const char *kWifiSsid = 0; - const char *kWifiPassword = 0; +## Anschlussbelegung +* Ei-Drehen Stepper: Y +* Stift-Bewegen Stepper: X +* Servo Ctrl Pin: Z-Step +* USB Versorgung an ESP32 UNO (nötig) +* 12V Netzteil an CNC Shield (nicht ESP32 UNO Buche) +Falls von der Anschlussbelegung abgewichen wird, muss die geänderte Belegung über das Webinterface angepasst werden. diff --git a/docs/res/cnc-shield-mod.png b/docs/res/cnc-shield-mod.png new file mode 100644 index 0000000..e76c17c Binary files /dev/null and b/docs/res/cnc-shield-mod.png differ diff --git a/include/ArduinoEsp32Compat.h b/include/ArduinoEsp32Compat.h new file mode 100644 index 0000000..acbf153 --- /dev/null +++ b/include/ArduinoEsp32Compat.h @@ -0,0 +1,14 @@ +#pragma once + +// Arduino-ESP32 1.0.6 does not define these version macros, but some newer +// libraries use them to select legacy-compatible code paths. +#ifndef ESP_ARDUINO_VERSION +#define EGGDUINO_LEGACY_ARDUINO_ESP32 1 +#define ESP_ARDUINO_VERSION 0 +#else +#define EGGDUINO_LEGACY_ARDUINO_ESP32 0 +#endif + +#ifndef ESP_ARDUINO_VERSION_VAL +#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) (((major) * 10000) + ((minor) * 100) + (patch)) +#endif diff --git a/include/button.h b/include/button.h index f387c78..65980a9 100644 --- a/include/button.h +++ b/include/button.h @@ -29,7 +29,7 @@ private: public: - Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) { + Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), pin(p), action(a) { pinMode(pin, INPUT_PULLUP); } @@ -56,4 +56,3 @@ public: }; //button #endif //__BUTTON_H__ - diff --git a/platformio.ini b/platformio.ini index a65022f..f420f00 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,34 +8,45 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:uno] +[platformio] +default_envs = uno_linux +extra_configs = platformio_override.ini + +[env] platform = platformio/espressif32 board = esp32dev framework = arduino monitor_speed = 115200 +lib_deps = + arminjo/ServoEasing + madhephaestus/ESP32Servo@^3.0.6 + bblanchon/ArduinoJson@^6.21.5 + links2004/WebSockets@^2.6.1 + +[env:uno_linux] upload_speed = 576000 upload_port = /dev/ttyUSB* -extra_scripts = post:scripts/package_firmware.py -lib_deps = - arminjo/ServoEasing - madhephaestus/ESP32Servo@^3.0.6 - bblanchon/ArduinoJson@^6.21.5 - gin66/FastAccelStepper@^0.33.13 - h2zero/NimBLE-Arduino@^2.3.6 - links2004/WebSockets@^2.6.1 +lib_deps = + ${env.lib_deps} + gin66/FastAccelStepper@^0.33.13 + h2zero/NimBLE-Arduino@^2.3.6 + +[env:uno_windows] +extra_scripts = pre:scripts/patch_legacy_esp32_libs.py +build_flags = + -DEGGDUINO_WINDOWS_BUILD_FIXES=1 + -include $PROJECT_INCLUDE_DIR/ArduinoEsp32Compat.h +monitor_port = COM* +upload_port = COM8 +lib_deps = + ${env.lib_deps} + gin66/FastAccelStepper@0.30.15 + h2zero/NimBLE-Arduino@2.2.3 [env:uno_macos] -platform = platformio/espressif32 -board = esp32dev -framework = arduino -monitor_speed = 115200 monitor_port = /dev/cu.usb* upload_port = /dev/cu.usb* -extra_scripts = post:scripts/package_firmware.py -lib_deps = - arminjo/ServoEasing - madhephaestus/ESP32Servo@^3.0.6 - bblanchon/ArduinoJson@^6.21.5 - gin66/FastAccelStepper@^0.33.13 - h2zero/NimBLE-Arduino@^2.3.6 - links2004/WebSockets@^2.6.1 +lib_deps = + ${env.lib_deps} + gin66/FastAccelStepper@^0.33.13 + h2zero/NimBLE-Arduino@^2.3.6 diff --git a/platformio_override_example.ini b/platformio_override_example.ini new file mode 100644 index 0000000..644b195 --- /dev/null +++ b/platformio_override_example.ini @@ -0,0 +1,5 @@ +# Copy file to platformio_override.ini and change default_envs to your needs. +# In this example file it uses the mac configuration. + +[platformio] +default_envs = uno_mac \ No newline at end of file diff --git a/scripts/patch_legacy_esp32_libs.py b/scripts/patch_legacy_esp32_libs.py new file mode 100644 index 0000000..dba357a --- /dev/null +++ b/scripts/patch_legacy_esp32_libs.py @@ -0,0 +1,98 @@ +from pathlib import Path + +Import("env") + + +def patch_nimble_address() -> None: + libdeps_dir = Path(env.subst("$PROJECT_LIBDEPS_DIR")) + env_name = env.subst("$PIOENV") + source_path = libdeps_dir / env_name / "NimBLE-Arduino" / "src" / "NimBLEAddress.cpp" + + if not source_path.exists(): + return + + original = source_path.read_text(encoding="utf-8") + updated = original + + include_old = '# include \n' + include_new = '# include \n# include \n' + if include_old in updated and "# include \n" not in updated: + updated = updated.replace(include_old, include_new, 1) + + call_old = " uint64_t address = std::stoull(mac, nullptr, 16);" + call_new = " uint64_t address = strtoull(mac.c_str(), nullptr, 16);" + updated = updated.replace(call_old, call_new, 1) + + if updated != original: + source_path.write_text(updated, encoding="utf-8") + print("Patched NimBLE-Arduino for legacy ESP32 toolchain compatibility") + + +def patch_nimble_device() -> None: + libdeps_dir = Path(env.subst("$PROJECT_LIBDEPS_DIR")) + env_name = env.subst("$PIOENV") + source_path = libdeps_dir / env_name / "NimBLE-Arduino" / "src" / "NimBLEDevice.cpp" + + if not source_path.exists(): + return + + original = source_path.read_text(encoding="utf-8") + updated = original + + updated = updated.replace( + " ble_sm_io pkey{.action = BLE_SM_IOACT_INPUT, .passkey = passkey};\n", + " ble_sm_io pkey{};\n" + " pkey.action = BLE_SM_IOACT_INPUT;\n" + " pkey.passkey = passkey;\n", + 1, + ) + updated = updated.replace( + " ble_sm_io pkey{.action = BLE_SM_IOACT_NUMCMP, .numcmp_accept = accept};\n", + " ble_sm_io pkey{};\n" + " pkey.action = BLE_SM_IOACT_NUMCMP;\n" + " pkey.numcmp_accept = accept;\n", + 1, + ) + + if updated != original: + source_path.write_text(updated, encoding="utf-8") + print("Patched NimBLEDevice.cpp for legacy ESP32 toolchain compatibility") + + +def patch_websockets_client() -> None: + libdeps_dir = Path(env.subst("$PROJECT_LIBDEPS_DIR")) + env_name = env.subst("$PIOENV") + source_path = libdeps_dir / env_name / "WebSockets" / "src" / "WebSocketsClient.cpp" + + if not source_path.exists(): + return + + original = source_path.read_text(encoding="utf-8") + updated = original + + old = ( + "#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)\n" + " _client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size);\n" + "#else\n" + " _client.ssl->setCACertBundle(_CA_bundle);\n" + "#endif\n" + ) + new = ( + "#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)\n" + " _client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size);\n" + "#else\n" + " // Arduino-ESP32 1.x has no CA bundle API; the project only uses\n" + " // WebSocketsServer, so keep the client path buildable with insecure TLS.\n" + " _client.ssl->setInsecure();\n" + "#endif\n" + ) + updated = updated.replace(old, new, 1) + + if updated != original: + source_path.write_text(updated, encoding="utf-8") + print("Patched WebSocketsClient.cpp for legacy ESP32 toolchain compatibility") + + +patch_nimble_address() +patch_nimble_device() +patch_websockets_client() diff --git a/src/Functions.cpp b/src/Functions.cpp index 527980b..a67780d 100644 --- a/src/Functions.cpp +++ b/src/Functions.cpp @@ -144,9 +144,7 @@ void setPen() { Log(__FUNCTION__); int cmd; - int value; char *arg; - char cstrMsg[20]; // moveToDestination(); @@ -172,7 +170,7 @@ void setPen() val = nextCommandArg(); if (val != NULL) { - value = atoi(val); + (void)atoi(val); sendAck(); // delay(value); } @@ -189,8 +187,7 @@ void setPen() void togglePen() { Log(__FUNCTION__); - char *arg; - arg = nextCommandArg(); + (void)nextCommandArg(); doTogglePen(); sendAck(); diff --git a/src/esp_timer_compat.c b/src/esp_timer_compat.c new file mode 100644 index 0000000..5569136 --- /dev/null +++ b/src/esp_timer_compat.c @@ -0,0 +1,13 @@ +#if defined(EGGDUINO_WINDOWS_BUILD_FIXES) +#include + +#if defined(ESP32) && EGGDUINO_LEGACY_ARDUINO_ESP32 +#include + +int esp_timer_is_active(esp_timer_handle_t timer) +{ + (void)timer; + return 0; +} +#endif +#endif