Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
|
projets:temps:accueil [2018/01/15 16:19] shaodan Créé depuis le formulaire projets:esadmm-creer |
projets:temps:accueil [2018/02/20 16:18] (Version actuelle) resonance [Code Arduino] |
||
|---|---|---|---|
| Ligne 13: | Ligne 13: | ||
| {{projets: | {{projets: | ||
| + | |||
| + | {{: | ||
| ===== Notes techniques ===== | ===== Notes techniques ===== | ||
| Guide pas à pas et conseil pour la réalisation du projet. | Guide pas à pas et conseil pour la réalisation du projet. | ||
| + | |||
| + | ==== Electronique ==== | ||
| + | * CNC shield | ||
| + | * 3 x A4988 drivers (microstep (1/16)) | ||
| + | * 3 Steppers nema 17 HS | ||
| + | |||
| + | |||
| + | ==== Code Arduino ==== | ||
| + | |||
| + | <code cpp> | ||
| + | // CNC shield / 3 A4988 drivers (microstep (1/16)) / 3 Steppers nema 17 HS??? | ||
| + | // pins | ||
| + | #define X_DIR 5 | ||
| + | #define Y_DIR 6 | ||
| + | #define Z_DIR 7 | ||
| + | #define X_STP 2 | ||
| + | #define Y_STP | ||
| + | #define Z_STP | ||
| + | #define EN 8 | ||
| + | |||
| + | // Variables | ||
| + | const boolean DEBUG = true; | ||
| + | int start_time = 200; // 1000 | ||
| + | const int step_delay = 200; // 500 ! microseconds | ||
| + | const int step_sec = 53; // 200*16 > 3200 steps / 60 = 53,3333 steps | ||
| + | const int step_min = 53; // 200*16 | ||
| + | const int step_hour = 133; // 200*16 > 3200 steps / 24 = 133,3333 steps | ||
| + | |||
| + | int current_sec = 1; | ||
| + | int current_min = 1; | ||
| + | int current_hour = 1; | ||
| + | |||
| + | int delay_time; | ||
| + | |||
| + | // Move functions | ||
| + | void moveSecond() { | ||
| + | for (int i = 0; i < step_sec; i++) { | ||
| + | digitalWrite(X_STP, | ||
| + | delayMicroseconds(step_delay); | ||
| + | digitalWrite(X_STP, | ||
| + | delayMicroseconds(step_delay); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void moveMinute(){ | ||
| + | for (int i = 0; i < step_min; i++) { | ||
| + | digitalWrite(Y_STP, | ||
| + | delayMicroseconds(step_delay); | ||
| + | digitalWrite(Y_STP, | ||
| + | delayMicroseconds(step_delay); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void moveHour(){ | ||
| + | for (int i = 0; i < step_hour; i++) { | ||
| + | digitalWrite(Z_STP, | ||
| + | delayMicroseconds(step_delay); | ||
| + | digitalWrite(Z_STP, | ||
| + | delayMicroseconds(step_delay); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void setup(){ | ||
| + | pinMode(X_STP, | ||
| + | pinMode(Y_STP, | ||
| + | pinMode(Z_STP, | ||
| + | | ||
| + | pinMode(X_DIR, | ||
| + | pinMode(Y_DIR, | ||
| + | pinMode(Z_DIR, | ||
| + | |||
| + | // Directions | ||
| + | digitalWrite(X_DIR, | ||
| + | digitalWrite(Y_DIR, | ||
| + | digitalWrite(Z_DIR, | ||
| + | |||
| + | // Enable | ||
| + | pinMode(EN, OUTPUT); | ||
| + | digitalWrite(EN, | ||
| + | |||
| + | // Debug console | ||
| + | if (DEBUG) Serial.begin(19200); | ||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | | ||
| + | // Seconds | ||
| + | moveSecond(); | ||
| + | current_sec = (current_sec + 1) % 10; // !! 60 | ||
| + | delay_time = start_time - (step_sec * step_delay / 1000); | ||
| + | |||
| + | // Minutes | ||
| + | if (current_sec == 0) { | ||
| + | moveMinute(); | ||
| + | current_min = (current_min + 1) % 10; // !! 60 | ||
| + | delay_time = delay_time - (step_min * step_delay / 1000) ; | ||
| + | } | ||
| + | |||
| + | // Hours | ||
| + | if (current_sec == 0 && current_min == 0) { | ||
| + | moveHour(); | ||
| + | current_hour = (current_hour + 1) % 24; | ||
| + | delay_time = delay_time - (step_hour * step_delay / 1000) ; | ||
| + | } | ||
| + | |||
| + | // Debug serial monitor | ||
| + | if (DEBUG) { | ||
| + | Serial.print(current_hour); | ||
| + | Serial.print(":" | ||
| + | Serial.print(current_min); | ||
| + | Serial.print(":" | ||
| + | Serial.print(current_sec); | ||
| + | Serial.print(" | ||
| + | Serial.println(delay_time); | ||
| + | } | ||
| + | |||
| + | // Delay time | ||
| + | delay(delay_time); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | === Test vitesse === | ||
| + | |||
| + | ++++ Code test vitesse | | ||
| + | <code cpp> | ||
| + | // Arduino UNO / CNC shield / 3 * A4988 drivers (microstep (1/16)) / 3 Steppers nema 17 HS??? | ||
| + | |||
| + | // pins | ||
| + | #define X_DIR 5 | ||
| + | #define Y_DIR 6 | ||
| + | #define Z_DIR 7 | ||
| + | #define X 2 | ||
| + | #define Y | ||
| + | #define Z | ||
| + | #define EN 8 | ||
| + | |||
| + | // Variables | ||
| + | int count=0; | ||
| + | int vitesse = 500; // vitesse 500 OK | ||
| + | int count_hour = 60; // normalement ~3200 pas pour changer d' | ||
| + | |||
| + | void setup(){ | ||
| + | // Pins | ||
| + | pinMode(X, OUTPUT); | ||
| + | pinMode(Y, OUTPUT); | ||
| + | pinMode(Z, OUTPUT); | ||
| + | pinMode(X_DIR, | ||
| + | pinMode(Y_DIR, | ||
| + | pinMode(Z_DIR, | ||
| + | |||
| + | // Directions | ||
| + | digitalWrite(X_DIR, | ||
| + | digitalWrite(Y_DIR, | ||
| + | digitalWrite(Z_DIR, | ||
| + | |||
| + | // Enable | ||
| + | pinMode(EN, OUTPUT); | ||
| + | digitalWrite(EN, | ||
| + | } | ||
| + | |||
| + | void loop(){ | ||
| + | count++; | ||
| + | moveMotor(X, | ||
| + | moveMotor(Y, | ||
| + | if ((count % count_hour) == 0) { | ||
| + | moveMotor(Z, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void moveMotor(int _pin, int _nb, int _delay){ | ||
| + | for (int i = 0; i < _nb; i++) { | ||
| + | digitalWrite(_pin, | ||
| + | delayMicroseconds(_delay); | ||
| + | digitalWrite(_pin, | ||
| + | delayMicroseconds(_delay); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| ===== Matériaux et outils ===== | ===== Matériaux et outils ===== | ||
| Ligne 21: | Ligne 204: | ||
| ===== Photos ===== | ===== Photos ===== | ||
| - | Code pour afficher les images du projet : | + | {{gallery>?& |
| - | < | + | |