How do I run two Arduino sketches at once?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have got two stepper motors that I want to drive at the same time using an Arduino. They both work with 2 separate DRV8825 stepper drivers that are connected to the Arduino. I can get them both to work at different times with the code but want to merge the code so that they both do different things at the same time?



Is this possible to do?










share|improve this question













migrated from electronics.stackexchange.com 1 hour ago


This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.


















    up vote
    2
    down vote

    favorite












    I have got two stepper motors that I want to drive at the same time using an Arduino. They both work with 2 separate DRV8825 stepper drivers that are connected to the Arduino. I can get them both to work at different times with the code but want to merge the code so that they both do different things at the same time?



    Is this possible to do?










    share|improve this question













    migrated from electronics.stackexchange.com 1 hour ago


    This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.
















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have got two stepper motors that I want to drive at the same time using an Arduino. They both work with 2 separate DRV8825 stepper drivers that are connected to the Arduino. I can get them both to work at different times with the code but want to merge the code so that they both do different things at the same time?



      Is this possible to do?










      share|improve this question













      I have got two stepper motors that I want to drive at the same time using an Arduino. They both work with 2 separate DRV8825 stepper drivers that are connected to the Arduino. I can get them both to work at different times with the code but want to merge the code so that they both do different things at the same time?



      Is this possible to do?







      untagged






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago







      jackveasey12333











      migrated from electronics.stackexchange.com 1 hour ago


      This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.






      migrated from electronics.stackexchange.com 1 hour ago


      This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote













          It would help if you added the current source code. Probably you use delays, in that case, use millis() instead and use the same technique as the Blink Without Delay example.



          When using delay, it will cause your program to 'halt' not being able to do actions concurrently. With keeping a state (and time since last state change) for both motors you can check for a time to elapse to do the correct actions for one or both motor.






          share|improve this answer



























            up vote
            0
            down vote













            The DRV8825 requires that your Arduino controls each step by acting the STEP and DIR pins for both motors. That requires you to carefully manage the timing of four output pins at the same time. While there are ways to sort-of multitask on an Arduino, that is not an easy task for timing critical tasks.



            Look at stepper drivers with an I2C interface. Your Arduino basically just tells the driver go left 16 steps, and the chip does all the stepping for you. And you can hook a number of drivers to the same I2C bus. The DRV8804 is an example, the DRV8823 even runs two steppers from one chip.



            Or check out the Adafruit Motor Shield V2 which also works through I2C and has great library support.






            share|improve this answer








            New contributor




            ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

















              Your Answer





              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("schematics", function ()
              StackExchange.schematics.init();
              );
              , "cicuitlab");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "540"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f57002%2fhow-do-i-run-two-arduino-sketches-at-once%23new-answer', 'question_page');

              );

              Post as a guest





























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote













              It would help if you added the current source code. Probably you use delays, in that case, use millis() instead and use the same technique as the Blink Without Delay example.



              When using delay, it will cause your program to 'halt' not being able to do actions concurrently. With keeping a state (and time since last state change) for both motors you can check for a time to elapse to do the correct actions for one or both motor.






              share|improve this answer
























                up vote
                4
                down vote













                It would help if you added the current source code. Probably you use delays, in that case, use millis() instead and use the same technique as the Blink Without Delay example.



                When using delay, it will cause your program to 'halt' not being able to do actions concurrently. With keeping a state (and time since last state change) for both motors you can check for a time to elapse to do the correct actions for one or both motor.






                share|improve this answer






















                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  It would help if you added the current source code. Probably you use delays, in that case, use millis() instead and use the same technique as the Blink Without Delay example.



                  When using delay, it will cause your program to 'halt' not being able to do actions concurrently. With keeping a state (and time since last state change) for both motors you can check for a time to elapse to do the correct actions for one or both motor.






                  share|improve this answer












                  It would help if you added the current source code. Probably you use delays, in that case, use millis() instead and use the same technique as the Blink Without Delay example.



                  When using delay, it will cause your program to 'halt' not being able to do actions concurrently. With keeping a state (and time since last state change) for both motors you can check for a time to elapse to do the correct actions for one or both motor.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  Michel Keijzers

                  5,87841733




                  5,87841733




















                      up vote
                      0
                      down vote













                      The DRV8825 requires that your Arduino controls each step by acting the STEP and DIR pins for both motors. That requires you to carefully manage the timing of four output pins at the same time. While there are ways to sort-of multitask on an Arduino, that is not an easy task for timing critical tasks.



                      Look at stepper drivers with an I2C interface. Your Arduino basically just tells the driver go left 16 steps, and the chip does all the stepping for you. And you can hook a number of drivers to the same I2C bus. The DRV8804 is an example, the DRV8823 even runs two steppers from one chip.



                      Or check out the Adafruit Motor Shield V2 which also works through I2C and has great library support.






                      share|improve this answer








                      New contributor




                      ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.





















                        up vote
                        0
                        down vote













                        The DRV8825 requires that your Arduino controls each step by acting the STEP and DIR pins for both motors. That requires you to carefully manage the timing of four output pins at the same time. While there are ways to sort-of multitask on an Arduino, that is not an easy task for timing critical tasks.



                        Look at stepper drivers with an I2C interface. Your Arduino basically just tells the driver go left 16 steps, and the chip does all the stepping for you. And you can hook a number of drivers to the same I2C bus. The DRV8804 is an example, the DRV8823 even runs two steppers from one chip.



                        Or check out the Adafruit Motor Shield V2 which also works through I2C and has great library support.






                        share|improve this answer








                        New contributor




                        ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.



















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          The DRV8825 requires that your Arduino controls each step by acting the STEP and DIR pins for both motors. That requires you to carefully manage the timing of four output pins at the same time. While there are ways to sort-of multitask on an Arduino, that is not an easy task for timing critical tasks.



                          Look at stepper drivers with an I2C interface. Your Arduino basically just tells the driver go left 16 steps, and the chip does all the stepping for you. And you can hook a number of drivers to the same I2C bus. The DRV8804 is an example, the DRV8823 even runs two steppers from one chip.



                          Or check out the Adafruit Motor Shield V2 which also works through I2C and has great library support.






                          share|improve this answer








                          New contributor




                          ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          The DRV8825 requires that your Arduino controls each step by acting the STEP and DIR pins for both motors. That requires you to carefully manage the timing of four output pins at the same time. While there are ways to sort-of multitask on an Arduino, that is not an easy task for timing critical tasks.



                          Look at stepper drivers with an I2C interface. Your Arduino basically just tells the driver go left 16 steps, and the chip does all the stepping for you. And you can hook a number of drivers to the same I2C bus. The DRV8804 is an example, the DRV8823 even runs two steppers from one chip.



                          Or check out the Adafruit Motor Shield V2 which also works through I2C and has great library support.







                          share|improve this answer








                          New contributor




                          ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 12 mins ago









                          ChrisH

                          111




                          111




                          New contributor




                          ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          ChrisH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f57002%2fhow-do-i-run-two-arduino-sketches-at-once%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery