VNH5019 and NRF24L01

Hello all,
Please be aware that I’m a beginner :slight_smile:
I request your help for 2 issues (maybe linked).
I want to manage 2 motors ( Metal Gearmotor 37Dx57L) with an arduino uno and a shield VNH5019. And I want to do that through a NRF24L01.
But I can’t found the settings to manage that :frowning:
It seems that the shield is using the pin 12 but the wireless module need this mandatory pin too !? Am I correct ?
How can I manage both ?
I know in datasheet we can remap or else but don’t know what to do.
My second point is when I try to manage the motor it doesn’t work well. The example provided is ok (without the wireless connected) but when I try to run the motors with a joystick connected I’cant move both of them in the same way or same speed …
Can you help ?
Thanks a lot for your help.

Before going through the process of modifying your VNH5019 shield to change the pin mapping, can you link to the NRF24L01 module as well as any associated libraries you are using?

If you are only having trouble moving your motors with the joystick when your NRF24L01 module is connected, then it seems like that could be problem. We can look deeper into that after we figure out whether you need to do any pin remapping.

Brandon

Hello,
Thank you for the feedback :slight_smile:
I tried again before any remapping.
I did without RC module first. Just wired the Joystick directly on the shield and it goes good.
Then i used the RC module and it seems to be not so bad.
But the NRF24L01 module is not stable. Maybe not a shield issue then … don’t know.

I explain … from my transmitor, if i check directly on the serial monitor the informations provided by the joystick, it’s perfect information : i mean in my case (with delay) :

  • middle i have 0 0 0 0 0 0 0 0 0 0 …
  • Y up i have 200 200 200 200 200 200 …
  • Y down i have -200 -200 -200 -200 -200 …
    for example and it’s stable (same for X).

But when i’m with remote control : i check the serial monitor to the target connected on the shield. And i can have this kind of results :

  • middle i have 0 0 0 200 0 0 0 0 200 0 …
  • Y up i have 200 200 0 200 200 -200 …
  • Y down i have -200 -200 200 -200 -200 -200 0 -200 -200 …

i added a capacitor on the RC module because i red on internet that it can help but no change :frowning:
Any idea to help ?
Thnak you.

Can you clarify what all is in your setup when you are using the NRF24L01 module? It might be helpful to remove everything else and try just that module with a simple code that outputs the signal received (i.e. does not use the libraries for your other devices) to see if it works by itself.

If it works when you test it separately, and you only have irregular readings when you use the VNH5019 shield with your NRF24L01 module, can you link to your particular NRF24L01 module as well as any associated libraries you are using?

Brandon

Hello BrandonM !

Thank you for your feedback !
I found my issue with NRF24L01 and now this part is ok. But i don’t know why, the job with the motors is not good :frowning: anymore

I explain :
First i provided the information from the Transmitor with a

  • radio.write(valueX, sizeof(valueX)) (data X of my Joystick)
  • radio.write(valueY, sizeof(valueY)) (data Y of my Joystick)
    → and this was working with my code to manage motors through the shield but i had not stable radio connections. With some advise of people in forums, i had to stack my datas in a Struct function to send just 1 pack.

So i did as follow :

struct Packet { 
  int vX;
  int vY;
} pack;

and data to send like this :
radio.write(&pack, sizeof(pack));

And this is working well for my radio data ! now data in arriving to my receiver with stable information.

but Now when i adapt my code, the shield doesn’t want to run my Motor2 !? don’t know why !?

Initial transmitor code :


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8); // CE, CSN du module wireless
int VRx = A5; // Pin A5, Axe des X du Joystick --> entre 0 (gauche) et 1023 (droite)
int VRy = A4; // Pin A4, Axe des Y du Joystick --> entre 1023 (bas) et 0 (haut)
int SW = 6; // Pin D6 pour le bouton du Joystick

int vX = 0;
int vY = 0;
int SW_state = 0;

const byte address[6] = "00001"; // Canal de communication entre les modules wireless

void setup() {
  Serial.begin(115200);  
  // initialisation pour le module Wireless
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);

  // initialisation des pin du Joystick
  pinMode(VRx, INPUT);
  pinMode(VRy, INPUT);
  pinMode(SW, INPUT_PULLUP);
}

