Hi,
i am almost new in arduino world, so i am trying to perform some projects in easy ways. I have done so many practices with Arduino including LEDs, PWM control, potentiometer, thermal sensor etc.
However i am confused of driving DC motors via I2C bus protocol with Arduino. Could you please help me on this?:
- MD22 driver spect here:
http://www.robot-electronics.co.uk/htm/md22tech.htm- Arduino connections:
http://www.robot-electronics.co.uk/htm/arduino_examples.htm ----> MD22 example
- sample code:
http://www.robot-electronics.co.uk/files/arduino_md22.ino I want to apply this code for I2C driver, but i couldnt understand the way in code:
- why do we need to define some adresses and bytes, what do they need for? : (#define MD22ADDRESS, MOTOR1,MOTOR2)
- Why do we allways set motor speed to 255 and then stop it to speed 0, and then stop?
- I couldnt understand what does this code mean? Start, stop, start, stop .. pfff. it shouldnot be PWM control.
ire.beginTransmission(MD22ADDRESS); // Set first motor to speed 0
Wire.write(MOTOR1);
Wire.write((byte)0); // Values of 0 being sent using write have to be cast as a byteto stop them being misinterperted as NULL this is bug with arduino 1
Wire.endTransmission();
Wire.beginTransmission(MD22ADDRESS); // Set second motor to stop
Wire.write(MOTOR2);
Wire.write(128);
Wire.endTransmission();
delay(1390);
Wire.beginTransmission(MD22ADDRESS); // Set first motor to stop
Wire.write(MOTOR1);
Wire.write(128);
Wire.endTransmission();
Wire.beginTransmission(MD22ADDRESS); // Set second motor to speed 255
Wire.write(MOTOR2);
Wire.write(255);
Wire.endTransmission();
delay(1390);
Wire.beginTransmission(MD22ADDRESS); // set first motor to stop
Wire.write(MOTOR1);
Wire.write(128);
Wire.endTransmission();
Wire.beginTransmission(MD22ADDRESS); // Set second motor to speed 0
Wire.write(MOTOR2);
Wire.write((byte)0);
Wire.endTransmission();
thanks in advance