MD03

Hi guys.
I'm buiding a small tool to controll speed of a 24Vdc motor with arduino and MD03. I like to have a display where I can read Motor Speed, Current and temperature.
I can't move motor. Can you please help me on this issue? is a software or hardware problem?

THANKYOU for your answer and suggestions....

hardware is:
Arduino Leonardo,
MD03 H-bridge
display AMD1602U

this my code:

/*
nome sketch: sketchdisplay con controllo motore
versione: 1.0
autore: diego trevisan
data 30/11/12

hardware: arduino (leonardo); ponte H tipo: MD03; display: AMD1602U ;potenziometro 10Kohm; potenziometro 10Kohm

collegamenti hardware:


LCD AMD1602U - arduino
positivo -  positivo
negativo - negativo
RX - digital 7 (come definito dalla variabile "txPin")

potenziometro impostazione velocità
centrale - analogico 0 definito come "sensorValue"
1 estremo - 5volt;
2 estremo - centrale 2 potenziometro (trim)

potenziometro trim (per tarare lo zero)
centrale - 2 estremo potenziometro lettura angolo
un estremo - negativo

MD03 - arduino
+5V - positivo 5volt
GND - negativo
SCL - SCL
SDA - SDA
switch tutti e 4 su ON
MD03 USCITA
+V positivo alimentazione motore (max 24Vdc)
GND massa alimentazione motore
MOT motore
MOT motore
(se gira al contrario del desiderato, invertire i fili MOT tra loro)
*/

// inserisce 3 librerie di funzioni
#include "Wire.h"
#include "SoftwareSerial.h"

#define ADDRESS             0x58                    // Address of MD03
#define SOFTREG             0x07                    // Byte to read software
#define CMDBYTE             0x00                    // Command byte
#define SPEEDBYTE           0x02                    // Byte to write to speed register
#define TEMPREG             0x04                    // Byte to read temprature
#define CURRENTREG          0x05                    // Byte to read motor current


#define txPin 7 //definisce il pin 7 di arduino come pin di trasmissione dati (sarà usato per mandare dati al display)

byte direct = 1;                                    // Stores what direction the motor should run in

int a, d; // assena il tipo di variabili a, d come numeri interi
int tspd,data; //assegna il tipo di variabile tspd com numero intero
int x; // x è la varialile necessaria per definire quanti gradi corrispondano i 5cm di escursione del potenziometro
int diametro; //è la variabile a cui è assegnato il valore in mm del diametro del tubo di rotazione


SoftwareSerial LCD = SoftwareSerial(0, txPin); //non mi è chiaro questo comando... arriva dalle librerie ma non l'ho capito
const int LCDdelay=100;  // assegna alla variabile LCDdelay il valore di 100 (espresso in millisecondi, quindi 1/10 di secondo)


// definizione delle funzioni per la gestione dell'LCD

//funzione che crea il comando lcdPosition, serve per posizionare il cursore nella posizione riga,colonna scrivendo solo lcdPosition(riga,colonna)
void lcdPosition(int row, int col) {                  
  LCD.write(0xFE);   //command flag
  LCD.write((col + row*64 + 128));    //position 
  delay(LCDdelay);
}

//crea la funzione clarLCD che pilisce il display
void clearLCD(){
  LCD.write(0xFE);   //command flag
  LCD.write(0x01);   //clear command.
  delay(LCDdelay);
}

//crea la funziona backlightOn che accende la retroilluminazione del display
void backlightOn() {  //turns on the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(157);    //light level.
  delay(LCDdelay);
}

//crea la funziona backlightOff che spegne la retroilluminazione del display
void backlightOff(){  //turns off the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(128);     //light level for off.
  delay(LCDdelay);
}

// funzione per spedire dati al modulo MD03
void sendData(byte reg, byte val){         // Function for sending data to MD03
  Wire.beginTransmission(ADDRESS);         // Send data to MD03
    Wire.write(reg);
    Wire.write(val);
  Wire.endTransmission();
}

//definisce la variabile nextPrint quale numero e gli assegna il valore 0
unsigned long nextPrint = 0;


// qui inizia il programma vero e proprio, è formato da 2 parti, la prima "void setup" che viene eseguito solo una volta e "void loop" che viene eseguito all'infinito se arduino è alimentato

