Setup code seems to be looping

Hey everyone, really new to Arduino here and I've been trying to do this project linked here:

I've made it to Step 10 but it's not working properly. I have 2 problems: 1. the motors are not spinning to 90 degrees and instead go a full 4 rotations before stopping and then continuing again. 2. The code seems to be looping every second. See code below:

#include "Quadruped.h"

Quadruped robot(48.302, 91, 15.151, 40, 40);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  robot.init_initialise(); // 8th line.
  // robot.initialise();
  
//   delay(100);
//   robot.translate_cog_on_support_polygon("rf");
// //  delay(1000);
//   robot.IK_one_leg("rf", 0,20,10);
//   delay(100);
//   robot.IK_one_leg("rf", 0,-20,5);

//   delay(100);
//   robot.translate_cog_on_support_polygon("lb");
// //  delay(1000);
//   robot.IK_one_leg("lb", 0,20,10);
//   delay(100);
//   robot.IK_one_leg("lb", 0,-20,5);

//   delay(100);
//   robot.translate_cog_on_support_polygon("lf");
// //  delay(1000);
//   robot.IK_one_leg("lf", 0,20,20);
//   delay(100);
//   robot.IK_one_leg("lf", 0,-20,10);

//   delay(100);
//   robot.translate_cog_on_support_polygon("rb");
// //  delay(1000);
//   robot.IK_one_leg("rb", 0,20,20);
//   delay(100);
//   robot.IK_one_leg("rb", 0,-20,10);
}

void loop() {
//   // put your main code here, to run repeatedly:
//   delay(100);
//   robot.translate_cog_on_support_polygon("rf");
// //  delay(1000);
//   robot.IK_one_leg("rf", 0,20,20);
//   delay(100);
//   robot.IK_one_leg("rf", 0,-20,10);

//   delay(100);
//   robot.translate_cog_on_support_polygon("lb");
// //  delay(1000);
//   robot.IK_one_leg("lb", 0,20,20);
//   delay(100);
//   robot.IK_one_leg("lb", 0,-20,10);

//   delay(100);
//   robot.translate_cog_on_support_polygon("lf");
// //  delay(1000);
//   robot.IK_one_leg("lf", 0,20,20);
//   delay(100);
//   robot.IK_one_leg("lf", 0,-20,10);

//   delay(100);
//   robot.translate_cog_on_support_polygon("rb");
// //  delay(1000);
//   robot.IK_one_leg("rb", 0,20,20);
//   delay(100);
//   robot.IK_one_leg("rb", 0,-20,10);
}

the function init_initialize is seen below:

void Quadruped::init_initialise(){
  attach_servos();

  rfh1.write(zero_positions[0]);
  rfh2.write(zero_positions[1]);
  rfk.write(zero_positions[2]);
  lfh1.write(zero_positions[3]);
  lfh2.write(zero_positions[4]);
  lfk.write(zero_positions[5]);
  rbh1.write(zero_positions[6]);
  rbh2.write(zero_positions[7]);
  rbk.write(zero_positions[8]);
  lbh1.write(zero_positions[9]);
  lbh2.write(zero_positions[10]);
  lbk.write(zero_positions[11]);
  
  delay(1000); // miliseconds
}

any ideas what might go wrong?
Using Arduino Mega 256, MEGA Sensor Shield V1.3, and MG90S microservos as per instructions on website link.
Any help is greatly appreciated!

Probably power supply not able to handle the motors and causing a brown-out, and the Arduino restarts.

Hi, @sebeyza00
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

What type of servo are you using? If you are getting 4 full rotations, that sounds like a continuous rotation servo, not a standard servo.

thanks for the quick reply! I'm connecting the mega arduino to my 2021 macbook m1 pro, i would assume this would be enough to power it but maybe not, what would the next recommended step be?

yes that's correct! it's a full rotation MG90S micro servo. hope this helps. Could this be why it's not working as wanted?

The inadequate power supply is the problem, regardless of the type of servo.
I can't really see that project working with continuous rotation servos, you need angular control.

1 Like

Hey Tom! Please see photos of what I have. An Arduino MEGA 2560 R3, A MEGA Sensor Shield V1.3, and 4 MG90S micro servos. I connect the arduino to my 2021 macbook pro via usb cable.



Hi @sebeyza00 .
Welcome to the forum..
Had to watch the vid to see how it was powered..
He's using 2 supplies, USB for the Uno and dedicated supply for the servos..
You would need to remove that jumper and use separate power through the blue terminal block connector for servos..
But yes, agree with @david_2018 , sounds like the servos are not correct..

sorry, good luck.. ~q

1 Like

Hi,

Do you have a DMM? Digital MultiMeter.

Measure the 5V pin when your problem occurs.

If you are using the computer power supply, it sounds like the 5V is dropping out and the Mega is resetting.
Continuous resetting has the symptoms of as if you are stuck in the void setup() loop.

Tom.. :grinning: :+1: :coffee: :australia:

1 Like

The Arduino is only for control, not for power for the motors.
The power supply should power the motors directly.

Thank you very much! I see what you mean, the video shows it towards the end. I'll get it connected to a power supply and get different servo motors as well. Just to confirm, there's a recommendation of 1 amp per servo from this article:

Is it safe to assume that for the 12 servos to run I'd need at least 12 amps at 5V?

Thank you David! I'll make the adjustments and see if it works. Will keep you all updated.

Hey Tom! I do not have one with me but I do have one at school, will check to see if that's the case tomorrow. Thanks for the help!

You're welcome..
I also noticed he was using what appeared to be a bench top power supply and I believe it is displaying current usage..
Keep in mind you wont be moving all 12 at once..
Don't see any mention of servo type but I would expect them to be 180's..
Looks like fun.. :slight_smile:

~q

1 Like

Sounds great! I'll get the 180 ones.
Got it, not necessarily 12 amps.
Sure thing! It's a fun project, I'll keep you all updated on how it goes.
Once again, thanks for the advice!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.