Hi,
I have a problem with the VNH2SP30 (Monster Moto Shield), I need a code from someone who has been able to run the VNH2SP30. The SparkFun code does not work for me.
could give me a code that works please.
This is the product:
My code is:
void setup()
{
digitalWrite(4,0);
digitalWrite(7,0);
digitalWrite(8,0);
digitalWrite(9,0);
}
void loop() {
/////////////////////////////
digitalWrite(7,1);
digitalWrite(8,0);
digitalWrite(4,1);
digitalWrite(9,0);
analogWrite(5,255);
analogWrite(6,255);
delay (2000);
////////////////////////////////
digitalWrite(7,0);
digitalWrite(8,1);
digitalWrite(4,0);
digitalWrite(9,1);
analogWrite(5,255);
analogWrite(6,255);
delay (2000);
}
I think you need to explain more: what's it supposed to do vs what it actually does.
Along with a circuit diagram?
Meantime I just noticed that you're digitalWrite()-ing to pins which you didn't yet pinMode() as outputs. Pins default as inputs.
I Added as output:
void setup()
{
pinMode(4,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(4,0);
digitalWrite(7,0);
digitalWrite(8,0);
digitalWrite(9,0);
}
void loop() {
/////////////////////////////
digitalWrite(7,0);
digitalWrite(8,1);
digitalWrite(4,1);
digitalWrite(9,0);
analogWrite(5,255);
analogWrite(6,255);
delay (6000);
digitalWrite(7,1);
digitalWrite(8,0);
digitalWrite(4,0);
digitalWrite(9,1);
analogWrite(5,255);
analogWrite(6,255);
delay (6000);
And this dont work 
Ty kenwood120s.
You should use meaningful names for your pin numbers. It makes the code much easier to understand.
Once I figured out what the pins were supposed to do I was able to understand the code and it looks correct. If the sketch is correct the problem must be in the hardware. Are you sure you have the motors connected correctly and are providing adequate power?
/// Motor 1
const byte M1CWPin = 7; // INA: Clockwise input
const byte M1CCWPin = 8; // INB: Counter-clockwise input
const byte M1PWMPin = 5; // PWM input
const byte M1CurrentSensePin = A2; // CS: Current sense ANALOG input
const byte M1EnablePin = A0; // EN: Status of switches output (Analog pin)
// Motor 2
const byte M2CWPin = 4; // INA: Clockwise input
const byte M2CCWPin = 9; // INB: Counter-clockwise input
const byte M2PWMPin = 6; // PWM input
const byte M2CurrentSensePin = A3; // CS: Current sense ANALOG input
const byte M2EnablePin = A1; // EN: Status of switches output (Analog pin)
void setup() {
pinMode(M1CWPin, OUTPUT);
pinMode(M1CCWPin, OUTPUT);
pinMode(M2CWPin, OUTPUT);
pinMode(M2CCWPin, OUTPUT);
digitalWrite(M1CWPin, LOW);
digitalWrite(M1CCWPin, LOW);
digitalWrite(M2CWPin, LOW);
digitalWrite(M2CCWPin, LOW);
}
void loop() {
/////////////////////////////
// Motor 1 ClockWise
digitalWrite(M1CWPin, HIGH);
digitalWrite(M1CCWPin, LOW);
// Motor 2 ClockWise
digitalWrite(M2CWPin, HIGH);
digitalWrite(M2CCWPin, LOW);
// Both motors full speed
analogWrite(M1PWMPin, 255);
analogWrite(M2PWMPin, 255);
// Move for two seconds
delay (2000);
////////////////////////////////
// Motor 1 CounterClockWise
digitalWrite(M1CWPin, LOW);
digitalWrite(M1CCWPin, HIGH);
// Motor 2 CounterClockWise
digitalWrite(M2CWPin, LOW);
digitalWrite(M2CCWPin, HIGH);
// Both motors full speed
analogWrite(M1PWMPin, 255);
analogWrite(M2PWMPin, 255);
// Move for two seconds
delay (2000);
}
Thank you johnwasser,
but still not working.
I've tried everything.