Go Down

Topic: Need basic code to run a motor (Read 2120 times) previous topic - next topic

Dexter7

I am trying to get a motor running using my Arduino Uno.  It is hooked up using I2C. I'm am using the code shown below...just a basic set of instructions, but the motor won't move.  What am I doing wrong?
Code: [Select]
#include <Wire.h>

void setup()
{
 Wire.begin(); // join i2c bus (address optional for master)
}


void loop()
{
 Wire.beginTransmission(4); // transmit to device #4
 Wire.write(150);              // sends one byte  
 delay(10000);
 Wire.endTransmission();    // stop transmitting
}

johnwasser

Part of the problem is that the library won't send the data until you call Wire.endTransmission().

What motor control hardware is between the Arduino and the motor?  Without knowing what the I2C device it it will be very hard to guess how to control it.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Grumpy_Mike

Sending a value of 150 to the motor controller sets bits 7, 4, 2 and 1.
What are these bits connected to and how did you come up with this value?

Dexter7

#3
Dec 14, 2012, 11:07 pm Last Edit: Dec 14, 2012, 11:22 pm by Dexter7 Reason: 1
I am using the MD25 board from Devantech.  My setup can be seen on this page (see the M25 I2C diagram): http://www.robot-electronics.co.uk/htm/arduino_examples.htm
  I set the value of 150 arbitrarily....I got it from some earlier code.  By "bits," do you mean the pins on the Arduino?  You can see all the connections of the Arduino in the diagram I gave here.

johnwasser

Here is an example of how to use that hardware:
http://www.robot-electronics.co.uk/files/arduino_md25_i2c.ino

Note:
Code: [Select]

#define MD25ADDRESS         0x58                         // Address of the MD25
Wire.beginTransmission(MD25ADDRESS);


Looks like you are using address 4 instead of 0x58.

To set the speed of motor1:
Code: [Select]

    Wire.beginTransmission(MD25ADDRESS);
    Wire.write(0);  // Motoe 1 speed register
    Wire.write(speed);
    Wire.endTransmission();
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Dexter7

I have been trying to get that code to run...the code in http://www.robot-electronics.co.uk/files/arduino_md25_i2c.ino    When I run it, the only thing that happens is the LCD shows "MD25  Example   V:" and that's all.  The motors do not turn.  I can see from the code that "MD25 Example V:" is the call to the LCD print on line 39.  Why won't my motors run and why won't the program continue?

johnwasser


When I run it, the only thing that happens is the LCD shows "MD25  Example   V:" and that's all. 


If the LCD doesn't show a software version number after "MD25  Example   V:" it probably means that it was unable to get the software version number from the driver. I would suspect a bad connection. Re-check all of your wires.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Dexter7

I did check all my wires...I changed the position of each wire on the breadboard and made sure all pins were seated correctly.  A week ago, I took the MD25 and Uno and breadboard and LCD to our local Microcenter help desk and a technician there looked at my wiring and compared it to the wiring on the Devantech website for the MD25 I2C configuration   (http://www.robot-electronics.co.uk/htm/arduino_examples.htm#MD25 RD02 Motor Controller ).  He said everything was wired up correctly.  Could some of my hardware be bad?  Is there some way to check which wire connection is faulty?  I put an extra LCD print statement in the code, and you're right, the program stops at the first call to getSoft() .

johnwasser

The pins used for "MD25 RD02 Motor Controller I2C" and "MD25 RD02 Motor Controller Serial" are the same.  Is there a switch or jumper you need to set on the MD25 to let it know you are using the I2C interface instead of Serial?  Where would we find the MD25 manual?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Dexter7

Here is a webpage showing the correct jumper setup for the MD25: http://www.robot-electronics.co.uk/htm/md25tech.htm      If you scroll down, there are several pictures showing the jumper setup.  The picture for the I2C shows no jumpers are needed for I2C, so that is how I have configured my MD25.   The following link gives a manual for the MD25 for I2C:  http://www.robot-electronics.co.uk/htm/md25i2c.htm    Any idea what could be hanging up my program?

Dexter7

#10
Dec 18, 2012, 05:30 pm Last Edit: Dec 18, 2012, 05:32 pm by Dexter7 Reason: 1
I suspect I damaged my MD 25 by running it with the jumpers set improperly.  I didn't even look at the jumpers until about a week ago.  Up until that time, for about a month, I had been running the Serial as well as the I2C with both jumpers on (the configuration as it was shipped from the factory).  This may be the reason why my program is stopping at the first call to the MD25.  When I first started running the Serial with both jumpers on, the motors were turning and the LCD was displaying values to V and encoder, etc.   Performance degraded after the first few runs of the program, however.   Anyone have similar problems?  Were your problems solved by using a new MD25?

diego3vsan

Dexter7,
I'm using MD03. it works when set as analogic but it dosen't in I2C configuration.
If I will solve my rebus, I'll come back to you with my experiencies.

ciao

Dexter7

diego3vsan,
     Thanks for your help.  I got the motors to run when I went back to Serial mode, using the MD25.  Now, another problem has popped up...my computer doesn't recognize my Uno R3.  You can follow the thread under "Installation and Troubleshooting" see  "UNO R3 NOT DETECTED ANY MORE."
     Thanks,
     Dexter7

Go Up