Pages: [1]   Go Down
Author Topic: MD22 I2C motor driver + arduino uno  (Read 1461 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 07, 2013, 05:30:55 pm by Denbo » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?



Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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  http://www.robot-electronics.co.uk/htm/md22tech.htm
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.


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the problem is solved... thanks..
Logged

Pages: [1]   Go Up
Jump to: