Pages: [1]   Go Down
Author Topic: Need basic code to run a motor  (Read 1708 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 603
Posts: 33389
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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.
« Last Edit: December 14, 2012, 05:22:34 pm by Dexter7 » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Note:
Code:
#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:
    Wire.beginTransmission(MD25ADDRESS);
    Wire.write(0);  // Motoe 1 speed register
    Wire.write(speed);
    Wire.endTransmission();
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

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

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

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() .
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

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

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

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?
« Last Edit: December 18, 2012, 11:32:08 am by Dexter7 » Logged

Italy
Offline Offline
Newbie
*
Karma: 1
Posts: 27
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

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
Logged

Pages: [1]   Go Up
Jump to: