MD5 and Arduino Uno

Can any one assist please trying to get the following code to
drive my robot md25 throughth I2c and uno

//#include "mbed.h"
 #include <Arduino.h> 
#include <Wire.h>
/* REGISTERS */
#define REG_SPEED1                  0x00    // R/W  | Motor1 speed (mode 0,1) or speed (mode 2,3)
#define REG_SPEED2                  0x01    // R/W  | Motor2 speed (mode 0,1) or turn (mode 2,3) 
#define REG_ENC1A                   0x02    // R    | Encoder 1 position, 1st byte (highest), capture count when read
#define REG_ENC1B                   0x03    // R    | Encoder 1 position, 2nd byte
#define REG_ENC1C                   0x04    // R    | Encoder 1 position, 3rd byte
#define REG_ENC1D                   0x05    // R    | Encoder 1 position, 4th (lowest byte)
#define REG_ENC2A                   0x06    // R    | Encoder 2 position, 1st  byte (highest), capture count when read
#define REG_ENC2B                   0x07    // R    | Encoder 2 position, 2nd byte
#define REG_ENC2C                   0x08    // R    | Encoder 2 position, 3rd byte
#define REG_ENC2D                   0x09    // R    | Encoder 2 position, 4th byte (lowest byte) 
#define REG_BATTERY_VOLTS           0x0A    // R    | The supply battery voltage
#define REG_MOTOR1_CURRENT          0x0B    // R    | The current through motor 1
#define REG_MOTOR2_CURRENT          0x0C    // R    | The current through motor 2
#define REG_SOFTWARE_REVISION       0x0D    // R    | Software Revision Number
#define REG_ACCELERATION_RATE       0x0E    // R/W  | Optional Acceleration register 
#define REG_MODE                    0x0F    // R/W  | Mode of operation (see below)
#define REG_COMMAND                 0x10    // R/W  | Used for reset of encoder counts and module address changes
 
/* MODES */
#define MODE_0                      0x00    // The meaning of the speed registers is literal speeds in the range of 0 (Full Reverse), 128 (Stop), 255 (Full Forward) (Default Setting).
#define MODE_1                      0x01    // The meaning of the speed registers is literal speeds in the range of -128 (Full Reverse), 0 (Stop), 127 (Full Forward).
#define MODE_2                      0x02    // Speed1 control both motors speed, and speed2 becomes the turn value. Data is in the range of 0 (Full Reverse), 128 (Stop), 255 (Full  Forward).
#define MODE_3                      0x03    // Speed1 control both motors speed, and speed2 becomes the turn value. Data is in the range of -128 (Full Reverse), 0 (Stop), 127 (Full Forward).
 
/* COMMANDS */
#define CMD_ENCODER_RESET           0x20    // Resets the encoder registers to zero
#define CMD_AUTO_SPEED_DISABLE      0x30    // Disables automatic speed regulation
#define CMD_AUTO_SPEED_ENABLE       0x31    // Enables automatic speed regulation (default)
#define CMD_TIMEOUT_DISABLE         0x32    // Disables 2 second timeout of motors (Version 2 onwards only)
#define CMD_TIMEOUT_ENABLE          0x33    // Enables 2 second timeout of motors when no I2C comms (default) (Version 2 onwards only)
#define CMD_CHANGE_I2C_ADDR_1       0xA0    // 1st in sequence to change I2C address
#define CMD_CHANGE_I2C_ADDR_2       0xAA    // 2nd in sequence to change I2C address
#define CMD_CHANGE_I2C_ADDR_3       0xA5    // 3rd in sequence to change I2C address
 
/* I2C ADDRESS */
#define I2C_START_ADDR              0xB0    // The start address of valid I2C addresses. LSB indicates R/W, so add 2 to get next valid. Last valid is 0xBE.
#define I2C_WRITE_BIT               0x00    // Add this to I2C address to perform a write.
#define I2C_READ_BIT                0x01    // Add this to I2C address to perform a read.
 
class MD25 {
private:
    /* Communication */
  //  I2C *i2c_interface;
    
    /* Variables */
    int mode;
    char i2c_address;
    
    /* Generic methods */
    int write(char reg_addr, char *data, int bytes);
    int read(char reg_addr, char *data, int bytes);
    char doDiscover();
public:
   // /* Constructor and Destructor */
    MD25(I2C *i2c_interface, char i2c_address);
    ~MD25(void);
    
