IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Roue à filtre photo motorisée et pilotée par Arduino


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Femme Profil pro
    GESTIONNAIRE DE PRODUCTION
    Inscrit en
    Septembre 2015
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 45
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : GESTIONNAIRE DE PRODUCTION

    Informations forums :
    Inscription : Septembre 2015
    Messages : 45
    Par défaut Roue à filtre photo motorisée et pilotée par Arduino
    Bonjour à tous,

    Je me permets de passer sur ce forum car après 2 semaines de recherche et de consultation de tutoriaux je suis toujours aussi perdu avec l'Arduino et surtout je ne trouve pas de sketch correspondant à mon besoin.

    Donc pour la petite histoire je suis astrophotographe amateur, j'ai un télescope et tout ce qui va avec et je fais des photos des étoiles, galaxies, nébuleuses et autres.

    Pour réaliser une photo, j'ai une caméra CCD avec capteur noir et blanc devant laquelle se trouve une roue à filtre. C'est un boitier dans lequel est placé un disque percé de 5 emplacement correspondant à chacun de mes filtres colorés.
    Donc, je fais tourner avec mon doigt le disque pour placer le bon filtre devant le capteur et je lance mes photos.

    Ce que je voudrais c'est automatiser la rotation de ce disque par l'intermédiaire d'un moteur PaP et Arduino comme dans cette vidéo:




    Pour ce faire j'ai commandé un moteur 28BYJ-48, un driver ULN2003 et un Arduino Nano, et j'ai trouvé les schémas de câblage mais voila LE GROS PROBLÈME est que mes compétences s'arrêtent là. J'ai tout pour faire mais pas le savoir en programmation.

    Je me tourne donc vers vous en espérant tomber sur le DIEU de la programmation Arduino lol ou du moins une âme charitable qui pourrait me développer un bout de code pour faire tourner cette fameuse roue.

    J'ai trouvé un joli sujet à concernant le moteur que j'ai acheté mais là aussi j'y pers mon latin et meme en essayant de parler un bon anglais je n'ai pas eu de réponse de ce coté.

    Le sketch initiale devrait être capable, à l'allumage de l'Arduino, de prendre la position de départ du stepper comme home/référence puis de le faire tourner d'un certain nombre de pas.
    Par la suite, si le projet se concrétise, je rajouterais un ou des capteurs à effet hall pour vraiment affiner la prise du home et le placement de chaque logement de filtre en face du capteur.
    Mais dans un premier temps et pour ne pas m'embrouiller de trop, je veux juste tester la précision du moteur.

    Je ne suis pas riche mais s'il faut faire un don paypal pour le développement je suis ouvert à propositions.

    Merci pour votre lecture et j'espère avoir des retours positifs?

    Mathieu

    voici un code que j'ai trouvé mais qui comme je n'y connais rien donc je ne peux pas l'utiliser. Pensez qu'on peut le rendre compatible avec ma demande ?

    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    // myfilterwheel example
    // ONLY FOR USE WITH 28BYJ-48 AND ULN2003 DRIVER
     
    // v1.00_ULN2003 25032016
    // Initial code
     
    #include <Arduino.h>
    #include <Stepper.h>                  // needed for stepper motor
    #include <EEPROM.h>                   // needed for EEPROM
    #include "eepromanything.h"           // needed for EEPROM
     
    // #define EEPROMSIZE 512              // ATMEGA168 512 EEPROM
    #define EEPROMSIZE 1024               // ATMEGA328P 1024 EEPROM
     
    #define FRED 1
    #define FGREEN 2
    #define FBLUE 3
    #define FLUMIN 4
    #define FOTHER 5
     
    // these are stored in EEPROM - all variables in a structure
    struct config_t
    {
      int validdata;
      int slots[5];        // slot[0] = home, this is a 5 position filter wheel, numbered 0 to 4, each holds a color value
      int steps[5] = { 0, 1000, 2000, -2000, -1000 };
    } myfilter;
     
    // will hold size of the struct myfocuser - 6 bytes
    int datasize;      // will hold size of the struct myfocuser - 6 bytes
    int nlocations;    // number of storage locations available in EEPROM
    int currentaddr;   // will be address in eeprom of the data stored
    bool writenow;     // should we update values in eeprom
    bool found;        // did we find any stored values?
    long previousMillis = 0L;   // used as a delay whenever the EEPROM settings need to be updated
    long interval = 10000L;     // interval in milliseconds to wait after a move before writing settings to EEPROM, 30s
     
    const String programName = "myFilter_ULN2003";
    const String programVersion = "1.0.0";
     
    const int stepsPerRevolution = 2048; // there are 2048 steps for one rotation of the 28BYJ-48 shaft
    // initialize the stepper library on pins 4 (IN1), 5 (IN2), 6 (IN3), 7 (IN4)
    Stepper mystepper(stepsPerRevolution, 4, 6, 7, 5);
    // note that the stepper does not release current to the coils after a step so it gets hot
    // the code below used by clearoutputs() releases the stepper after a step preventing it from getting hot
    int motorPins[] = { 4, 5, 6, 7 };  // used to disable the output so it does not overheat
    int motorSpeed = 2;
     
    long maxsteps = 3000L;         // default maximum number of steps of filter wheel
    int currentslotnumber = 0;
    int targetslotnumber = 0;
    int homepin = 2;               // this is where the index for home is connected to D2 pin
    #define dirclockwise 1
    #define diranticlockwise 2
     
    char inChar;
    boolean isMoving = false;        // is the motor currently moving
    long pos;
     
    #define MAXCOMMAND 8
    char mycmd[MAXCOMMAND];
    char param[MAXCOMMAND];
    char line[MAXCOMMAND];
    int eoc = 0;    // end of command
    int idx = 0;    // index into command string
     
    // disable the stepper motor outputs
    void clearOutput()
    {
        for (int i = 0; i < 4; i++)
        {
          digitalWrite(motorPins[i], 0);
        }
    }
     
    // Move stepper anticlockwise
    void anticlockwise()
    {
      mystepper.step(-1);        // step the motor one step anticlockwise
    }
     
    // Move stepper clockwise
    void clockwise()
    {
      mystepper.step(1);         // step the motor one step clockwise
    }
     
    void findindex()
    {
      // this homes the filter wheel to slot 0
      // it uses a hall-effect or magnet which gives true on Pin2 when its home
      // avoid going too fast else will miss the home signal
      int steps = 0;
      int mydirection = dirclockwise;
      while ( digitalRead( homepin ) == false )
      {
        if ( mydirection == dirclockwise )
        {
          clockwise();    // move the filter wheel
          steps++;
          if ( steps > maxsteps )
          {
            steps = 0;
            mydirection = diranticlockwise;
          }
        }
        else if ( mydirection == diranticlockwise )
        {
          anticlockwise();
          steps--;
          if ( steps < 0 )
          {
            steps = 0;
            mydirection = dirclockwise;
          }
        }
      }
      // found signal, so
      // ismoving = false;
      currentslotnumber = 0;
      targetslotnumber = 0;
    }
     
    void movetoslotnumber( int slottomoveto )
    {
      targetslotnumber = slottomoveto;
      // check if we are already there
      if ( targetslotnumber == currentslotnumber )
      {
        // we are already there
        // so do nothing
      }
      else
      {
        // we are not there so move
        // work out direction and number of steps
     
        // yet to finish this code
     
      }
    }
     
    // ASCOM Serial Commands
    void processCommand(String command)
    {
      memset(mycmd, 0, MAXCOMMAND);
      memset(param, 0, MAXCOMMAND);
      int len = strlen(line);
      if (len >= 2)
      {
        strncpy(mycmd, line, 2);
      }
      if (len > 2)
      {
        strncpy(param, line + 2, len - 2);
      }
     
      memset(line, 0, MAXCOMMAND);
      eoc = 0;
      idx = 0;
     
      // get the current filter position
      if (!strcasecmp(mycmd, "GP"))
      {
        Serial.print("P");
        Serial.print(currentslotnumber);
        Serial.print("#");
      }
     
      // motor is moving - 1 if moving, 0 otherwise
      else if (!strcasecmp(mycmd, "GI"))
      {
        if (isMoving )
        {
          Serial.print("I01#");
        }
        else {
          Serial.print("I00#");
        }
      }
     
      // home the filter, slot 0
      else if (!strcasecmp(mycmd, "PH"))
      {
        isMoving = true;
        findindex();
        currentslotnumber = 0;
        isMoving = true;
      }
     
      // get current slot number
      else if (!strcasecmp( mycmd, "GS"))
      {
        Serial.print("S");
        Serial.print(currentslotnumber);
        Serial.print("#");
      }
     
      // move to slot position
      else if (!strcasecmp( mycmd, "MS"))
      {
        // get the slot number to move to
        pos = decstr2long(param);
        movetoslotnumber( pos);    // move to the slot number
        writenow = true;             // updating of EEPROM ON
        previousMillis = millis();   // start time interval
      }
     
      // assign filter color to slot position
      else if (!strcasecmp(mycmd, "AF"))
      {
         // there are two arguments, slotnumber, filtercolor
         // get slotnumber (range is 0 to 4)
         int slotnumber;
         pos = decstr2long(param);
         slotnumber = pos;
     
         // now get filtercolor, 1=R, 2=G, B=3, L=4, O=5
         int colorfilter;
         pos = decstr2long(param);
         colorfilter = pos;
         // check for valid slot number
         if( (slotnumber >= 0) && (slotnumber <= 4))
         {  
           // check that colorfilter is in range 1-5
           if( (colorfilter >=1) && (colorfilter <=5) )
           {
             // assign the color filter to the slot number
             myfilter.slots[slotnumber] = colorfilter;
           }
           else
           {
             // colorfilter is outside range
             // do nothing
           }
         }
         else
         {
           // slotnumber is outside range
           // do nothing
         }   
      }
     
      // troubleshooting only - print currentaddr value, use in serial monitor mode is best
      else if (!strcasecmp(mycmd, "XY"))
      {
        Serial.println();
        Serial.print("Current Slot number=");
        Serial.println(currentslotnumber);
        Serial.print("maxsteps=");
        Serial.println(maxsteps);
        Serial.print("Slot[0]=");
        switch(myfilter.slots[0])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[1]=");
        switch(myfilter.slots[1])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[2]=");
        switch(myfilter.slots[2])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[3]=");
        switch(myfilter.slots[3])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[4]=");
        switch(myfilter.slots[4])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("#");
      }
     
      // troubleshooting only - reset focuser defaults
      else if (!strcasecmp(mycmd, "XZ"))
      {
        currentslotnumber = 0;
        targetslotnumber = 0;
     
        // setup the slots table
        myfilter.validdata = 99;
        myfilter.steps[0] = 0;
        myfilter.steps[1] = 1000;
        myfilter.steps[2] = 2000;
        myfilter.steps[3] = -2000;
        myfilter.steps[4] = -1000;
        myfilter.slots[0] = FRED;
        myfilter.slots[1] = FGREEN;
        myfilter.slots[2] = FBLUE;
        myfilter.slots[3] = FLUMIN;
        myfilter.slots[4] = FOTHER;
        // now write the data to EEPROM
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
        // Set focuser defaults.
        findindex();
      }
    }
     
    // convert string to long int
    long decstr2long(char *line) 
    {
      long ret = 0;
      ret = strtol(line, NULL, 10);
      return (ret);
    }
     
    // Setup
    void setup() 
    {
      // initialize serial for ASCOM
      Serial.begin(9600);
     
      eoc = 0;
      idx = 0;
      isMoving = false;
      memset(line, 0, MAXCOMMAND);
     
      mystepper.setSpeed(motorSpeed); // medium speed
     
      currentaddr = 0;    // start at 0 if not found later
      found = false;
      writenow = false;
      datasize = sizeof( myfilter );    // should be 14 bytes
      nlocations = EEPROMSIZE / datasize;  // for AT328P = 1024 / datasize = 73 locations
     
      for (int lp1 = 0; lp1 < nlocations; lp1++ )
      {
        int addr = lp1 * datasize;
        EEPROM_readAnything( addr, myfilter );
        // check to see if the data is valid
        if ( myfilter.validdata == 99 ) 
        {
          // data was erased so write some default values
          currentaddr = addr;
          found = true;
        }
      }
      if ( found == true )
      {
        // set the filter back to the previous settings
        EEPROM_readAnything( currentaddr, myfilter );
        myfilter.validdata = 0;
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
     
        // goto next free address and write data
        currentaddr += datasize;
        // bound check the eeprom storage and if greater than last index [0-EEPROMSIZE-1] then set to 0
        if ( currentaddr >= (nlocations * datasize) ) currentaddr = 0;
     
        myfilter.validdata = 99;
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
      }
      else
      {
        // set defaults because not found
        myfilter.validdata = 99;
        myfilter.steps[0] = 0;
        myfilter.steps[1] = 1000;
        myfilter.steps[2] = 2000;
        myfilter.steps[3] = -2000;
        myfilter.steps[4] = -1000;
        myfilter.slots[0] = FRED;
        myfilter.slots[1] = FGREEN;
        myfilter.slots[2] = FBLUE;
        myfilter.slots[3] = FLUMIN;
        myfilter.slots[4] = FOTHER;
        // now write the data to EEPROM
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
      }
      findindex();
    }
     
    // Main Loop
    void loop()
    {
      // process the command string when a hash arrives:
      if (eoc)
      {
        processCommand(line);
        memset(line, 0, MAXCOMMAND);
        eoc = false;
      }
    }
     
    // SerialEvent occurs whenever new data comes in the serial RX.
    void serialEvent()
    {
      // : starts the command, # ends the command, do not store these in the command buffer
      // read the command until the terminating # character
      while (Serial.available() && !eoc)
      {
        inChar = Serial.read();
        if (inChar != '#' && inChar != ':')
        {
          line[idx++] = inChar;
          if (idx >= MAXCOMMAND)
          {
            idx = MAXCOMMAND - 1;
          }
        }
        else
        {
          if (inChar == '#')
          {
            eoc = 1;
            idx = 0;
          }
        }
      }
    }

  2. #2
    Expert confirmé
    Avatar de Auteur
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    7 660
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 7 660
    Par défaut
    Bonjour,


    Le code que tu as posté est assez complexe et visiblement la personne qui a réalisé ce code n'utilise pas l'IDE Arduino. Donc je te conseille de le mettre de côté.

    J'ai trouvé ce tutoriel qui pourra correspondre à tes attentes :
    http://tiptopboards.free.fr/arduino_...ic.php?t=41&43
    Il y a même un exemple de code.

    Il te faudra une petite alimentation externe de 5V, car je ne pense pas que le port USB soit capable de fournir la puissance nécessaire à ton moteur. Autre point important, l'arduino nano fonctionne sous 5V également, ce qui sera utile pour l'étape suivante : utiliser la même alimentation pour l'arduino et le moteur.

  3. #3
    Membre confirmé
    Femme Profil pro
    GESTIONNAIRE DE PRODUCTION
    Inscrit en
    Septembre 2015
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 45
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : GESTIONNAIRE DE PRODUCTION

    Informations forums :
    Inscription : Septembre 2015
    Messages : 45
    Par défaut
    bonjour,

    Enfin une réponse, merci beaucoup.

    Je vais m'empresser de regarder ton lien.

    Effectivement le code que j'ai récupéré est très complexe, surtout pour quelqu'un qui ne sait pas programmer.

    Je pensais que faire tourner un moteur d'un certain nombre de pas et ce par l’intermédiaire d'un petit logiciel sous Windows était vraiment plus simple.

    Pour l'alimentation, je la possède déjà. En fait j'ai fais la grosse erreur de tout acheter sans penser que sans le code je ne ferai rien; et à mon age, c'est trop tard pour apprendre le language Arduino.

    J’espère ne pas avoir à jeter mes composants et réaliser ce projet.

    [EDIT] j'avais deja consulté ce lien comme beaucoup d'autres mais comme je disais, sans savoir coder ça va être dur d’adapter ça à mon besoin. Je vais me résigner .

  4. #4
    Expert confirmé
    Avatar de Auteur
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    7 660
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 7 660
    Par défaut
    Citation Envoyé par seriousmath Voir le message
    [EDIT] j'avais deja consulté ce lien comme beaucoup d'autres mais comme je disais, sans savoir coder ça va être dur d’adapter ça à mon besoin. Je vais me résigner .
    non, non. Tu as des outils assez simples pour programmer avec un Arduino : "Arduino IDE" http://www.arduino.org/software. Prends la version "Windows Installer". Il y a tout ce qu'il faut.
    Après installation indique bien au programme le type de carte utilisé (Arduino nano) et le port sur lequel il est branché.

    Ensuite, prends le code proposé dans mon lien et fais un copier-coller dans l'éditeur Arduino et compile. Après, certes il faudra sans doute modifier le code pour qu'il réponde exactement à tes attentes. Mais dans un premier temps essaye ce qui est proposé.

  5. #5
    Membre confirmé
    Femme Profil pro
    GESTIONNAIRE DE PRODUCTION
    Inscrit en
    Septembre 2015
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 45
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : GESTIONNAIRE DE PRODUCTION

    Informations forums :
    Inscription : Septembre 2015
    Messages : 45
    Par défaut
    j'ai deja le logiciel installé et j'ai déjà transféré du code pour un projet précédent, mais de là à modifier le sketch c'est un autre monde, largement au dessus de mes compétences.

    Je vais mettre une annonce sur le bon coin et continuerais à tourner ma roue à filtre avec le doigt ou si un jour j'ai les 450€ j’achèterais la roue à filtre déjà Arduinoisée.

    merci encore pour tes réponses !

    je repasserais par là à l'occasion voir si le dieu du codage est passé sur mon sujet lol

  6. #6
    Expert confirmé
    Avatar de Auteur
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    7 660
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 7 660
    Par défaut
    Dommage de laisser tomber aussi rapidement. La programmation comme la photo ça s'apprend et comme la photo il faut être patient (je suis persuadé que tu dois attendre parfois des heures pour faire ton cliché).

    Teste le code indiqué. Si ton moteur tourne c'est déjà une étape réussie. Ensuite, on modifie : on peut imaginer un bouton sur une entrée numérique et à chaque impulsion le moteur fait un certain nombre de rotations qui pourrait amener le filtre à la bonne place.
    Donc j'insiste : teste. Les modifications viendront ensuite, il est probable qu'elles ne sont pas très importantes.

  7. #7
    Invité de passage
    Homme Profil pro
    Professor
    Inscrit en
    Janvier 2017
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Nouvelle-Zélande

    Informations professionnelles :
    Activité : Professor
    Secteur : Enseignement

    Informations forums :
    Inscription : Janvier 2017
    Messages : 1
    Par défaut
    Please explain why you deleted my name as the author of this code

    Veuillez expliquer pourquoi vous avez supprimé mon nom comme l'auteur de ce code


    Citation Envoyé par seriousmath Voir le message
    Bonjour à tous,

    Je me permets de passer sur ce forum car après 2 semaines de recherche et de consultation de tutoriaux je suis toujours aussi perdu avec l'Arduino et surtout je ne trouve pas de sketch correspondant à mon besoin.

    Donc pour la petite histoire je suis astrophotographe amateur, j'ai un télescope et tout ce qui va avec et je fais des photos des étoiles, galaxies, nébuleuses et autres.

    Pour réaliser une photo, j'ai une caméra CCD avec capteur noir et blanc devant laquelle se trouve une roue à filtre. C'est un boitier dans lequel est placé un disque percé de 5 emplacement correspondant à chacun de mes filtres colorés.
    Donc, je fais tourner avec mon doigt le disque pour placer le bon filtre devant le capteur et je lance mes photos.

    Ce que je voudrais c'est automatiser la rotation de ce disque par l'intermédiaire d'un moteur PaP et Arduino comme dans cette vidéo:




    Pour ce faire j'ai commandé un moteur 28BYJ-48, un driver ULN2003 et un Arduino Nano, et j'ai trouvé les schémas de câblage mais voila LE GROS PROBLÈME est que mes compétences s'arrêtent là. J'ai tout pour faire mais pas le savoir en programmation.

    Je me tourne donc vers vous en espérant tomber sur le DIEU de la programmation Arduino lol ou du moins une âme charitable qui pourrait me développer un bout de code pour faire tourner cette fameuse roue.

    J'ai trouvé un joli sujet à concernant le moteur que j'ai acheté mais là aussi j'y pers mon latin et meme en essayant de parler un bon anglais je n'ai pas eu de réponse de ce coté.

    Le sketch initiale devrait être capable, à l'allumage de l'Arduino, de prendre la position de départ du stepper comme home/référence puis de le faire tourner d'un certain nombre de pas.
    Par la suite, si le projet se concrétise, je rajouterais un ou des capteurs à effet hall pour vraiment affiner la prise du home et le placement de chaque logement de filtre en face du capteur.
    Mais dans un premier temps et pour ne pas m'embrouiller de trop, je veux juste tester la précision du moteur.

    Je ne suis pas riche mais s'il faut faire un don paypal pour le développement je suis ouvert à propositions.

    Merci pour votre lecture et j'espère avoir des retours positifs?

    Mathieu

    voici un code que j'ai trouvé mais qui comme je n'y connais rien donc je ne peux pas l'utiliser. Pensez qu'on peut le rendre compatible avec ma demande ?

    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    // myfilterwheel example
    // ONLY FOR USE WITH 28BYJ-48 AND ULN2003 DRIVER
     
    // v1.00_ULN2003 25032016
    // Initial code
     
    #include <Arduino.h>
    #include <Stepper.h>                  // needed for stepper motor
    #include <EEPROM.h>                   // needed for EEPROM
    #include "eepromanything.h"           // needed for EEPROM
     
    // #define EEPROMSIZE 512              // ATMEGA168 512 EEPROM
    #define EEPROMSIZE 1024               // ATMEGA328P 1024 EEPROM
     
    #define FRED 1
    #define FGREEN 2
    #define FBLUE 3
    #define FLUMIN 4
    #define FOTHER 5
     
    // these are stored in EEPROM - all variables in a structure
    struct config_t
    {
      int validdata;
      int slots[5];        // slot[0] = home, this is a 5 position filter wheel, numbered 0 to 4, each holds a color value
      int steps[5] = { 0, 1000, 2000, -2000, -1000 };
    } myfilter;
     
    // will hold size of the struct myfocuser - 6 bytes
    int datasize;      // will hold size of the struct myfocuser - 6 bytes
    int nlocations;    // number of storage locations available in EEPROM
    int currentaddr;   // will be address in eeprom of the data stored
    bool writenow;     // should we update values in eeprom
    bool found;        // did we find any stored values?
    long previousMillis = 0L;   // used as a delay whenever the EEPROM settings need to be updated
    long interval = 10000L;     // interval in milliseconds to wait after a move before writing settings to EEPROM, 30s
     
    const String programName = "myFilter_ULN2003";
    const String programVersion = "1.0.0";
     
    const int stepsPerRevolution = 2048; // there are 2048 steps for one rotation of the 28BYJ-48 shaft
    // initialize the stepper library on pins 4 (IN1), 5 (IN2), 6 (IN3), 7 (IN4)
    Stepper mystepper(stepsPerRevolution, 4, 6, 7, 5);
    // note that the stepper does not release current to the coils after a step so it gets hot
    // the code below used by clearoutputs() releases the stepper after a step preventing it from getting hot
    int motorPins[] = { 4, 5, 6, 7 };  // used to disable the output so it does not overheat
    int motorSpeed = 2;
     
    long maxsteps = 3000L;         // default maximum number of steps of filter wheel
    int currentslotnumber = 0;
    int targetslotnumber = 0;
    int homepin = 2;               // this is where the index for home is connected to D2 pin
    #define dirclockwise 1
    #define diranticlockwise 2
     
    char inChar;
    boolean isMoving = false;        // is the motor currently moving
    long pos;
     
    #define MAXCOMMAND 8
    char mycmd[MAXCOMMAND];
    char param[MAXCOMMAND];
    char line[MAXCOMMAND];
    int eoc = 0;    // end of command
    int idx = 0;    // index into command string
     
    // disable the stepper motor outputs
    void clearOutput()
    {
        for (int i = 0; i < 4; i++)
        {
          digitalWrite(motorPins[i], 0);
        }
    }
     
    // Move stepper anticlockwise
    void anticlockwise()
    {
      mystepper.step(-1);        // step the motor one step anticlockwise
    }
     
    // Move stepper clockwise
    void clockwise()
    {
      mystepper.step(1);         // step the motor one step clockwise
    }
     
    void findindex()
    {
      // this homes the filter wheel to slot 0
      // it uses a hall-effect or magnet which gives true on Pin2 when its home
      // avoid going too fast else will miss the home signal
      int steps = 0;
      int mydirection = dirclockwise;
      while ( digitalRead( homepin ) == false )
      {
        if ( mydirection == dirclockwise )
        {
          clockwise();    // move the filter wheel
          steps++;
          if ( steps > maxsteps )
          {
            steps = 0;
            mydirection = diranticlockwise;
          }
        }
        else if ( mydirection == diranticlockwise )
        {
          anticlockwise();
          steps--;
          if ( steps < 0 )
          {
            steps = 0;
            mydirection = dirclockwise;
          }
        }
      }
      // found signal, so
      // ismoving = false;
      currentslotnumber = 0;
      targetslotnumber = 0;
    }
     
    void movetoslotnumber( int slottomoveto )
    {
      targetslotnumber = slottomoveto;
      // check if we are already there
      if ( targetslotnumber == currentslotnumber )
      {
        // we are already there
        // so do nothing
      }
      else
      {
        // we are not there so move
        // work out direction and number of steps
     
        // yet to finish this code
     
      }
    }
     
    // ASCOM Serial Commands
    void processCommand(String command)
    {
      memset(mycmd, 0, MAXCOMMAND);
      memset(param, 0, MAXCOMMAND);
      int len = strlen(line);
      if (len >= 2)
      {
        strncpy(mycmd, line, 2);
      }
      if (len > 2)
      {
        strncpy(param, line + 2, len - 2);
      }
     
      memset(line, 0, MAXCOMMAND);
      eoc = 0;
      idx = 0;
     
      // get the current filter position
      if (!strcasecmp(mycmd, "GP"))
      {
        Serial.print("P");
        Serial.print(currentslotnumber);
        Serial.print("#");
      }
     
      // motor is moving - 1 if moving, 0 otherwise
      else if (!strcasecmp(mycmd, "GI"))
      {
        if (isMoving )
        {
          Serial.print("I01#");
        }
        else {
          Serial.print("I00#");
        }
      }
     
      // home the filter, slot 0
      else if (!strcasecmp(mycmd, "PH"))
      {
        isMoving = true;
        findindex();
        currentslotnumber = 0;
        isMoving = true;
      }
     
      // get current slot number
      else if (!strcasecmp( mycmd, "GS"))
      {
        Serial.print("S");
        Serial.print(currentslotnumber);
        Serial.print("#");
      }
     
      // move to slot position
      else if (!strcasecmp( mycmd, "MS"))
      {
        // get the slot number to move to
        pos = decstr2long(param);
        movetoslotnumber( pos);    // move to the slot number
        writenow = true;             // updating of EEPROM ON
        previousMillis = millis();   // start time interval
      }
     
      // assign filter color to slot position
      else if (!strcasecmp(mycmd, "AF"))
      {
         // there are two arguments, slotnumber, filtercolor
         // get slotnumber (range is 0 to 4)
         int slotnumber;
         pos = decstr2long(param);
         slotnumber = pos;
     
         // now get filtercolor, 1=R, 2=G, B=3, L=4, O=5
         int colorfilter;
         pos = decstr2long(param);
         colorfilter = pos;
         // check for valid slot number
         if( (slotnumber >= 0) && (slotnumber <= 4))
         {  
           // check that colorfilter is in range 1-5
           if( (colorfilter >=1) && (colorfilter <=5) )
           {
             // assign the color filter to the slot number
             myfilter.slots[slotnumber] = colorfilter;
           }
           else
           {
             // colorfilter is outside range
             // do nothing
           }
         }
         else
         {
           // slotnumber is outside range
           // do nothing
         }   
      }
     
      // troubleshooting only - print currentaddr value, use in serial monitor mode is best
      else if (!strcasecmp(mycmd, "XY"))
      {
        Serial.println();
        Serial.print("Current Slot number=");
        Serial.println(currentslotnumber);
        Serial.print("maxsteps=");
        Serial.println(maxsteps);
        Serial.print("Slot[0]=");
        switch(myfilter.slots[0])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[1]=");
        switch(myfilter.slots[1])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[2]=");
        switch(myfilter.slots[2])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[3]=");
        switch(myfilter.slots[3])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("Slot[4]=");
        switch(myfilter.slots[4])
        {
          case 1: // RED
            Serial.println("RED");
            break;
          case 2: // GREEN
            Serial.println("GREEN");
            break;
          case 3: // BLUE
            Serial.println("BLUE");
          case 4: // LUMIN
            Serial.println("LUMIN");
          case 5: // OTHER
            Serial.println("OTHER");
          default: // INVALID
            Serial.println("INVALID SLOT NUMBER");        
        }
        Serial.print("#");
      }
     
      // troubleshooting only - reset focuser defaults
      else if (!strcasecmp(mycmd, "XZ"))
      {
        currentslotnumber = 0;
        targetslotnumber = 0;
     
        // setup the slots table
        myfilter.validdata = 99;
        myfilter.steps[0] = 0;
        myfilter.steps[1] = 1000;
        myfilter.steps[2] = 2000;
        myfilter.steps[3] = -2000;
        myfilter.steps[4] = -1000;
        myfilter.slots[0] = FRED;
        myfilter.slots[1] = FGREEN;
        myfilter.slots[2] = FBLUE;
        myfilter.slots[3] = FLUMIN;
        myfilter.slots[4] = FOTHER;
        // now write the data to EEPROM
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
        // Set focuser defaults.
        findindex();
      }
    }
     
    // convert string to long int
    long decstr2long(char *line) 
    {
      long ret = 0;
      ret = strtol(line, NULL, 10);
      return (ret);
    }
     
    // Setup
    void setup() 
    {
      // initialize serial for ASCOM
      Serial.begin(9600);
     
      eoc = 0;
      idx = 0;
      isMoving = false;
      memset(line, 0, MAXCOMMAND);
     
      mystepper.setSpeed(motorSpeed); // medium speed
     
      currentaddr = 0;    // start at 0 if not found later
      found = false;
      writenow = false;
      datasize = sizeof( myfilter );    // should be 14 bytes
      nlocations = EEPROMSIZE / datasize;  // for AT328P = 1024 / datasize = 73 locations
     
      for (int lp1 = 0; lp1 < nlocations; lp1++ )
      {
        int addr = lp1 * datasize;
        EEPROM_readAnything( addr, myfilter );
        // check to see if the data is valid
        if ( myfilter.validdata == 99 ) 
        {
          // data was erased so write some default values
          currentaddr = addr;
          found = true;
        }
      }
      if ( found == true )
      {
        // set the filter back to the previous settings
        EEPROM_readAnything( currentaddr, myfilter );
        myfilter.validdata = 0;
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
     
        // goto next free address and write data
        currentaddr += datasize;
        // bound check the eeprom storage and if greater than last index [0-EEPROMSIZE-1] then set to 0
        if ( currentaddr >= (nlocations * datasize) ) currentaddr = 0;
     
        myfilter.validdata = 99;
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
      }
      else
      {
        // set defaults because not found
        myfilter.validdata = 99;
        myfilter.steps[0] = 0;
        myfilter.steps[1] = 1000;
        myfilter.steps[2] = 2000;
        myfilter.steps[3] = -2000;
        myfilter.steps[4] = -1000;
        myfilter.slots[0] = FRED;
        myfilter.slots[1] = FGREEN;
        myfilter.slots[2] = FBLUE;
        myfilter.slots[3] = FLUMIN;
        myfilter.slots[4] = FOTHER;
        // now write the data to EEPROM
        EEPROM_writeAnything(currentaddr, myfilter);    // update values in EEPROM
      }
      findindex();
    }
     
    // Main Loop
    void loop()
    {
      // process the command string when a hash arrives:
      if (eoc)
      {
        processCommand(line);
        memset(line, 0, MAXCOMMAND);
        eoc = false;
      }
    }
     
    // SerialEvent occurs whenever new data comes in the serial RX.
    void serialEvent()
    {
      // : starts the command, # ends the command, do not store these in the command buffer
      // read the command until the terminating # character
      while (Serial.available() && !eoc)
      {
        inChar = Serial.read();
        if (inChar != '#' && inChar != ':')
        {
          line[idx++] = inChar;
          if (idx >= MAXCOMMAND)
          {
            idx = MAXCOMMAND - 1;
          }
        }
        else
        {
          if (inChar == '#')
          {
            eoc = 1;
            idx = 0;
          }
        }
      }
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [C#]Propriétés Excel pilotées par C#
    Par Mictou dans le forum C#
    Réponses: 7
    Dernier message: 22/07/2008, 12h29
  2. Réponses: 1
    Dernier message: 15/11/2007, 13h51
  3. Réponses: 3
    Dernier message: 14/11/2007, 14h01
  4. [Excel] - QueryTable dans Excel Piloté par Access
    Par Invité dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 23/02/2007, 13h28
  5. Réponses: 1
    Dernier message: 23/08/2005, 14h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo