How do I run two Arduino sketches at once?
Clash 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?
untagged
migrated from electronics.stackexchange.com 1 hour ago
This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.
add a comment |Â
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?
untagged
migrated from electronics.stackexchange.com 1 hour ago
This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.
add a comment |Â
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?
untagged
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
untagged
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.
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered 3 hours ago


Michel Keijzers
5,87841733
5,87841733
add a comment |Â
add a comment |Â
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.
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.
add a comment |Â
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.
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.
add a comment |Â
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.
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.
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.
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.
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password