Working with the Pololu Motor Driver Shield with Arduino

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
Hello everyone,

I am currently trying to solve an issue regarding the Pololu Dual VNH5019 Motor Driver Shield for the arduino. My goal is to be able to make the motors continuously move forward. If I can get passed this issue, I will be able to control all the directions of the motors. The library for the Motor Driver Shield can be found here as well as its example:

https://github.com/pololu/dual-vnh5019-motor-shield

I have tried to understand how it works, but I have had no luck with it. The only time it has worked is with a different program:

C:
#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;
/*
#include <Servo.h>
Servo myservo;
*/

char dataIn='S';
char determinant;
char det;
int vel = 200; //Bluetooth Stuff

int overdrive = 13; //Press Toggle Switch #1, the pin13 LED will light up

void setup(){
Serial.begin(9600);md.init();

/*
myservo.attach(6);delay(100);
myservo.write(90);delay(100);
*/

}

void loop(){ det = check();  // You'll need to reconstruct this if your not using the Pololu Dual VNH5019
  
      while (det == 'F')   // F, move forward
       {md.setSpeeds(vel,vel);det = check();}
  
      while (det == 'B')   // B, move back
       {md.setSpeeds(-vel,-vel);det = check();}

      while (det == 'L')   // L, move wheels left
       {md.setSpeeds(-vel,vel);det = check();}
  
      while (det == 'R')   // R, move wheels right
       {md.setSpeeds(vel,-vel);det = check();}

      while (det == 'I')   // I, turn right forward
       {md.setSpeeds(vel,vel/2);det = check();}

      while (det == 'J')   // J, turn right back
       {md.setSpeeds(-vel,-vel/2);det = check();}
  
      while (det == 'G')   // G, turn left forward
       {md.setSpeeds(vel/2,vel);det = check();}

      while (det == 'H')   // H, turn left back
       {md.setSpeeds(-vel/2,-vel);det = check();}
  
      while (det == 'S')   // S, stop
       {md.setSpeeds(0,0);det = check();}
  
      //---------------------Toggle switch code------------------//
      /*while (det == 'W'){myservo.write(180);delay(100);det = check();}
      while (det == 'w'){myservo.write(90);delay(100);det = check();}
    
      while (det == 'U'){myservo.write(0);delay(100);det = check();}
      while (det == 'u'){myservo.write(90);delay(100);det = check();}
      */

}

int check()
{if (Serial.available() > 0) {dataIn = Serial.read();
        if (dataIn == 'F'){determinant = 'F';}
        else if (dataIn == 'B'){determinant = 'B';}else if (dataIn == 'L'){determinant = 'L';}
        else if (dataIn == 'R'){determinant = 'R';}else if (dataIn == 'I'){determinant = 'I';}
        else if (dataIn == 'J'){determinant = 'J';}else if (dataIn == 'G'){determinant = 'G';}
        else if (dataIn == 'H'){determinant = 'H';}else if (dataIn == 'S'){determinant = 'S';}
        else if (dataIn == '0'){vel = 400;}else if (dataIn == '1'){vel = 380;}
        else if (dataIn == '2'){vel = 340;}else if (dataIn == '3'){vel = 320;}
        else if (dataIn == '4'){vel = 280;}else if (dataIn == '5'){vel = 240;}
        else if (dataIn == '6'){vel = 200;}else if (dataIn == '7'){vel = 160;}
        else if (dataIn == '8'){vel = 120;}else if (dataIn == '9'){vel = 80;}
        else if (dataIn == 'q'){vel = 40;}
        else if (dataIn == 'U'){determinant = 'U';}else if (dataIn == 'u'){determinant = 'u';}
        else if (dataIn == 'W'){determinant = 'W';}else if (dataIn == 'w'){determinant = 'w';}
    
        }return determinant;}

I've tried working with it, however I can't understand what the issue is. The basic code that I have been trying to do is this:

#include "DualVNH5019MotorShield.h"

DualVNH5019MotorShield md;

int Foward = 200;

void setup() {
  // put your setup code here, to run once:

Serial.begin(9600);md.init();

}

void loop() {
  // put your main code here, to run repeatedly:

     while (Foward == 200)
     {md.setSpeeds(300, 300);}

}

If anyone has any suggestions, questions, and/or an answer it would be appreciated!
 
Last edited:

philba

Joined Aug 17, 2017
959
UC;DR (unformatted code; didn't read).

Try using tags to post code so it's actually readable.

Also, what are the symptoms? "can't understand" isn't a symptom, it's a result. Do you understand simple debugging techniques and have you tried them?
 

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
UC;DR (unformatted code; didn't read).

Try using tags to post code so it's actually readable.

Also, what are the symptoms? "can't understand" isn't a symptom, it's a result. Do you understand simple debugging techniques and have you tried them?
I've tried multiple ways of debugging, however I am still an amateur, can you point me in the right direction?
 

philba

Joined Aug 17, 2017
959
Well to start with, try fixing your first post with code tags. Highlight the code and hit the + on the edit bar. No one wants to read unformatted/unindented code

Be clear as to what code you are using and what you are seeing.

I would start with proving that the hardware works by running demo code. Once you know the HW is good, then tackle the SW without changing the HW. I would modify the demo code to be what I want. If you have done that, say so. Be precise about what you have done - don't expect others to read your mind. Be precise about what you are seeing.
 

Thread Starter

John A Bonilla

Joined Mar 11, 2017
92
Well to start with, try fixing your first post with code tags. Highlight the code and hit the + on the edit bar. No one wants to read unformatted/unindented code

Be clear as to what code you are using and what you are seeing.

I would start with proving that the hardware works by running demo code. Once you know the HW is good, then tackle the SW without changing the HW. I would modify the demo code to be what I want. If you have done that, say so. Be precise about what you have done - don't expect others to read your mind. Be precise about what you are seeing.
Thank you for your suggestion, however I managed to find the solution to my issue. I appreciate your support. Have a great day!
 
Top