From 3247fd13fb957523fad00dbfdece5d1ba89ec0a4 Mon Sep 17 00:00:00 2001 From: dd060606 Date: Fri, 2 May 2025 15:36:42 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20configuration=20du=20projet,?= =?UTF-8?q?=20des=20fichiers=20de=20wowki=20ainsi=20que=20le=20contr=C3=B4?= =?UTF-8?q?le=20des=20moteurs=20pas=20=C3=A0=20pas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 37 +++-------------- .vscode/extensions.json | 10 +++++ diagram.json | 89 +++++++++++++++++++++++++++++++++++++++ include/README | 37 +++++++++++++++++ lib/README | 46 +++++++++++++++++++++ platformio.ini | 15 +++++++ src/main.cpp | 92 +++++++++++++++++++++++++++++++++++++++++ test/README | 11 +++++ wokwi.toml | 4 ++ 9 files changed, 309 insertions(+), 32 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 diagram.json create mode 100644 include/README create mode 100644 lib/README create mode 100644 platformio.ini create mode 100644 src/main.cpp create mode 100644 test/README create mode 100644 wokwi.toml diff --git a/.gitignore b/.gitignore index 259148f..89cc49c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,32 +1,5 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/diagram.json b/diagram.json new file mode 100644 index 0000000..4d038e7 --- /dev/null +++ b/diagram.json @@ -0,0 +1,89 @@ +{ + "version": 1, + "author": "Anonymous maker", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-devkit-c-v4", + "id": "esp", + "top": 180.74, + "left": -265.1, + "rotate": 90, + "attrs": {} + }, + { + "type": "wokwi-a4988", + "id": "drv1", + "top": 91.4, + "left": -206, + "rotate": 270, + "attrs": {} + }, + { + "type": "wokwi-stepper-motor", + "id": "stepper1", + "top": -140.39, + "left": -258.77, + "attrs": { "size": "17" } + }, + { + "type": "wokwi-a4988", + "id": "drv2", + "top": 91.4, + "left": -33.2, + "rotate": 270, + "attrs": {} + }, + { + "type": "wokwi-stepper-motor", + "id": "stepper2", + "top": -140.39, + "left": -85.97, + "attrs": { "size": "17" } + }, + { + "type": "wokwi-a4988", + "id": "drv3", + "top": 91.4, + "left": -378.8, + "rotate": 270, + "attrs": {} + }, + { + "type": "wokwi-stepper-motor", + "id": "stepper3", + "top": -140.39, + "left": -431.57, + "attrs": { "size": "17" } + } + ], + "connections": [ + ["esp:TX", "$serialMonitor:RX", "", []], + ["esp:RX", "$serialMonitor:TX", "", []], + ["drv1:1B", "stepper1:B-", "green", ["v0"]], + ["drv1:1A", "stepper1:B+", "green", ["v0"]], + ["drv1:2A", "stepper1:A+", "green", ["v0"]], + ["drv1:2B", "stepper1:A-", "green", ["v0"]], + ["drv2:1B", "stepper2:B-", "green", ["v0"]], + ["drv2:1A", "stepper2:B+", "green", ["v0"]], + ["drv2:2A", "stepper2:A+", "green", ["v0"]], + ["drv2:2B", "stepper2:A-", "green", ["v0"]], + ["drv3:1B", "stepper3:B-", "green", ["v0"]], + ["drv3:1A", "stepper3:B+", "green", ["v0"]], + ["drv3:2A", "stepper3:A+", "green", ["v0"]], + ["drv3:2B", "stepper3:A-", "green", ["v0"]], + ["drv3:STEP", "esp:33", "gold", ["v28.8", "h86.4"]], + ["drv1:STEP", "esp:32", "gold", ["v28.8", "h-38.4"]], + ["drv1:SLEEP", "drv1:RESET", "green", ["v9.6", "h-9.6", "v9.6"]], + ["drv2:RESET", "drv2:SLEEP", "green", ["v9.6", "h9.6"]], + ["drv3:RESET", "drv3:SLEEP", "green", ["v9.6", "h9.6"]], + ["esp:14", "drv3:ENABLE", "green", ["v-19.05", "h-124.8"]], + ["esp:27", "drv1:ENABLE", "green", ["v0"]], + ["esp:26", "drv2:ENABLE", "green", ["v-28.65", "h144"]], + ["esp:16", "drv1:DIR", "blue", ["v9.6", "h144"]], + ["esp:4", "drv3:DIR", "blue", ["v19.2", "h-57.6", "v-201.6"]], + ["drv2:DIR", "esp:2", "blue", ["v211.2", "h-288"]], + ["drv2:STEP", "esp:13", "gold", ["v76.8", "h-105.6"]] + ], + "dependencies": {} +} diff --git a/include/README b/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..bcff6c8 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,15 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +lib_deps = teemuatlut/TMCStepper@^0.7.3 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a453783 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,92 @@ +#include + +#include + +// Courant max moteur (en mA) +#define R_SENSE 0.11f // Valeur typique pour TMC2209 +#define CURRENT 800 // Courant RMS souhaité + +// UART +#define TX_PIN1 17 +#define RX_PIN1 16 + +// Moteur 1 +#define DIR_PIN1 4 +#define STEP_PIN1 33 + +// Moteur 2 +#define DIR_PIN2 16 +#define STEP_PIN2 32 + +// Moteur 3 +#define DIR_PIN3 2 +#define STEP_PIN3 13 + +// Instances TMC2209 +TMC2209Stepper driver1(&Serial1, R_SENSE, 0b00); +TMC2209Stepper driver2(&Serial1, R_SENSE, 0b01); +TMC2209Stepper driver3(&Serial1, R_SENSE, 0b10); + +void setup() +{ + Serial.begin(115200); + Serial1.begin(115200, SERIAL_8N1, RX_PIN1, TX_PIN1); + + pinMode(STEP_PIN1, OUTPUT); + pinMode(DIR_PIN1, OUTPUT); + pinMode(STEP_PIN2, OUTPUT); + pinMode(DIR_PIN2, OUTPUT); + pinMode(STEP_PIN3, OUTPUT); + pinMode(DIR_PIN3, OUTPUT); + + // Initialisation des drivers + driver1.begin(); + driver1.rms_current(CURRENT); + driver1.microsteps(16); + driver1.en_spreadCycle(false); // Utilise StealthChop + driver1.pdn_disable(true); // UART uniquement + + driver2.begin(); + driver2.rms_current(CURRENT); + driver2.microsteps(16); + driver2.en_spreadCycle(false); + driver2.pdn_disable(true); + + driver3.begin(); + driver3.rms_current(CURRENT); + driver3.microsteps(16); + driver3.en_spreadCycle(false); + driver3.pdn_disable(true); + + Serial.println("Drivers initialisés."); +} + +void stepMotor(int stepPin, int dirPin, bool direction, int steps, int delay_us) +{ + digitalWrite(dirPin, direction); + for (int i = 0; i < steps; i++) + { + digitalWrite(stepPin, HIGH); + delayMicroseconds(delay_us); + digitalWrite(stepPin, LOW); + delayMicroseconds(delay_us); + } +} + +void loop() +{ + // Exemple : chaque moteur fait 200 pas dans un sens, puis dans l'autre + stepMotor(STEP_PIN1, DIR_PIN1, true, 200, 1000); + delay(500); + stepMotor(STEP_PIN1, DIR_PIN1, false, 200, 1000); + + stepMotor(STEP_PIN2, DIR_PIN2, true, 200, 1000); + delay(500); + stepMotor(STEP_PIN2, DIR_PIN2, false, 200, 1000); + + stepMotor(STEP_PIN3, DIR_PIN3, true, 200, 1000); + delay(500); + stepMotor(STEP_PIN3, DIR_PIN3, false, 200, 1000); + + delay(2000); +} diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/wokwi.toml b/wokwi.toml new file mode 100644 index 0000000..71c36a7 --- /dev/null +++ b/wokwi.toml @@ -0,0 +1,4 @@ +[wokwi] +version = 1 +firmware = '.pio/build/esp32dev/firmware.bin' +elf = '.pio/build/esp32dev/firmware.bin' \ No newline at end of file