    /* Control methods */
    int mode_set(int mode);                 // Set the mode of operation (0 - 3) (default: 0).
    int mode_get();                         // Get the current mode of operation.
    int encoder_reset();                    // Resets the encoder registers.
    int auto_speed_set(bool enabled);       // Enable/disable automatic speed regulation (default: enabled).
    int timeout_set(bool enabled);          // Enable/disable 2 sec timeout of motors when no I2C comms (default: enabled).
    int i2c_addr_set(char address);         // Set a new I2C device address (Default: 0xB0).
    
    /* Data methods */
    int speed1_set(int speed);              // Set the speed of motor 1. (Only mode 0 or 1).
    int speed1_get();                       // Get the set speed of motor 1. (Only mode 0 or 1).
    int speed2_set(int speed);              // Set the speed of motor 2. (Only mode 0 or 1).
    int speed2_get();                       // Get the set speed of motor 2. (Only mode 0 or 1).
    
    int speed_set(int speed);               // Set the speed. (Only mode 2 or 3).
    int speed_get();                        // Get the set speed. (Only mode 2 or 3).
    int turn_set(int turn);                 // Set the turn speed. (Only mode 2 or 3).
    int turn_get();                         // Get the set turn speed. (Only mode 2 or 3).
    
    int acceleration_set(int acceleration); // Set a desired acceleration rate.
    int acceleration_get();                 // Get the set desired acceleration rate.
    
    int encoder1_get();                     // Encoder 1 position.
    int encoder2_get();                     // Encoder 2 position.
    
    float bat_voltage_get();                // Get battery voltage.
    float motor1_current_get();             // Get current for motor 1.
    float motor2_current_get();             // Get current for motor 2.
    
    int software_rev_num_get();             // Returns the software revision in the PIC16F873 controller.
};

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Can any one assist please trying to get the following code to
drive my robot md25 throughth I2c and uno

//#include "mbed.h"
 #include <Arduino.h> 
#include <Wire.h>
/* REGISTERS */
#define REG_SPEED1                  0x00    // R/W  | Motor1 speed (mode 0,1) or speed (mode 2,3)
#define REG_SPEED2                  0x01    // R/W  | Motor2 speed (mode 0,1) or turn (mode 2,3) 
#define REG_ENC1A                   0x02    // R    | Encoder 1 position, 1st byte (highest), capture count when read
#define REG_ENC1B                   0x03    // R    | Encoder 1 position, 2nd byte
#define REG_ENC1C                   0x04    // R    | Encoder 1 position, 3rd byte
#define REG_ENC1D                   0x05    // R    | Encoder 1 position, 4th (lowest byte)
#define REG_ENC2A                   0x06    // R    | Encoder 2 position, 1st  byte (highest), capture count when read
#define REG_ENC2B                   0x07    // R    | Encoder 2 position, 2nd byte
#define REG_ENC2C                   0x08    // R    | Encoder 2 position, 3rd byte
#define REG_ENC2D                   0x09    // R    | Encoder 2 position, 4th byte (lowest byte) 
#define REG_BATTERY_VOLTS           0x0A    // R    | The supply battery voltage
#define REG_MOTOR1_CURRENT          0x0B    // R    | The current through motor 1
#define REG_MOTOR2_CURRENT          0x0C    // R    | The current through motor 2
#define REG_SOFTWARE_REVISION       0x0D    // R    | Software Revision Number
#define REG_ACCELERATION_RATE       0x0E    // R/W  | Optional Acceleration register 
#define REG_MODE                    0x0F    // R/W  | Mode of operation (see below)
#define REG_COMMAND                 0x10    // R/W  | Used for reset of encoder counts and module address changes
 
/* MODES */
#define MODE_0                      0x00    // The meaning of the speed registers is literal speeds in the range of 0 (Full Reverse), 128 (Stop), 255 (Full Forward) (Default Setting).
#define MODE_1                      0x01    // The meaning of the speed registers is literal speeds in the range of -128 (Full Reverse), 0 (Stop), 127 (Full Forward).
#define MODE_2                      0x02    // Speed1 control both motors speed, and speed2 becomes the turn value. Data is in the range of 0 (Full Reverse), 128 (Stop), 255 (Full  Forward).
#define MODE_3                      0x03    // Speed1 control both motors speed, and speed2 becomes the turn value. Data is in the range of -128 (Full Reverse), 0 (Stop), 127 (Full Forward).
 
