DC motor test works with Arduino Uno but not Mega 2560

Hey guys,

I was testing out my Arduino hardware using this link:

I can get the motor to move when using a Freetronics Eleven controller board (based on Arduino Uno controller) and the two channel Arduino motor shield. I copied the Void setup code into Arduino 1.0.5-r2 and the motor moved as expected.

However, when I try the same code with a Freetronics EtherMega controller board (based on Arduino Mega 2560 controller) and an Arduino 6 channel motor shield (http://www.ledsee.com/datasheet_ledsee/Arduino_LED_shield_mega.jpg), I get no movement on the motor at all. The RX and TX lights on the EtherMega controller hardly flash so I assume the Void setup code is the problem.

Is there a Void Setup code that I can try that is appropriate for the EtherMega setup? I have Googled it thoroughly and found nothing.

Also, when I plugged the DC motor into the shield, I made sure to put it into Channel A to match the Void Setup code.

Any ideas?

(deleted)

Call me an Arduino noob but which is line 23?

I assume you are excluding the remark lines precedded with //

(deleted)

The code is in the first url link I posted.

marky000:
Hey guys,

I was testing out my Arduino hardware using this link:

http://arduino.cc/en/Tutorial/DueMotorShieldDC

I can get the motor to move when using a Freetronics Eleven controller board (based on Arduino Uno controller) and the two channel Arduino motor shield. I copied the Void setup code into Arduino 1.0.5-r2 and the motor moved as expected.

However, when I try the same code with a Freetronics EtherMega controller board (based on Arduino Mega 2560 controller) and an Arduino 6 channel motor shield (http://www.ledsee.com/datasheet_ledsee/Arduino_LED_shield_mega.jpg), I get no movement on the motor at all. The RX and TX lights on the EtherMega controller hardly flash so I assume the Void setup code is the problem.

Is there a Void Setup code that I can try that is appropriate for the EtherMega setup? I have Googled it thoroughly and found nothing.

Also, when I plugged the DC motor into the shield, I made sure to put it into Channel A to match the Void Setup code.

Any ideas?

First of all, try some code for Arduino Uno from your motor shield supplier.
Secondly, how are you powering the lot? And can your provide a link to the technical details of your motor shield?

I think you guys are not understanding me so here is the code that I used (found in first url I posted).

As you will notice the code/link says its for the Arduino Due. Well the code works for the Uno but not the Mega 2650. I am trying to find code that works for the Mega 2560 to do simple motor test (just like in the url link I posted).

At this stage I am only using USB power which works fine for the Uno setup. I was under the impression you only need DC power when something is actually hooked up to the DC motor (like a fan etc).

To make things easier for all, here is the code:

Code

const int
PWM_A = 3,
DIR_A = 12,
BRAKE_A = 9,
SNS_A = A0;

void setup() {
// Configure the A output
pinMode(BRAKE_A, OUTPUT); // Brake pin on channel A
pinMode(DIR_A, OUTPUT); // Direction pin on channel A

// Open Serial communication
Serial.begin(9600);
Serial.println("Motor shield DC motor Test:\n");
}

void loop() {

// Set the outputs to run the motor forward

digitalWrite(BRAKE_A, LOW); // setting brake LOW disable motor brake
digitalWrite(DIR_A, HIGH); // setting direction to HIGH the motor will spin forward

analogWrite(PWM_A, 255); // Set the speed of the motor, 255 is the maximum value

delay(5000); // hold the motor at full speed for 5 seconds
Serial.print("current consumption at full speed: ");
Serial.println(analogRead(SNS_A));

// Brake the motor

Serial.println("Start braking\n");
// raising the brake pin the motor will stop faster than the stop by inertia
digitalWrite(BRAKE_A, HIGH); // raise the brake
delay(5000);

// Set the outputs to run the motor backward

Serial.println("Backward");
digitalWrite(BRAKE_A, LOW); // setting againg the brake LOW to disable motor brake
digitalWrite(DIR_A, LOW); // now change the direction to backward setting LOW the DIR_A pin

analogWrite(PWM_A, 255); // Set the speed of the motor

delay(5000);
Serial.print("current consumption backward: ");
Serial.println(analogRead(SNS_A));

// now stop the motor by inertia, the motor will stop slower than with the brake function
analogWrite(PWM_A, 0); // turn off power to the motor

Serial.print("current brake: ");
Serial.println(analogRead(A0));
Serial.println("End of the motor shield test with DC motors. Thank you!");

while(1);
}

The RX and TX lights on the EtherMega controller hardly flash so I assume the Void setup code is the problem.

Explain what you think you mean by this.

I was under the impression you only need DC power when something is actually hooked up to the DC motor (like a fan etc).

To run a DC motor of any kind, you need an appropriate power source for it.

If you are in doubt about the functionality of your Mega, the first thing to do is to upload some simple sketch, like "Blink", to make sure the upload communication works and that the Mega works.

michinyon:

The RX and TX lights on the EtherMega controller hardly flash so I assume the Void setup code is the problem.

Explain what you think you mean by this.

During the DC motor test when using the Arduino Uno, the tx/rx LEDs at pin 13 were very active. Not so when running the same test using the EtherMega.

michinyon:
To run a DC motor of any kind, you need an appropriate power source for it.

If you are in doubt about the functionality of your Mega, the first thing to do is to upload some simple sketch, like "Blink", to make sure the upload communication works and that the Mega works.

Well, the Arduino Uno had no issue driving the motor on USB power alone.

Already did the blink test. LEDs very active on the Arduino Uno for maybe 5 to 10 seconds. On the EtherMega, the LEDs only flashed ever so slightly (less than a second).

Thanks for all the help but still no response to my main question. Is there different code required when using the EtherMega and where might I find some examples?

I am just trying to get the DC motor to at least twitch a little when running a simple motor test like was found in my first url link: http://arduino.cc/en/Tutorial/DueMotorShieldDC

DC motor moved significantly when using the Uno but nothing at all when using the Mega 2560. So I assume the code is the problem.

You seem to be trying to use the same code with two different Freetronics products. Have you any information from Freetronics that leads you to think that should work?

If so please provide a link to it.

...R

Robin2:
You seem to be trying to use the same code with two different Freetronics products.
...R

The code I am using was pulled from the Ardunio website and is basically a simple DC motor test using an Arduino Due. I suppose it makes sense that the code for a Due might work for a Uno but not the Mega but I was hoping someone might be able to highlight the main lines in the code that explain why the Due code is working for the Uno but not the Mega.

I will see if I can dig up anything from Freetronics but as far as I can tell the EtherMega = Arduino Mega 2560 (for all intensive purposes) as is the Freetronics Eleven = Arduni Uno. Especially when we are only talking about a simple DC motor test. Thats why I started by looking at code available on the Arduino site.

marky000:
a simple DC motor test.

The motor may be simple. The Freetronics boards are unlikely to be.

...R

Hi this is John from Freetronics.
Please give us a link to the product page for the motor shield (that has the technical details such as schematic) you are attempting to use with your EtherMega and we can help you with it.

Robin2:
The motor may be simple. The Freetronics boards are unlikely to be.

...R

Straight from the Arduino link I posted at start:

"This example shows the simplest thing you can do with an Arduino Due and an Arduino Motor Shield, driving a DC motor in forward and backward directions."

johnft:
Please give us a link to the product page for the motor shield (that has the technical details such as schematic) you are attempting to use with your EtherMega and we can help you with it.

Hi John, I am trying to get more info about the shield but at this stage I can tell you it is this one here: http://www.ledsee.com/index.php/arduino-modules2013-02-16-10-32-17/arduino-6-channel-led-shield-035-07-1a-detail

But as I have eluded to, I think the issue is the code I am using with the EtherMega (Mega 2560 compatible) rather than to do with the shield itself. The lack of LED light activity on the EtherMega is a slight concern to me. The LEDs only lit up briefly (less than a second) when uploading the blink sketch.

Anyway, I will see what other info about the shield I can get and appreciate your help.

A quick qestion about the driver. Would you have to use the Freetronics USB drivers or would the Arduino drivers for the Mega 2560 also work?

Not exactly a motor shield, however you can control motors using PWM.
The documentation for the shield is terrible, however based on what is provided we'll assume that the six outputs are controlled by Mega PWM pins. So you would use analogWrite() for pins 3~8. Again, the pin numbers could be different so experiment and see what happens.
For more on analogWrite see:

Please use our USB drivers - Installing the USB driver file for Windows | Freetronics

Next time you shop for an Arduino shield, ensure the supplier has made the effort to document the shield for end users before purchasing.

As @johnft says, that board is very different from the motor shield. It is not even intended to drive motors so it has no direction control.

You probably could use it to drive a small motor in one direction at different speeds but you would need to put a diode across the motor terminals to prevent back emf damaging the board. It is unlikely to have protection since it is designed for LEDs.

I can't understand how you could think it would work with the same code.

...R

Hi, when you changed from UNO to mega, did you select mega in the IDE before loading it to the controller.

Tom..... :slight_smile: