MD22 I2C motor driver + arduino uno

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?:

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

When an Arduino talks to an MD22 to drive a motor it doesn't send PWM and direction signals like most motor shields/controllers do.

The MD22 has a chip on it that is talking to the Arduino using I2C. I2C is a two wire communication protocol. In I2C, each device connected to the Arduino has an address which is what you need to communicate with it. In this case, the I2C address for the MD22 is defined as MD22ADDRESS(0x58).

When you write to the driver to control the motors you send two bytes, the motor and the speed. It appears that setting a speed of 128 stops the motors, 255 makes it go the maximum speed in one direction, and 0 makes it go the maximum speed in the other direction.

The two motors are defined as MOTOR1(0x01) and MOTOR2(0x02).

PWM does happen but it is happening between the motors and a chip on the MD22. The Arduino just sends this chip commands to send the appropriate PWM signals to the motors.

Not sure this answered what you wanted.

Thank you very much.
It was so helpful instruction.
two bytes are required in order to command speed for motor, however i couldnt understand the accelerating mechanism for motor.
I mean the other speed steps. How can i obtain any speed (not a full speed) without giving just 0 or 255 .
Should i give a number between 0 and 255 to get that speed. Otherside, how can i be sure that i got the specified speed for example 200 rpm?

In pwm method, we send numerous duty cycles, but in I2C we are commanding only a cycle ( just a byte) in order to move the motor?

emreg:
I mean the other speed steps. How can i obtain any speed (not a full speed) without giving just 0 or 255 . Should i give a number between 0 and 255 to get that speed.

One of the pages you posted has the answer to this MD22 Technical Documentation
If you look at that page and scroll down to the section called Mode Register there seems to be different modes you can set.

The default mode 0 says the following:

(Default Setting) If a value of 0 is written to the mode register then the meaning of the speed registers is literal speeds in the range of:
0 (Full Reverse)
128 (Stop)
255 (Full Forward).

So in this mode, I assume that 191, the number between 255 and 128, would give you half speed in one direction.

ah yes, i saw the mode register section. thank you.
i want to help on another issue.

  • In datasheet page, what does "I2C mode" and "Mode Switches" section mean? what is it used for?

the problem is solved... thanks..

hi every one i am trapped with md22 driver and i can't program it, i need to set a pid controller with the driver i used to do it with pwm but here the situation is different

i need help please