void setup() {
 Serial.begin(9600);           //inizializza la porta di comunicazione seriale a 9600 baud
 Wire.begin();                 //inizia il collegamento con l porta seriale
 
 LCD.begin(9600);              //inizializza la porta di comunicazione con l'LCD a 9600 baud
 clearLCD();                   // pulisce il display
 
 backlightOn();                // accemde la luce di retroilluminazione
// backlightOff();
 
 pinMode(txPin, OUTPUT);       //dichiara che il txPin sarà di tipo output ovvero trasmetterà i dati al display. il txPin era stato impostato 4 precedentemente
 lcdPosition(0,0);             //posiziona il cursre nella riga 0 e colonna 0
 LCD.print("Tspd");         // scrive il testo tra " "
 lcdPosition(1,0);             //posiziona il cursre nella riga 0 e colonna 0
 LCD.print("mA  ");         // scrive il testo tra " "
 lcdPosition(1,8);             //posiziona il cursre nella riga 0 e colonna 0
 LCD.print("Temp");         // scrive il testo tra " "
 }

// inizia il ciclo che verrà eseguito per sempre quando arduino ha alimentazione
void loop() {
  while (true) {
    
   // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a value (-250,250):
   tspd= (map(sensorValue,0,1023,-250,250)); //operazione necessaria in quanto si tratta di un partitore quindi la massima tensione è metà della tensione applicata
  
   lcdPosition(0,5);              //posiziona il cursore nella riga 0, colonna 5
      LCD.print("   ");            //scrive 3 spazi (essendo un loop, serve cancellare la precedente lettura, in realtà servirebbe cancellarla solo se la precedente lettura fosse di 3 cifre e l'attuale di 2)
      lcdPosition(0,5);           //posiziona il cursore nella riga 0, colonna 5//riga, colonna
      LCD.print(tspd);             // scrive il valore tspeed (target speed)
      
   int current = analogRead(CURRENTREG);  // Gets motor current
   lcdPosition(1,3);               //posiziona il cursore nella riga 1, colonna 5
      LCD.print("   ");            //scrive 3 spazi (essendo un loop, serve cancellare la precedente lettura, in realtà servirebbe cancellarla solo se la precedente lettura fosse di 3 cifre e l'attuale di 2)
      lcdPosition(1,3);            //posiziona il cursore nella riga 1, colonna 5//riga, colonna
      LCD.print(current);          // scrive il valore current (corrente assorbita dal motore)
      
   int temp = analogRead(TEMPREG);
   lcdPosition(1,13);                //posiziona il cursore nella riga 1, colonna 5
      LCD.print("   ");            //scrive 3 spazi (essendo un loop, serve cancellare la precedente lettura, in realtà servirebbe cancellarla solo se la precedente lettura fosse di 3 cifre e l'attuale di 2)
      lcdPosition(1,13);           //posiziona il cursore nella riga 1, colonna 5//riga, colonna
      LCD.print(TEMPREG);          // scrive il valore tempreg (temperatura regolatore)

sendData(SPEEDBYTE, tspd);         //invia al modulo MD03 il comando per la velocità target tspd
}

}

Can you please help me on this issue?

Not until you post your code correctly. Modify your post. Select the code. Delete it. Start the IDE up, and open the sketch. Use Tools + Auto Format.

Get rid of the infinite loop in loop(). Save the sketch.

Select the # icon to create code tags. Paste the sketch between the tags. Save.

While you are doing that, does the LCD have anything to do with the problem? Did you have a problem before you added it? If so, say that. If not, unplug the LCD and put it back in the drawer and remove all code that deals with it.

Paul thanks for first help on my first post!

LCD is working correctly. I have this info on LCD:

  • Tspd (Target Speed for motor). it is a value read from potentiometer Analogic pin A0. DATA is CORRECT.
  • mA (current). It should be current used by motor. NOT correct data.
  • Temp (temperature). It should be data coming from MD03 (fix value is 4): not corect.

I have doubts about comunication to/from MD03 due to code and hardware.
Hardware: I connected SCL - SCL and SDA - SDA. It should be correct but....
Software: I'm not sure about data reciving and trasmission....

Thankyou!

LCD is working correctly.

Does it have anything to do with your failure to communicate with the MD03? There is only one way to find out.

Did you also connect the grounds and Vcc?

Paul,
I like to try some easy comunication arduino-Md03. A new code to try MD03 without LCD.
I have dubts how to do it.

wold you like to help me on this first step?
connections are:

  • power (no doubt with this);
  • I2C. Is it correct to connect SCL - SCL and SDA - SDA?

