From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW + Arduino + MD49 (serial communication)

Hi,

I am trying to control a motor through LabVIEW and Arduino. 

I am able to send serial commands to the motor without LabVIEW:

- In Arduino Serial Monitor I type the desired speed (a number), which is sent to the Arduino UNO via USB

- The UNO converts this to the signal an sends a serial message via its pins 10 and 11 to the MD49 controller.  The pins 10 and 11 are configured to work as serial coms, as is done with the code below.

- The MD49 controls the servomotor.

Now I would like to control the motor speed with LabVIEW, using a knob or slider.  Can you help me doing this?  More generally, how can I make the UNO write serial messages through pins 10 and 11 at baud rate 38400?

Some more info about the motor controller can be found at http://www.robot-electronics.co.uk/htm/md49tech.htm.

The UNO is programmed with this code:

/**************************************

*    Arduino example code for MD49    *

*                                     *

*    By James Henderson, 2010.        *

**************************************/

#define CMD        0x00

#define GET_VER    0x29

#define GET_ENC1   0x23

#define GET_ENC2   0x24

#define GET_VI     0x2c

#define GET_ERROR  0x2d

#define SET_ACCEL  0x33

#define SET_SPEED1 0x31

#define SET_SPEED2 0x32

byte enc1a, enc1b, enc1c, enc1d = 0;

byte enc2a, enc2b, enc2c, enc2d = 0;

byte bat_volt, mot1_cur, mot2_cur = 0;

byte ver = 0;

byte error = 0;

int desiredSpeed1 = 0;

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // Rx, Tx

void setup()

{

   Serial.begin(38400);

   mySerial.begin(38400);

//   Serial.begin(9600);

}

void loop()

{

  if (Serial.available() > 0) {

    desiredSpeed1 = Serial.parseInt();

  }

 

  if (desiredSpeed1 != 0)

  {

    mySerial.write((byte)CMD);                   // command byte, moet duidelijk gemaakt worden dat dit een byte is en geen char

    mySerial.write(SET_ACCEL);                 

    mySerial.write(3);                          // Set accelleration to 5

    mySerial.write((byte)CMD);

    mySerial.write(SET_SPEED1);

    mySerial.write(desiredSpeed1);                        // Set motor 1 speed

    mySerial.write((byte)CMD);

  }

  Serial.print("Speed1 = ");

  Serial.println(desiredSpeed1);

 

}

0 Kudos
Message 1 of 6
(6,923 Views)

I'm sure you could probably use LabVIEW alone without the Arduino since you can send serial communication via LabVIEW directly.

However, if you want to use LIFA, you would need to create custom functions that send information out on the second serial connection (your pins 10 and 11).  You basically have to recreate all the functionality into the LIFA firmware as well as the LabVIEW side of LIFA.

To do this, you just need to look at the existing functions and learn how they interact (between LabVIEW and LIFA) then create your own.

0 Kudos
Message 2 of 6
(3,715 Views)

Thank you, Nathan.  It is a good idea, but I cannot use it for two reasons.

1. The Arduino has 0V (logic 0) and 5V (logic 1) as logic levels, and that is what the MD49 motor controller wants.  RS232 has values+3 to +15 volts (logic 0), or the range -3 to -15 volts (logic 1).  This could be solved with some voltage converter.

2. I want to add more functionality later on.

So anyone who has suggestions is kindly invited to post them!

0 Kudos
Message 3 of 6
(3,715 Views)

1.  USB is 5V.

2.  You will need to do what I mentioned in the latter half of my post.

0 Kudos
Message 4 of 6
(3,715 Views)

Has this been resolved? I, too am trying to communicate with my MD49 controller straight from LabVIEW, but MAx can't even communicate with it. Any suggestions?

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 6
(3,715 Views)

James,

I did not resolve my prblem; I made a workaround.  I wanted to automate a series of experiments with waiting times in between them, and prgrammed the Arduino UNO to send a logic 1 to LabVIEW while an experiment was running, and a logic 0 during waiting times.

If you use an extra chip like the UNO, there are plenty of workarounds you can try, depending on what you want to do exactly.  Reliability of the whole system goes down, of course, because you have an extra (cheap!) component.

0 Kudos
Message 6 of 6
(3,715 Views)