Hello,
I am using an Intel Galileo Gen2 with a DFROBOT motor shield. The power and wiring is all correct but still the analogWrite is not working, and I need to move the wheels backward. I cannot use the PWM because of the conflict it causes with my servo. here is a sample code that is not working:
Arduino PLL Speed Control
int E1 = 7;
int M1 = 6;
int E2 = 4;
int M2 = 5;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
}
void loop()
{
//Move forward is woking because of digitalWrite
digitalWrite(E1,HIGH);
digitalWrite(E2, HIGH);
analogWrite(M1, 255);
analogWrite(M2, 255);
delay(30);
//Move backward is not working because analog is not
digitalWrite(E1,HIGH);
digitalWrite(E2, HIGH);
analogWrite(M1, 0);
analogWrite(M2, 0);
delay(30);
}
}
analogWrite() with a value of 255 is NO different from digitalWrite() with a value of HIGH.
analogWrite() with a value of 0 is NO different from digitalWrite() with a value of LOW.
So, your statement about the wheels not moving backwards because PWM is not working is nonsense. Your wheels don't go backwards because you are standing on the brakes.
Try something novel like analogWrite(thePin, 200); so the wheels actually are given some speed to turn at.
The digitalWrite()s on the enable pins are what controls the direction. The analogWrite() is what controls the speed. I think you can envision that 0 is going to be pretty slow.
The code is the authority. And, it has changed. The Servo class used to be limited as to the number of servos that could be controlled with one timer. Apparently, something has changed to remove that limit.