Baby Orangutan B-328, Arduino Serial, and the motor library

I’m using the Baby Orangutan and programming it with the Arduino tool chain. So far I’ve been able to interface it with the MinIMU-9 v2 and used pin 1 to read Serial.print output in a terminal.

Next I tried the motors example with the Tamiya worm gearbox and I noticed a few odd things. The first is that I’m having a hard time getting any oomph out of the motors. For many settings of the on board pot the motors just whine. I decided to see what values were being used for different pot settings. So I added the debug code below:

void setup()               // run once, when the sketch starts

// Further down in loop I added a print of the motorSpeed value

  Serial.println(motorSpeed, DEC);  
  motors.setSpeeds(motorSpeed, motorSpeed);

What I’ve noticed is that for certain values of motorSpeed the output works fine. But for others it ends up being the word motor appended endless like this: “motormotormotormotormotormotormotormotor”. But tuning the pot causes output to look normal like this: “motorSpeed=-21”. If I comment out the setSpeeds call the output always looks normal.

Is this an interaction between the motor PWM and the Arduino serial library?

The whining and low power also bothers me as these motors have worked fine with other H bridges. My batteries are 4 AA so I was figuring a setting of 128 should produce full power. I know these motors can really suck down the current during a stall condition, but this is a test and I’m not stalling them.


Those motors are also very noisy electrically, and 4 AAs does not give you a lot of room above the AVR’s brownout voltage (are you using alkalines or NiMH cells?). I strongly suspect a power problem, either from battery voltage dropping due to high current draw or electrical noise is making it to VCC.

The motors will briefly draw nearly the full stall current when initially supplied with power, assuming you aren’t ramping the speed up slowly in software, so it could be a situation where the inrush current drops the supply voltage and the controller resets before the motor has a chance to start turning, so the same current-burst-reset cycle repeats over and over again.

I don’t suppose you have access to an oscilloscope you could use to look at VIN with?

There are a few things you could try:

  1. Confirm that it is a reset issue by programming the Baby Orangutan to do something special when it first starts running.
  2. Limit the maximum duty cycle to something smaller (e.g. 50%); does the problem still happen? What if you ramp up motor speed slowly?
  3. Make sure you are using new or freshly-charged batteries.
  4. Try using a higher-voltage power supply, like six AA batteries.
  5. Solder 0.1 uF caps across your motor terminals.

Please let me know what you find out.

- Ben

Ben, thanks for the suggestions. I know about the motor noise and already had a 0.1 uF cap across the leads. I’m using a alkaline cells which are pretty fresh, but a brown out makes a lot of sense. I did try ramping by slowly turning the pot, but I could have easily gone too quickly.

Later, on tonight I will add a piezo speak and output a tone in the setup function to see if a reset is occurring. If so I will switch to a higher voltage. I will reply with what I find out.

An oscilloscope is on my wish list because it could come in handy.

I added the buzzer and added a call to the following in setup:

// play note at max volume
buzzer.playNote(NOTE_E(5), 500, 15);

It did indeed reset as I turned the pot past a certain position. I switched to new batteries and reset still occurred. So I put a 1000 uF capacitor across Vin and GND and the problem went away. I’m able to run the motors at full power now.

Thanks for the suggestions. I should have thought about a reset condition, but that didn’t occur to me.

Thanks for reporting what you found. I’m glad you were able to solve the problem (I had meant to suggest trying a big cap across your power supply, but it slipped my mind while I was actually writing the list!).

- Ben

Hi, Marin_H,

I just encountered the same issue. Could you explain why do we need a 1000uF capacitor between vin and GND? Also, which pins do you mean by VIN and GND. The board’s VIN GND? Or the H bridge chip’s?

Would love to discuss with you.

Thanks for reading.