/* COMMANDS */
#define CMD_ENCODER_RESET           0x20    // Resets the encoder registers to zero
#define CMD_AUTO_SPEED_DISABLE      0x30    // Disables automatic speed regulation
#define CMD_AUTO_SPEED_ENABLE       0x31    // Enables automatic speed regulation (default)
#define CMD_TIMEOUT_DISABLE         0x32    // Disables 2 second timeout of motors (Version 2 onwards only)
#define CMD_TIMEOUT_ENABLE          0x33    // Enables 2 second timeout of motors when no I2C comms (default) (Version 2 onwards only)
#define CMD_CHANGE_I2C_ADDR_1       0xA0    // 1st in sequence to change I2C address
#define CMD_CHANGE_I2C_ADDR_2       0xAA    // 2nd in sequence to change I2C address
#define CMD_CHANGE_I2C_ADDR_3       0xA5    // 3rd in sequence to change I2C address
 
/* I2C ADDRESS */
#define I2C_START_ADDR              0xB0    // The start address of valid I2C addresses. LSB indicates R/W, so add 2 to get next valid. Last valid is 0xBE.
#define I2C_WRITE_BIT               0x00    // Add this to I2C address to perform a write.
#define I2C_READ_BIT                0x01    // Add this to I2C address to perform a read.
 
class MD25 {
private:
    /* Communication */
  //  I2C *i2c_interface;
    
    /* Variables */
    int mode;
    char i2c_address;
    
    /* Generic methods */
    int write(char reg_addr, char *data, int bytes);
    int read(char reg_addr, char *data, int bytes);
    char doDiscover();
public:
   // /* Constructor and Destructor */
    MD25(I2C *i2c_interface, char i2c_address);
    ~MD25(void);
    
    /* Control methods */
    int mode_set(int mode);                 // Set the mode of operation (0 - 3) (default: 0).
    int mode_get();                         // Get the current mode of operation.
    int encoder_reset();                    // Resets the encoder registers.
    int auto_speed_set(bool enabled);       // Enable/disable automatic speed regulation (default: enabled).
    int timeout_set(bool enabled);          // Enable/disable 2 sec timeout of motors when no I2C comms (default: enabled).
    int i2c_addr_set(char address);         // Set a new I2C device address (Default: 0xB0).
    
    /* Data methods */
    int speed1_set(int speed);              // Set the speed of motor 1. (Only mode 0 or 1).
    int speed1_get();                       // Get the set speed of motor 1. (Only mode 0 or 1).
    int speed2_set(int speed);              // Set the speed of motor 2. (Only mode 0 or 1).
    int speed2_get();                       // Get the set speed of motor 2. (Only mode 0 or 1).
    
    int speed_set(int speed);               // Set the speed. (Only mode 2 or 3).
    int speed_get();                        // Get the set speed. (Only mode 2 or 3).
    int turn_set(int turn);                 // Set the turn speed. (Only mode 2 or 3).
    int turn_get();                         // Get the set turn speed. (Only mode 2 or 3).
    
    int acceleration_set(int acceleration); // Set a desired acceleration rate.
    int acceleration_get();                 // Get the set desired acceleration rate.
    
    int encoder1_get();                     // Encoder 1 position.
    int encoder2_get();                     // Encoder 2 position.
    
    float bat_voltage_get();                // Get battery voltage.
    float motor1_current_get();             // Get current for motor 1.
    float motor2_current_get();             // Get current for motor 2.
    
    int software_rev_num_get();             // Returns the software revision in the PIC16F873 controller.
};

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Split from an old unrelated topic

newtoprog2020:
Can any one assist please trying to get the following code to
drive my robot md25 throughth I2c and uno

You need to explain in detail what your program actually does and what you want it to do that is different.

What is a "robot md25"?

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor. The text editor shows line numbers, identifies matching brackets and allows me to search for things like all instances of a particular variable or function.

...R

You've posted this same question 4 times and in none of them have you made any attempt to explain what help you need, what the problems are, what the code does or doesn't do or even what a "robot md25" is. And it's not even a complete Arduino program.

No useful information = no real chance of help.

Steve

Multiple duplicate post merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Once again I apologise for Cross-posting. I am using an MD25 H Bridge Dual 12v 2.8Amp Motor Drive supplied by Robot Electronics with Arduino Uno to drive EMG30 motors. Using I2c my intention is to place in front of the Robot 3 LDRs . This will detect a laser beam and move the Robot forward. The middle LDR would enable the laser to move straight and if it veers of as a result of a bump pointing the laser at side LDR would straighten it. I hope this is clear enough.

