Dual VNH5019 Library Conflicting with Arduino PulseIn

Hi all,

I am trying to use an RC transmitter to control the Dual VNH5019 motor controller through an Arduino. I want to use PulseIn() to measure the pulse width from the receiver, map() it down to a usable set of values (-400 to 400 as per the motor controller), and send those values to the motor controller. However, the Dual VNH5019 library and the PulseIn function dont seem to play well together. The PulseIn and mapped values work fine until md.init() is added. I tried doing this with interrupts and it still didnt work.

Once md.init() is uncommented all I get on the serial stream is:

Pulse Width: 0
Mapped Pulse: -2332

Here is the broken code:

[code]#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;

int pulse;
int Setpoint;

void setup() {

pinMode(7, INPUT);

Serial.begin(9600);

md.init();
}

void loop() {

pulse = pulseIn(7, HIGH, 25000);
Setpoint = map(pulse, 1280, 1810, -400, 400);

Serial.print(“Pulse Width:”);
Serial.println(pulse);

Serial.print(“Mapped Pulse:”);
Serial.println(Setpoint);

md.setM1Speed(Setpoint);

//delay(200);
}[/code]

I’m no code guru so please go easy on me!

Thanks in advance!

Hello.

I am sorry you are having trouble getting our VNH5019 Arduino shield library working with your code. That library sets Arduino pin 7 as an output (specifically, the library assumes INA2 is connected to pin 7). So, if you want to use the driver with its default connections as a shield, you should choose a different pin for your pulseIn input. Or, if you do not have your Arduino connected in a way that the shield uses Arduino pin 7 in that expected way, you should initialize the DualVNH5019MotorShield object with the pins you are actually using.

-Jon

Jonathan,

Brilliant! I should have known! Switched to pin 3 and It works flawlessly now.

Thanks for your assistance!

-Ryan C.