I'm very new to all this (so please be nice) I'm attempting to build an Arduino controlled tank as a base for future hardware and coding projects (add arm, sensing etc) but for now it would be really great just to be able to get the movement bit sorted.
I've bought a Pololu md08a motor controller (has a Toshiba TB6612FNG chip on it) which seems to be working great. However i can't work out how to implement PWM to gain control over the speed.
To really cut out the variables I've hard coded a set of values that should have the motors turning slowly, once i understand how to control it, i can then look at making it more usable.
const int motorAPin1 = 8; // AIN1
const int motorAPin2 = 9; // AIN2
const int motorBPin1 = 10; // BIN1
const int motorBPin2 = 11; // BIN2
const int enablePin = 2; // H-bridge enable pin
const int ledPin = 13; // LED
const int PWMA = 3; // Pulse Width Modulation Motor A
const int PWMB = 5; // Pulse Width Modulation Motor B
void setup() {
// set outputs:
pinMode(motorAPin1, OUTPUT);
pinMode(motorAPin2, OUTPUT);
pinMode(motorBPin1, OUTPUT);
pinMode(motorBPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
// set enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
}
void loop() {
digitalWrite(motorAPin1, LOW);
digitalWrite(motorAPin2, HIGH);
digitalWrite(PWMA, 60);
}
With motorAPin1 Low and motorAPin2 High, if i understand correctly, i should be able to use PWMA to control the speed moving the motor counter clockwise.
To save knackering a motor i've got a multimeter connected over AO1 and A02 (motor voltage output on H Bridge) and with this code i see the 9V i'm putting into the Motor voltage Pin. Hurrah!
Thing is, if i change the PWMA value (if i understand PWM it should be a value between 0 and 255. 0 being 0 duty and 255 being full duty) i'm still getting the same 9v.
What i was hoping for an incremental increase in the output voltage as i changed the PWMA value from 0 to 255.
Where am i going wrong!
Many thanks in advance!
Rich