void loop() {    
  radio.stopListening();
  
  vX = analogRead(VRx);
  vY = analogRead(VRy);
  SW_state = digitalRead(SW);
    
  radio.write(&vX, sizeof(vX));
  radio.write(&vY, sizeof(vY));
  radio.write(&SW_state, sizeof(SW_state));

  Serial.print("X: ");
  Serial.print(vX);
  Serial.print(" | Y: ");
  Serial.print(vY);
  Serial.print(" | Bouton: ");
  Serial.println(SW_state);
  delay(100);
}

Initial Receiver code :

#include "DualVNH5019MotorShield.h"

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


DualVNH5019MotorShield md; // declaration pour le shield Pololu
RF24 radio(5, 3); // CE, CSN du module wireless

const byte address[6] = "00001"; // Canal de communication entre les modules wireless

int vX = 0;
int vY = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;

void setup()
{
  Serial.begin(115200);
  md.init(); // initialisation pour utiliser les fonctions du shield
  
  // initialisation pour le module Wireless
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
    
}

void loop()
{ 
  radio.startListening();

while  (radio.available()) {
    radio.read(&vX, sizeof(vX));
    radio.read(&vY, sizeof(vY));
    radio.read(&SW_state, sizeof(SW_state));

  mapX = map(vX, 0, 1023, -200, 200);
  mapY = map(vY, 0, 1023, 200, -200);

  if (mapY > 50) { // en avant
    md.setSpeeds(mapY,mapY);
  }
  if (mapY < -50) { // en arriere
    md.setSpeeds(mapY,mapY);
  }
  if ((mapX > 50) && (mapY > 50)) { // en avant a droite
    md.setM1Speed(mapY-mapX); // moteur de droite
    md.setM2Speed(mapY); // moteur de gauche
  }
  if ((mapX < -50) && (mapY > 50)) { // en avant a gauche
    md.setM1Speed(mapY); // moteur de droite
    md.setM2Speed(mapY+mapX); // moteur de gauche
  }
  if ((mapX > 50) && (mapY < -50)) { // en arriere a droite
    md.setM1Speed(mapY+mapX); // moteur de droite
    md.setM2Speed(mapY); // moteur de gauche
  }
  if ((mapX < -50) && (mapY < -50)) { // en arriere a gauche
    md.setM1Speed(mapY); // moteur de droite
    md.setM2Speed(mapY-mapX); // moteur de gauche
  }
  if ((mapY >= -50) && (mapY <= 50)) { // a l'arret
    md.setSpeeds(0,0);
  }
}

  Serial.print("X: ");
  Serial.print(mapX);
  Serial.print(" | Y: ");
  Serial.print(mapY);
  Serial.print(" | Bouton: ");
  Serial.println(SW_state);
  delay(100);
  
}

→ This is working but with not stable data from Radio

Oh ! I was doing again my code to copy paste here … but it works well now ^^
Don’t know why and what mistake i did before !!??

So all is good now :slight_smile:

Thank You very much for your help !

Cheers,

Hello Brandon !

I’m coming back to you for something strange in the use of DualVNH5019MotorShield library …

He re is my code :

#include "DualVNH5019MotorShield.h"

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


DualVNH5019MotorShield md; // declaration pour le shield Pololu
RF24 radio(5, 3); // CE, CSN du module wireless

const byte address[6] = "00001"; // Canal de communication entre les modules wireless

struct Pack
{
  int vX;
  int vY;
  int SW_state;
}pack;

int mapX = 0;
int mapY = 0;

void setup()
{
  Serial.begin(115200);
  md.init(); // initialisation pour utiliser les fonctions du shield
  
  // initialisation pour le module Wireless
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
    
}

