Hello,
I buy a Pololu mc33926 motor driver to recover an old rc car. I use it with an arduino Uno and connected like a shield.
I use a bluetooth HC-06 and an android app called “Bluetooth RC Controller” to move the car.
My code is a modification of the demo code from Pololu library.
#include <SoftwareSerial.h>
#include "DualMC33926MotorShield.h"
const int MAX_VEL = 280;
const int MAX_GIRO = 350;
const int AVANCE = 20;
DualMC33926MotorShield md;
SoftwareSerial BT(3,6); //5 RX, 6 TX.
int velocity = 0;
int giroActual = 0;
float currentVel = 0;
char dataIn = 'S';
void setup() {
//Iniciamos el Bluetooth
BT.begin(9600);
Serial.begin(9600);
//Iniciamos el motor drive
md.init();
}
void loop() {
currentVel = md.getM1CurrentMilliamps();
Serial.print("Vel: ");
Serial.print(velocity);
Serial.print(", I: ");
Serial.println(currentVel);
//Comprobamos si hemos recibido un dato nuevo y actualizamos nuestra variable
if(BT.available())
{
dataIn = BT.read(); //Guarda los datos carácter a carácter en la variable "dato"
Serial.println(dataIn);
} //if BT Available
//Segun el ultimo caracter recibido actuamos de una u otra manera
if (dataIn == 'F'){ //Forward
goForward();
noTurn();
} else if (dataIn == 'B') { //Backward
goBackward();
noTurn();
} else if (dataIn == 'L') { //Left
stopCar();
turnLeft();
} else if (dataIn == 'R') { //Right
stopCar();
turnRight();
} else if (dataIn == 'I') { //Right Forward
goForward();
turnRight();
} else if (dataIn == 'J') { //Right Backward
goBackward();
turnRight();
} else if (dataIn == 'G') { //Left Forward
goForward();
turnLeft();
} else if (dataIn == 'H') { //Left Backward
goBackward();
turnLeft();
} else if (dataIn == 'S') { //Stop
stopCar();
noTurn();
}
}
/*** FUNCIONES DE MOTOR ***/
//Gira las ruedas a la derecha
void turnRight() {
//if (giroActual != MAX_GIRO) {
md.setM2Speed(-MAX_GIRO);
giroActual = -MAX_GIRO;
stopIfFault();
//}
}
void turnLeft() {
//if (giroActual != -MAX_GIRO) {
md.setM2Speed(MAX_GIRO);
giroActual = MAX_GIRO;
stopIfFault();
//}
}
void noTurn() {
md.setM2Speed(0);
stopIfFault();
}
void goForward() {
velocity += AVANCE;
if (velocity >= MAX_VEL) {
velocity = MAX_VEL;
}
md.setM1Speed(velocity);
stopIfFault();
}
void goBackward() {
velocity -= AVANCE;
if (velocity <= - MAX_VEL) {
velocity = -MAX_VEL;
}
md.setM1Speed(velocity);
stopIfFault();
}
void stopCar() {
velocity = 0;
md.setM1Speed(velocity);
stopIfFault();
}
//Medida de prevenci´n en caso de fallo del Motor Shield _SF
void stopIfFault()
{
if (md.getFault())
{
Serial.println("fault");
velocity = 0;
stopCar();
while(1);
}
}
All is fine when the wheels are on the air, but when I put the car on the floor the code always goes to fault.
Someone can help me with this problem? I don’t know if it’s a problem with the dc motor or the battery (Ni-Mh 9,6V 2300mAh).
The circuit is simple with only the motor shield and an Arduino Uno conected to the battery (not visible) and the front and rear motors and in a protoboard is the bluetooth.
I’m new in electronic and I don’t understand how current works. My battery have 2300 mAh that is less than 3A, but I understand that the “hour (h)” in units is important but I don’t know the difference. Can I know how much Amp provide my battery?
I try to limit MAX_VEL to 250 instead 400 but the problem persists.
What can I do? Thanks