Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: MD23 Motor Driver and Arduino

  1. #1
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    MD23 Motor Driver and Arduino

    I was scared to post before thoroughly researching the topic after getting yelled at before but I really can't get this one. I just got an MD23 motor driver and I am trying to interface with my arduino over I2C. I am going off of this sites advise on how to hook it up and talk to it. So far I have had to modify the code to get rid of the software that controls the LCD. Also I tried to narrow it down to just the code that spins the motor because my encoders are not hooked up. I have looked for tutorials on i2c communication with google and still come up blank. I can't even get the MD23 to acknowledge that it has received my command. This can be seen because a green light flashes every time a byte is received. The only success I have had is with this code.

    Code:
    #include <Wire.h>
    
    void setup()
    {
      Wire.begin();
    }
    
    void loop()
    {    
    Wire.endTransmission();
    }
    I assume this is because the end transmission command flushes the line. This causes the green LED to flash. My problem is that I don't know how to send the right data with the arduino. My MD23's address is 0xB0. I don't really know what data type this is so that is the start of my problem. Also thanks to the lack of arduino documentation on i2c I don't know what type of data it sends when I ask it to send 0xB0. All I know is that Wire.send() requires an int data type. If somebody could tell me how to initialize communication with the arduino I would appreciate it. Also the data sheet for the MD23 has lots of tables that show how to check stored information. How would you read register 32 on the MD23? Please help I researched this for 6 hours strait and I can't get anything to work.
    Dalton Caughell

  2. #2
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    127

    Re: MD23 Motor Driver and Arduino

    Just about to nod off for the night, but the first thing to check is the Address of the device. Devantech uses 8 bit addresses, and Arduino I2C library uses 7-bit addresses, try shifting the address 1 bit: 0xB0-> 0x58.

    -Fergs

  3. #3
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: MD23 Motor Driver and Arduino

    The light dosn't blink. Here is my code.

    #include <Wire.h>

    #define md23Address 0x58

    void setup()
    {
    Wire.begin();
    }

    void loop()
    {
    Wire.beginTransmission(0x58);
    }
    Dalton Caughell

  4. #4
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: MD23 Motor Driver and Arduino

    Maybe it is a problem with my setup? I connected it right as far as I can tell but I bypassed the resistors and connected my wire strait to the analog pin 4. Is it possible for this to cause my problem? From what I understood it is just a case of pulsing pins high and low for communication. That brings up another question. How can the arduino send a pulse out of an analog pin? How can I test my circuit to insure the analog pins work correctly?
    Last edited by ROBOTMAN; 01-07-2010 at 07:08 PM.
    Dalton Caughell

  5. #5
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    73

    Re: MD23 Motor Driver and Arduino

    here is a pretty good example of I2C on an Arduino talking to an EEPROM.
    http://www.arduino.cc/playground/Code/I2CEEPROM

    Edit: here is the reference for the wire library:
    http://arduino.cc/en/Reference/Wire
    Last edited by jes1510; 01-07-2010 at 07:10 PM.
    "If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
    -
    Einstein

    Don't be a HelpVampire

  6. #6
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    127

    Re: MD23 Motor Driver and Arduino

    Have you not seen this page: http://www.robot-electronics.co.uk/files/MD23.pde I'm assuming that's the "code you had to modify to remove the LCD stuff", but then I have to wonder why you were using 0xB0, and not 0x58...

    Seems like all the code you could need is there. The reason your code doesn't work is that it's not sending a complete transmission, you're just sending the start bit and the address...

    As for not knowing what send does, that's not documented on Arduino because it's part of I2C itself. Everything is byte-oriented, you are reading and writing 8-bit bytes on the device. Therefore, each send() call, converts that int to a byte, and sends it. To write to a register on the motor driver, you have to call beginTransmission(addr), a send(first_register_num_to_write), a number of send(byte_of_data) calls to set the value of the registers, and an endTransmission(). In their code, a good example is:

    PHP Code:
    void encodeReset(){      // This function resets the encoder values to 0
      
    Wire.beginTransmission(md23Address);
      
    Wire.send(cmdByte);
      
    Wire.send(0x20);       // Putting the value 0x20 to reset encoders
      
    Wire.endTransmission(); 

    Here, they are writing to the cmdByte register (defined earlier in the code as 0x10 -- or decimal 16 in their documentation). The only data sent is 0x20, the value of a command to reset the encoders.

    As for reading from Address 32, um, there doesn't appear to be an address 32. But a read is also shown in that code:

    PHP Code:
    long encoder1(){                                            // Function to read and display value of encoder 1 as a long
      
    Wire.beginTransmission(md23Address);                      // Send byte to get a reading from encoder 1
      
    Wire.send(encoderOne);
      
    Wire.endTransmission();
      
      
    Wire.requestFrom(md23Address4);                         // Request 4 bytes from MD23
      
    while(Wire.available() < 4);                              // Wait for 4 bytes to arrive
      
    long firstByte Wire.receive();                          // Recieve 4 bytes highest byte first
      
    long secondByte Wire.receive();
      
    long thirdByte Wire.receive();
      
    long fourthByte Wire.receive();
      
      
    long poss1 = (firstByte << 24) + (secondByte << 16) + (thirdByte << 8) + fourthByte;  // Put them together
      
      // removed lcd code for clarity...
      
      
    return(poss1);                                            // returns value of encoder 1 position as a long

    This looks a bit funky at first, but remember, we are using a register table in the device. The begin/send/end part in the first 3 lines tell the MD03 what register we want to read (encoderOne). We then do a requestFrom for the 4 bytes, and read in the bytes, finally putting them together to get a 32-bit value.

    Devantech also has an I2C tutorial that you may want to look at (or google around for another, there's quite a few, this was just one that I knew the address of): http://www.robot-electronics.co.uk/a...he_i2c_bus.htm

    -Fergs

  7. #7
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: MD23 Motor Driver and Arduino

    That is helpful but I got most of that already. I think my problem is hardware not software. I try and begin transmission with the device but I don't get a light like I should. All the jumpers are connected so the address must be right. Everything is wired but the resistors and when the transmission is ended the light flashes but that is the only time.

    Edit:
    Sorry didn't see your message I'll check it out.
    Dalton Caughell

  8. #8
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    127

    Re: MD23 Motor Driver and Arduino

    Quote Originally Posted by ROBOTMAN View Post
    Everything is wired but the resistors... .
    You mean the 1K8 resistors? Yeah you NEED those... it's also I2C spec. (1k8 is really quite low, making me really think they need them. The Arduino is equivalent to a 10-30k pullup, so it's not getting enough current to bounce back possibly).

    EDIT: Oh, and I just noticed that their schematic is WRONG. You need a 1k8 between VCC and SCL, and another between VCC and SDA, not two on SDA.

    -Fergs
    Last edited by lnxfergy; 01-07-2010 at 07:38 PM.

  9. #9
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: MD23 Motor Driver and Arduino

    Nothing seems to work. I can't tell if the encoder reset works and because my encoders are not connected I can't run the other code. I made this program based on what I learned and it wont work.

    #include <Wire.h>

    #define md23Address 0x58 // Address of the MD22
    #define softwareReg 0x0D // Byte to read the software version
    #define speed1 0x00 // Byte to send speed to first motor
    #define speed2 0x01 // Byte to send speed to second motor
    #define cmdByte 0x10 // Command byte
    #define encoderOne 0x02 // Byte to read motor encoder 1
    #define encoderTwo 0x06 // Byte to read motor encoder 2



    void setup()
    {
    Wire.begin();
    }

    long encoder1;

    void loop()
    {
    int x = 0;
    x = 255;
    Wire.beginTransmission(md23Address);
    Wire.send(speed1);
    Wire.send(x); // Putting the value 0x20 to reset encoders
    Wire.endTransmission();
    delay(100);
    }

    Because it is a loop you would think the light would keep blinking but it only blinks once and nothing happens.

    Edit:
    Again missed the post I'll work on it.
    Dalton Caughell

  10. #10
    Join Date
    Dec 2008
    Location
    Washington
    Posts
    312
    Images
    35
    Rep Power
    41

    Re: MD23 Motor Driver and Arduino

    I rewired everything and connected it the way you told me. Still nothing. I tested the motors and they work. Could accidentally attaching the resistors to 9v instead of 5v have broken the controller? I assume vcc means regulated 5v right? No deadly blue smoke came out so I thought I was fine. Also the 1k8 resistor would be BROWN, GRAY, RED and 1.700ish k right?
    Last edited by ROBOTMAN; 01-07-2010 at 08:23 PM.
    Dalton Caughell

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) How to determine speed with arduino
    By ROBOTMAN in forum Software and Programming
    Replies: 27
    Last Post: 02-02-2011, 08:43 PM
  2. Quick Arduino Question...
    By Azinman in forum Arbotix, Microcontrollers, Arduino
    Replies: 14
    Last Post: 04-07-2009, 06:47 AM
  3. PVision library for Arduino (Pixart/Wiimote to Arduino)
    By shobley in forum Robot Computers
    Replies: 1
    Last Post: 03-01-2009, 05:07 PM
  4. Replies: 6
    Last Post: 01-07-2009, 08:10 AM
  5. Project Arduino and RSRs (Really Small Robots)
    By LinuxGuy in forum Rovers
    Replies: 8
    Last Post: 08-12-2008, 03:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •