code/power question for Motor/Stepper/Servo Shield for Ardui

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
flicker
 
Posts: 5
Joined: Mon Dec 13, 2021 12:50 pm

code/power question for Motor/Stepper/Servo Shield for Ardui

Post by flicker »

I am still in the early stages of learning and have a question about the example code for the motor shield:
In the DC motor test example code for the shield, how do I retain the speed that a DC motor reaches?
For example in this piece of code, if I wanted to continue running the motor at the speed of 30 for any amount of time? I tried increasing the delay after the speed gain but it did not produce the expected result, so I am assuming that was wrong.

Code: Select all

motor_01->run(FORWARD);
  for (i=0; i<30; i++) {
motor_01->setSpeed(i);
    delay(10);
  }
  for (i=30; i!=0; i--) {
 motor_01->setSpeed(i);
    delay(10);
  }
The question about power: I plan to stack 10 shields and power four 3V DC motors from each of the shields. Does this mean I will have to power each shield individually? There is no way to run it all from the Arduino, correct? What would be a good power source for each shield?
Thank you!

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by dastels »

If I understand you correctly you want to ramp the speed up to 30 and hold it at that speed for some length of time and then ramp it back down? If so, then you just need to not change it for that amount of time. A simple example would be to add a delay between the for loops.

This page from the tutorial talk about power: https://learn.adafruit.com/adafruit-mot ... ing-motors.

I notice that it recommends 5v-12v motors.

If you have a big enough supply you could run everything off the Arduino's DC barrel jack. That's what the VIN jumper is for. However, as mentioned on the above "power" page, it's generally not a good idea to share a power source between the controller board and motors.

You wouldn't need a separate supply for each shield. If you have enough current you can supply all the shields with one supply. Or have smaller groups of shields powered by smaller supplies (e.g. 1 small supply for every 2-3 shields.

What size power supply do you need? It depends on how much current your motors will require.

For example, if you use https://www.adafruit.com/product/711, each motor will need a max of 250mA so with 4 on a shield, the shield will need 1A. I'd go a bit bigger beacause nothing is perfect. Say 3A for every pair of shield.

I don't see a good 6v supply but you could use https://www.adafruit.com/product/4880 set to 6v for each ground of 4 shields. It's a 5A supply so it would handle the 4A requirement with some to spare.

If you went with 12v motors, there's a good 12v 5A supply: https://www.adafruit.com/product/352.

But in general: a supply the same voltage as your motors with enough current capacity to handle some number of them (i.e. some number of shields with 4 motors per shield) when loaded.

Dave

User avatar
flicker
 
Posts: 5
Joined: Mon Dec 13, 2021 12:50 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by flicker »

Thank you so much for such a detailed reply, Dave!

Yes, I am trying to keep/sustain the speed the motor reaches, in this case 30.
The snippet of code I posted does ramp the motor up and has a delay, I tried increasing it after

Code: Select all


motor_01->run(FORWARD);
  for (i=0; i<30; i++) {
motor_01->setSpeed(i);
    delay(10);

////I changed the above delay to delay(1000) to have a visible continuous speed but it was longer than anticipated and the motor didn’t go down in speed after. 
Is there a different delay I should add? Is this not a correct location? 
  }
  for (i=30; i!=0; i--) {
 motor_01->setSpeed(i);
    delay(10);
  }

do I add the delay in addition to the delay that is already there delay(10), after the } of the for loop?


How do I share power source between the groups of shields? Do I put the VIN power jumper on conduit shields and off for the energy suppliers?
Thank you so much!

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by dastels »

Changing the delay inside the for loop just makes it take longer to ramp up. You need to add it immediately before the second for loop, after the closing brace of the first one:

Code: Select all

for(...) {
  ...
}
ADD THE DELAY HERE TO KEEP THE MOTOR AT 30 FOR A WHILE
for(...) {
  ...
}
As to power, you just wire the power supply to the power screw terminals on multiple shields. You take the power & ground wires from the power supply and solder a wire to each for each shield they will power. Tin the other ends of those wires and connect them to the screw terminals.

You would remove the VIN jumper on all shields. As I said, if you have that many motors you will need (pretty much guaranteed) a separate supply for the Arduino due to motor noise. You can often get away with sharing power if you only have a couple motors, but each one you add increases the likelihood of problems. I ran into an interesting case of this on one of my projects: https://learn.adafruit.com/crickit-wobblybot/power

You could try using a single power supply that's big enough (amperage-wise) to power everything. In that case you would connect it to the Arduino's power jack and put the VIN jumper on each shield. But as I said, I very much doubt that would work. The problem (as described in my project guide) is that noise from the motors can mess with the power line and cause the MCU to crash or reset.

Dave

User avatar
flicker
 
Posts: 5
Joined: Mon Dec 13, 2021 12:50 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by flicker »

Thank you thank you thank you!!!

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by dastels »

You'll probably run into a metaphorical brick wall trying to manage multiple motors using delay. Granted I don't know what your project is so maybe you'll be ok. But I doubt it ;) .

Have a look at Bill Earl's series on multi-tasking with C++/Arduino code:
https://learn.adafruit.com/multi-taskin ... ino-part-1
https://learn.adafruit.com/multi-taskin ... ino-part-2
https://learn.adafruit.com/multi-taskin ... ino-part-3

Dave

User avatar
flicker
 
Posts: 5
Joined: Mon Dec 13, 2021 12:50 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by flicker »

Thank you so much for anticipating that! It's highly likely I will be running into a full stop. I did use the delay previously when running 8-14 motors directly from the Arduino (a big no-no) but trying to do it right this time and use the shield and learn more, so I really appreciate the links!

User avatar
dastels
 
Posts: 15656
Joined: Tue Oct 20, 2015 3:22 pm

Re: code/power question for Motor/Stepper/Servo Shield for A

Post by dastels »

Those guides are full of useful techniques. I almost never use delay/sleep.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”