I have been working with the Arduino and the Dual VNH5019 Shield (Part number 2502) and I have been getting inconsistent readings from the feedback on 1 of 2 linear actuators. The circuit components are as follows: 2 linear actuators, 1 3 position switch, Arduino, Arduino Protoshield, Dual VNH5019 Shield (Part number 2502), and a 12 Volt battery system.
I uploaded an attachment of the circuit.
The idea behind the project is to put the switch in the up position and then both actuators would extend at the same time and length out until they hit the limit. (The limit code is not in the code below.) When in the down position the it would go down synchronized as well. When in the other position they would turn off. Currently the issue I am having is that the feedback from the 2nd motor potentiometer is not giving me consistent results. The result I am get is when the 3 position switch tells the actuators to move it cause the feedback in linear actuator 2 to go up by about 25mV which in the Arduino world is like 20-25 out of 0-1023. I tried taking the motor driver board off and moving the Actuators and checking the feedback and the result become consistent, so I think it has something to do with motor driver board but I cannot track it down.
Here is the code that I am using with the Arduino:
[code]#include <DualVNH5019MotorShield.h>
DualVNH5019MotorShield md;
// Variables
int keyUp = 3; // Reads signal from keylock switch. If high it will be used to move the actuators UP
int keyDown = 5; // Reads signal from keylock switch. If high it will be used to move the actuators Down
float act1 = 0; // Motor 1 speed value
float act2 = 0; // Motor 2 speed value
int actPot1MapVal; // Variable to store the new map value of the potentiameter
int actPot2MapVal; // Variable to store the new map value of the potentiameter
int limit1Up; // Limit to be set to stop the actuators from extending to far
int limit1Down; // Limit to be set to stop the actuators from retracting to far
int limit2Up; // Limit to be set to stop the actuators from extending to far
int limit2Down; // Limit to be set to stop the actuators from retracting to far
void setup() {
analogReference(EXTERNAL);
pinMode(keyUp, INPUT_PULLUP);
pinMode(keyDown, INPUT_PULLUP);
md.init();
Serial.begin(115200);
READACT1POT();
READACT2POT();
}
void loop() {
int actPot1 = A4;
int actPot2 = A5;
Serial.print("Actuator Pot REAL 2 = "); // Prints to the Serial Monitor the value of the POT 2
Serial.println(analogRead(actPot2));
Serial.print("Actuator Pot REAL 1: ");
Serial.println(analogRead(actPot1));
if(digitalRead(keyUp) == HIGH && digitalRead(keyDown) == HIGH){
act1 = 0;
act2 = 0;
md.setM1Speed(act1);
md.setM2Speed(act2);
md.setM1Brake(400);
md.setM2Brake(400);
Serial.print("Act1 Speed: ");
Serial.println(act1);
Serial.print("Act2 Speed: ");
Serial.println(act2);
return;
}
else if (digitalRead(keyUp) == LOW){
READACT1POT();
READACT2POT();
UP();
}
else if(digitalRead(keyDown) == LOW){
READACT1POT();
READACT2POT();
DOWN();
}
Serial.print("Act1 Speed: ");
Serial.println(act1);
Serial.print("Act2 Speed: ");
Serial.println(act2);
}
void UP(){ // If the Up keylock switch is activated then it will move the actuators Up
if(actPot1MapVal == actPot2MapVal){
act1 = 360.00;
act2 = 360.00;
}
else if(actPot1MapVal > actPot2MapVal){
act1 = (float(actPot2MapVal) / float(actPot1MapVal)) * 360.00;
act2 = 360.00;
}
else if(actPot1MapVal < actPot2MapVal){
act2 = (float(actPot1MapVal) / float(actPot2MapVal)) * 360.00;
act1 = 360.00;
}
md.setBrakes(0, 0);
md.setM1Speed(act1);
md.setM2Speed(act2);
}
void DOWN(){ // If the Down keylock switch is activated then it will move the actuators Down
if(actPot1MapVal == actPot2MapVal){
act1 = -360.00;
act2 = -360.00;
}
else if(actPot1MapVal < actPot2MapVal){
act1 = (float(actPot1MapVal) / float(actPot2MapVal)) * -360.00;
act2 = -360.00;
}
else if(actPot1MapVal > actPot2MapVal){
act2 = (float(actPot2MapVal) / float(actPot1MapVal)) * -360.00;
act1 = -360.00;
}
md.setBrakes(0, 0);
md.setM1Speed(act1);
md.setM2Speed(act2);
}
void READACT1POT(){
int actPot1 = A4; // Reads signal from potentiometer in actuator 1 (left side when looking at back of trailer).
int actPot1Val = 0; // Variable to save the value of the potentiaometer from ActPot1
for (int i = 0; i < 4; i = i +1){
actPot1Val = actPot1Val + analogRead(actPot1);
}
actPot1Val = actPot1Val / 4;
actPot1Val = constrain(actPot1Val, 31, 945);
actPot1MapVal = map(actPot1Val, 31, 945, 1, 1216);
Serial.print("Actuator Pot 1 = "); // Prints to the Serial Monitor the value of the POT 1
Serial.println(actPot1Val);
Serial.print("Actuator1 MV: ");
Serial.println(actPot1MapVal); // Prints to the Serial Monitor the mapped value of the POT 1
}
void READACT2POT(){
int actPot2 = A5; // Reads signal from potentiometer in actuator 2 (right side when looking at back of trailer).
int actPot2Val = 0; // Variable to save the value of the potentiaometer from ActPot2
for (int z = 0; z < 4; z = z + 1){
actPot2Val = actPot2Val + analogRead(actPot2);
}
actPot2Val = actPot2Val / 4;
actPot2Val = constrain(actPot2Val, 32, 935);
actPot2MapVal = map(actPot2Val, 32, 935, 1, 1216);
Serial.print("Actuator Pot 2 = "); // Prints to the Serial Monitor the value of the POT 2
Serial.println(actPot2Val);
Serial.print("Actuator2 MV: ");
Serial.println(actPot2MapVal); // Prints to the Serial Monitor the mapped value of the POT 2
}[/code]
Thank you to everyone who can help!!
Mike