void loop()
{ 
  radio.startListening();

while  (radio.available()) {
    radio.read( &pack, sizeof(pack) );

  mapX = map(pack.vX, 0, 1023, -200, 200);
  mapY = map(pack.vY, 0, 1023, 200, -200);

  if (mapY > 50) { // en avant
    md.setSpeeds(mapY,mapY);
  }
  if (mapY < -50) { // en arriere
    md.setSpeeds(mapY,mapY);
  }
  
  if ((mapX > 50) && (mapY > 50)) { // en avant a droite
    md.setSpeeds(0,mapY);
  }
  if ((mapX < -50) && (mapY > 50)) { // en avant a gauche
    md.setSpeeds(mapY,0);
  }
  
  if ((mapX > 50) && (mapY >= -50) && (mapY <= 50)) { // right
    md.setSpeeds(-200,200); 
  }
  if ((mapX < -50) && (mapY >= -50) && (mapY <= 50)) { // left
    md.setSpeeds(200,-200); 
  }
  
  if ((mapX > 50) && (mapY < -50)) { // en arriere a droite
    md.setSpeeds(0,mapY);
    //md.setM1Speed(mapY+mapX); // moteur de droite
    //md.setM2Speed(mapY); // moteur de gauche
  }
  if ((mapX < -50) && (mapY < -50)) { // en arriere a gauche
    md.setSpeeds(mapY,0);
    //md.setM1Speed(mapY); // moteur de droite
    //md.setM2Speed(mapY-mapX); // moteur de gauche
  }
  
  if ((mapY >= -50) && (mapY <= 50) && (mapX <= 50) && (mapX <= 50)) { // a l'arret
    md.setSpeeds(0,0);
  }
}

  Serial.print("X: ");
  Serial.print(mapX);
  Serial.print(" | Y: ");
  Serial.print(mapY);
  Serial.print(" | Bouton: ");
  Serial.println(pack.SW_state);
  delay(100);
  
}

I try to make work this part of code :

  if ((mapX > 50) && (mapY >= -50) && (mapY <= 50)) { // right
    md.setSpeeds(-200,200); 
  }
  if ((mapX < -50) && (mapY >= -50) && (mapY <= 50)) { // left
    md.setSpeeds(200,-200); 
  }

But this is working well for going “right” : both motors are going each in the speed defined, but for the one to go “left” !? In the left side, no motors is running !?

Every other “if” condition is ok.

Do you have an idea about this ?

Thanks in advance for your support.
Regards,

It looks like you might have a typo in your last check that is likely overriding the “left turn” check.

For example, when your left turn check is true (i.e. mapX is less than -50 and mapY is between -50 and 50), your last check that stops the motor is also true (mapY is between -50 and 50 and mapX is less than 50). Since your last check has duplicate code for checking that mapX is less than 50, I suspect you meant for one of those to be checking that it is greater than -50.

By the way, I am not sure what exactly you are trying to do in this code, but I suspect there’s a much more elegant way to go about it than many independent IF statements.

Brandon

It looks like a good point :wink:
Thank you very much for your help !

Regards,

Hello Brandon,

Me again :stuck_out_tongue:
Have a new issue :confused:
After my program was working well thanks to your help, I disconnected all to create my final support for my robot.
But when are reconnect all exactly in the same configuration, one of my motors didn’t work anymore. I tried to exchange the two motors and both work on M1 connection on the shield.
So i upload the simple “demo” of Pololu shield and I have the following result in monitor : “M2 fault” ?!
Any idea what is going wrong with the shield ?

Thanks again for your help.
Regards,

Hi,
I changed the arduino Uno to test and it works … don’t understand what happened … !?
If you have any idea …
Regards,

OK … again … now with my initial code that worked before, only 1 motor is running …
i really think that there is some interference or else between VNH5019 and NRF24L01 !!!??
Something is really going strangely :frowning:

ok … now working without any structural changes except some “print” function :open_mouth: !?
Really, if you have any idea to make it stable … :frowning:
Thanks

It is hard to make any specific suggestions without a lot more information. If you are still having problems and can post a link to the NRF24L01 module you are using as well as a link to the specific library you are using, I can double check if there are any potential conflicts. Aside from that, since your results seem very inconsistent, I would suggest simplifying your code as much as possible and slowly building it back up to see if you can catch where the problem starts.

Additionally, it’s possible it is a connection issue. If you post close-up pictures of both sides of your VNH5019 shield, I would be happy to check for any questionable soldering. Similarly, if you post pictures of your entire setup that show all of your connections, I can see if I notice anything concerning.

Brandon

Hello Brandon,
Thanks again for your reply :slight_smile:
I received the shield with all connections done … I only had to put the shield on the Arduino. But maybe it was delivered with bad connections. Anyway, I will take pictures to post and will check how I can simplify the code for testing.
I will revert to you soon.
Thank you