Kind regards

new2prog2020

newtoprog2020:
I hope this is clear enough.

I don't mean to be unkind, but it is not at all clear. It's not even clear what parts of the project you can do and what you need help with.

Using I2c my intention is to place in front of the Robot 3 LDRs . This will detect a laser beam and move the Robot forward.

I don't understand what I2C has to do with LDRs unless you have a specific module that communicates using I2C. If you have you need to post a link to its datasheet.

Where will the laser beam come from? Are you thinking of a hand-held laser pointer?

The middle LDR would enable the laser to move straight

This gives me the idea that the laser is attached to the vehicle - but I can't get that idea to match up with the idea of the front LDRs detecting a laser beam.

You need to provide a lot more detail. You have a lot of info and ideas about your project in your head - but we can't access that unless you tell us all about it. Help us to help you.

...R

Let's start with the basics. The code posted doesn't contain a setup() or a loop() so it is not a valid Arduino program. So it doesn't compile and therefore it doesn't do anything.

Other than that is there anything specific we can help with?

Steve

Thank you for your prompt replies. My apologies the 3 LDR would be placed in front of the vehicle. The idea is that when a laser is pointed at the middle LDR the vehicle would move forward . if the vehicle veers off course then the laser would be pointed to either side LDR depending on which direction it veer off and this would straighten the vehicle again. so for example if it veers of to the left shining the laser to the left LDR would straighten it back and vice versa.

I am using MD25 H Bridge Dual 12v 2.8Amp Motor Drive supplied by Robot Electronics with Arduino Uno to drive EMG30 motors. this communicates through Serial or I2C.
Information can be found from the following url.
http://www.robot-electronics.co.uk/htm/md25i2c.htm#speed1
Correct am thinking of using a hand- held laser pointer.

I have the robot built already connected to the
MD25 and motors. Tested the LDRs for readings. However need advice with coding.

Hope this is much clearer.

Kind regards,

new2prog2020

newtoprog2020:
Thank you for your prompt replies. My apologies the 3 LDR would be placed in front of the vehicle. The idea is that when a laser is pointed at the middle LDR the vehicle would move forward . if the vehicle veers off course then the laser would be pointed to either side LDR depending on which direction it veer off and this would straighten the vehicle again. so for example if it veers of to the left shining the laser to the left LDR would straighten it back and vice versa.

Writing code to do that would be straightforward.

However I suspect that you will find the system unworkable in practice because of the difficulty of pointing a hand-held laser accurately and steadily at the relevant LDR while the vehicle is moving.

If the laser is fixed and the robot is started facing the laser and with the laser illuminating the centre LDR then if the robot veers off course the laser would illuminate one of the side LDRs and cause a course correction. This would be a laser equivalent of a line-following robot.

...R

Thank for your advice Robin2. I was thinking to place a DIY lens in front of the LDRs which would allow LDR more light detection. However your explanation seems accurate. My issue is moving the Robot forward having difficulty with how to do this. I understand that the previous code I posted did not have a set up or loop section
I have identified several libraries for the MD25 H Bridge Dual 12v 2.8Amp Motor Drive supplied by Robot Electronics with Arduino Uno to drive EMG30 motors. After building the robot I am now stuck of how to move it using the I2c communication.Information can be found from the following url.
http://www.robot-electronics.co.uk/htm/md25i2c.htm#speed1

You certainly don't need a lens with a laser.

You seem to be trying to tackle two or three problems at the same time. Don't. Deal with them one at a time.

Write a short program to allow you to learn how to control the motors with the h-bridge using fixed values for speed and direction that are stored as variables in the program. Change the values and re-upload the program to see the effect of the changes.

Write another short program that can identify which LDR the laser is shining on and print the name of the LDR on the Arduino Serial Monitor.

I'm not sure where I2C comes into the project. If it is the means to control the motor then it will be part of the motor-control learning I already mentioned. If it is for some other purpose please explain.

...R
Planning and Implementing a Program

newtoprog2020:
I have identified several libraries for the MD25 H Bridge Dual 12v 2.8Amp Motor Drive supplied by Robot Electronics with Arduino Uno to drive EMG30 motors.

How about sharing links to those libraries with us? Or even better, if they come with example programs, try one or two of those examples to drive your motors. Let us know what you tried and how it worked out.

Steve