If this is correct... may you please help me with code?
I just like to try to send a fix speed and recive temperature from arduino and send it to COM in order to read it on monitor's PC.
This to try Arduino-MOD3 comunication and MD03 proprer operations.

If this will work then I try to merge this code with LCD code in order to have "final" software.

Thankyou!
diego

  • I2C. Is it correct to connect SCL - SCL and SDA - SDA?

Correct, yes. Sufficient, no.

I just like to try to send a fix speed and recive temperature from arduino and send it to COM in order to read it on monitor's PC.

Which ONE do you want to do? Pick ONE, and we'll work on that. Pick TWO and your on your own.

Pick one, get it working. Pick another, get it working. Then, combine two sketches that you know work.

Paul
I think my LCD is working correctly. So let's pick the MD03-Arduino and work on it...
I like to make a code with your help in order to read TEMPERATURE from MD03, set a speed for motor.

On my code I done this "Serial.begin(9600);" in order to give a baud rate of 9600 to the serial.
Then"Wire.begin();" order to start comunication

To read temperature my code is: "int temp = analogRead(TEMPREG);"

To send speed order my code is: "sendData(SPEEDBYTE, tspd);" where tspd is integer value from 0 to 255.

It dosen't work!

So let's pick the MD03-Arduino and work on it...

Is this the MD03 we are talking about?
http://www.robot-electronics.co.uk/htm/md03tech.htm

If so, have you read the note about "temperature"?

To read temperature my code is: "int temp = analogRead(TEMPREG);"

Why? The temperature register is not connected to an analog pin.

To send speed order my code is: "sendData(SPEEDBYTE, tspd);" where tspd is integer value from 0 to 255.

Without seeing sendData, I have no idea whether that does anything useful.

Yes, it is!

I read the note. Temperature is value used internally. I like to convert and read on my LCD. For sure is possible... may be not helpful but possible.
If you prefere give me some help with "current", you are welcome. I like to have booth information on my LCD.

I have not enought background to understand I2C communication protocol. This is main issue for me. I hope a library or some software command solve my issue.


about your last message...
you right, isn't an analogic pin! Is "Wire.read()" more appropriate?
"sendData" is coming from a code foud on WEB. I guess is inside wire.h? isn't?

Have you looked at Nick Gammon's I2C site?

It should answer all (or most) of your questions about I2C.

You do have 4 wires connected between the Arduino and the MD03, right?

correct!

+5Vdc
GND
SCL
SDA

Personally, I'd skip the temperature stuff for now. Move the SDA line to a PWM pin. Move the SCL line to a digital pin. Use analogWrite() to write to the PWM pin, with a value of 0 to 255. The motors should spin, and change speed as the value goes up and down. Setting the SCL pin high or low defines direction.

Once you know that the motors are wired correctly, and the speed and direction are controllable, you could then, if needed, switch the wires back and use I2C to control the motors and get the "temperature".

Thankyou Paul!
I will try it as soon as possible then I will repot to you.
I wrote you a PM.

Keep in touch!
Many thanks

Dear Paul,
I'm back on this project.

With this very easy code it works.

int Speed;
int PinMotore = 9;

void setup() {

}

void loop() {
for(Speed = 0 ; Speed <= 123; Speed +=25s) {
analogWrite(PinMotore, Value);
delay(5000);
}

}

..... Comunication ARDUINO <--> MD03 via I2C still a nightmare! =( =( =(

H E L P ! ! !

Comunication ARDUINO <--> MD03 via I2C still a nightmare!

We don't know what code you are using. We don't know what results you are seeing.

H E L P ! ! !

H o w c a n w e ? ? ?

Paul,
code is in first msg.
output are:

  • Motor not moving,
  • Temperature "4" never changing,
  • Current change between 600 and 900 when changing speed input arduino ---> MD03.

Looks like there is no comunication arduino / MD03. For sure is my fault but I can't go further without help.

thanks
Diego

The code in reply #14, which you said works, looks NOTHING like the code in the original message.

Correct.

First try was comunication via I2C.
code on my msg #14 is using analogic comunications. Analogic comunication is working but I just control motor speed, no Temperature nor Current information are available with this protocol.

Because I need to have MD03 Temperature and Current information and motore speed control, I suppose I must use I2C. I wrote code as per my 1st msg without succes.

I hope, I'm clear writing english... :roll_eyes: