Hiya,
I have been having issues running a 12v DC motor with an arduino Mega 2560 and a Pololu 18v25 CS motor.
The motor is connected into the OUTA and OUTB of the Pololu. The V+ and GND on the logic side of the board are connected to the corresponding ports in the arduino. The other pins connected to the arduino are PWMH, PWML, and DIR. According to the pololu page on the motor driver, PWMH should be sent the duty cycle and driven high, PWML should be driven high for forward/reverse motions, and DIR written high or low to switch the current in the motor and thus change directions. The arduino is powered through a seperate variable power supply.
The code seemed relatively simple/straightforward.
Here is an example code I threw together that should provide the general idea. The end goal of my current project involves seven motors driven through pololu 18v25 CS motor drivers (Considering switching to 18v15) and a pneumatics system. I had to take a step back after problems arose in the larger setup.
#include <arduino.h>
const int pwmh=3;
const int pwml=4;
const int dir =5;
void setup()
{
pinMode (pwmh, OUTPUT); //Setting pins
pinMode (pwml, OUTPUT);
pinMode (dir, OUTPUT);
digitalWrite (pwml, HIGH); //Writing pwml high. Shouldnt need to change
delay(5000); //adds 5 seconds before the initial write
}
void loop()
{
analogWrite (pwmh, 255);
digitalWrite (dir, HIGH);
delay(3000);
digitalWrite (dir, LOW);
delay(3000);
}
I have tried using the millis() command in replacement of delay with no success.
In regards to the code, I interpret this as running at full duty cycle in one direction for 3 seconds before switching directions and still sending the motor a 100% duty cycle. Another variation upon this was switching between a 0% and 100% duty cycle with no success.
Instead of doing the above, the motor will generally run for 5-10 seconds in one direction, do a short stop and reverse and then immediately return to the original direction and continue running for a long period. The periods of time and stops/reverses seem completely random.
I have not tried any duty cycles other than 0 and 100% as an attempt to remove any pwm interference from the testing. Also, according to the timer table for the mega, the pwm pins should be on their own timers (timer 0 I believe). If my thinking is correct, this would remove any problems with pwm interfering with the delay.
That completes the first problem. (Unable to control the speed and direction of motor).
The second problem involves uploading to the arduino with the motor driver connected and the motor is running. This is the reason the 5 second delay was added into the setup of the above code. Both the TX and RX light turn on and stay on if I try to upload to the arduino while the motor is running. If I remove the motor driver or upload in the 5 second delay, there is no problem uploading to the motor.
The third problem involves integrating an OLED screen with the motor driver into the setup. I am using the Sparkfun Microview OLED breakout board in SPI. I can include a sample code if necessary, but I am just using the library provided by Microview. I have not had problems with the screen in the past and have used it in several projects before this. Also, I have tried using a new microview breakout with the same problem occuring. I have not trying running the breakout in I2C. The actual problem arising in the setup is the OLED outputting the correct information for a few moments before either turning off or displaying random pixels.
Finally, the last problem, and most annoying problem. I have burned out two Mega 2560s while using the motor driver. If I try and attach a 12v power supply into the GND and V+ on the motor side of the pololu 18v25 CS, the board will immediately burn out upon turning the supply on. The first time this happened, it actually caused a surge in my laptop and caused the battery to expand (Unfortunately, no exploding batteries. How fun would that be?). The second time I was powering the arduino externally rather than through the USB. Same problem arose and again I saw the sad puff of smoke that was the mega.
I have been trying to troubleshoot the problem for the past week with no success, so any help/advice anyone could offer would be awesome! If you need any questions answered to provide help, please let me know.
I will be trying a new 18v25 cs motor driver in the case that the problem is in the driver itself. Also, as mentioned above, I will be trying an 18v15 motor driver as well to see if I am setting up the 18v25CS wrong.