Motor 1 Crash

I am stuck on what is freezing up the code using motor1 with the AFMotor.h/AFMotor.cpp library.

Using ATMega328P controller which goes through the "LOOP()" 298 times before it stops functioning or freezes.

Motor2 functions or runs continually without any problem.

Well we are stuck too. Perhaps you might share the code with us? And spell “loop”
correctly!

Sorry about that Mark - thought I was being clear, did not intend to step on your toes.

You asked for code. The following is the code segment that stops functioning when motor1 setSpeed is called.

As shown below it will cycle through the loop 298 times before it freezes.

Motor2, motor3, and motor4 function properly.

Code has been simplified to debug what is causing the problem and it seems to be related to motor1.

I have only the serial monitor for debug, so this makes debug more difficult.

==============================================================

AF_DCMotor motor1(1,MOTOR34_1KHZ); // set up motors. AF_DCMotor motor2(2, MOTOR34_1KHZ);

void MotorDriver() {

////////////////////////////////////////////////////////////////////////

LeftMotor = RightMotor = abs(AcX);

//////////////// Motor 1 and 2 Forward ////////////////////////

// motor1 set to 1 = fault /// motor1.setSpeed(RightMotor); //set the speed of the motor, between 0-255 Right Motor // motor2.setSpeed((LeftMotor)); //set the speed of the motor, between 0-255 Left Motor // motor2 commented out to find offending function call

// Forward //

motor1.run(FORWARD); // Turn as long as there's an obstacle ahead. motor2.run(FORWARD); // Turn as long as there's an obstacle ahead.

}

Output response

Loop 0

Loop 270 Loop 271 Loop 272 Loop 273 Loop 274 Loop 275 Loop 276 Loop 277 Loop 278 Loop 279 Loop 280 Loop 281 Loop 282 Loop 283 Loop 284 Loop 285 Loop 286 Loop 287 Loop 288 Loop 289 Loop 290 Loop 291 Loop 292 Loop 293 Loop 294 Loop 295 Loop 296 Loop 297 Loop 298 Loop 2 Crash point

Post your complete program using the code button </> so it looks like this

The snippet you posted does not even contain the code that prints the results you showed.

…R

You need to read the sticky threads about how to post here.

Include the whole sketch, something that doesn't just give:

'AF_DCMotor' does not name a type

when compiled for instance. Indicate for each library you use where to get the version you are using. Say which Arduino board you are using too.

You need to provide the information that allows someone to recreate the exact same problem you have (not a different problem, that helps no-one). We don't use divine inspiration to answer questions, we use the facts, all of them. You should also detail the hardware and how it is wired up and what the power source is. For motors the problem is often inadequate powering or interference.

Hi,

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks…Tom… :slight_smile: