LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Inaccuracy in running stepper motor with arduino interface for Labview compared to plain arduino code

Hi,

I have built a calibration rig which controls the pitch and yaw angle of my flow anemometer. I am using the Arduino UNO r3, Easydriver v4.4 and a standard sparkfun motor(https://www.sparkfun.com/products/9238). A 80:1 wormdrive is used to increase the accuracy, with microstepping(default) that gives 355.6 steps per degree((1600*80)/360), one step equals 0.0028 degrees. To test the accuracy of the system i have connected a laser pointer which projects on a wall, where i can measure the distances and calculate the actual angle. This setup enables me to measure the actual angle quite accuratly(~0.01 deg), which is more than sufficient for my needs

First I tested my rig with a standard arduino code for running a stepper motor, which I found here: http://bildr.org/2011/06/easydriver/. I modified the program to make the stepper run a pattern(0,+5,0,-5,0 degrees). I then ran the program and checked that my laser marker returned to the original position. This worked perfectly.

Then I ran the same test using the labview interface for arduino. I then obtained a deviation at the last zero reading of around 0.02 degrees. Yes, I know this sounds small, but if I run it for a long time and many different angles the deviation grows. The error equals 7-8 microsteps(perhaps 2 steps per move?) I have attached my labview code, it is written in labview 2013, i have also added a 10.0 version

Since things are working perfectly without the arduino interface I assume that the problem is somewhere on the labview side of things. If anybody has an idea which can shed light on this problem or can point to a perhaps obvious mistake on my side, it would be greatly appreciated!

Best regards

Pål Egil

Message 1 of 19
(13,101 Views)

Some things to try.

Reduce the acceleration rate.

Reduce the maximum step rate.

Increase the current the Easy Driver feeds the step motor.

Compare your Arduino code with the LIFA code used to drive the step motor. The LIFA code is in LabviewInterface.pde. LabviewInterface.pde is the code that runs on an ARduino that LIFA uses to drive a step motor.  You need to look for a section labeled Stepper.  However, the packets Stepper uses are not documented. Hence it will tae some time to comprehend the code.

As a last resort attach an absolute encoder to the step motor.

hrh1818

0 Kudos
Message 2 of 19
(4,597 Views)

Just to clarify (so people don't get confused), the file name is LabVIEWInterface.ino in the latest version of LIFA.

Message 3 of 19
(4,597 Views)

Hi hrh1818 and Nathan_B., thanks for taking the time to answer.

I have been experimenting a lot since my last post without really being able to solve my problem. Acceleration rate and step speed does not affect my problem(i have tested with low stepping velocities and zero acceleration). I have also increased the current supplied to the easydrivers without any effect. I tried looking at the LabviewInterface code but I must admit to not being a expert in arduino code, and couldnt really figure much out besides that the baud rate seems ok.

I thought I had worked my way around the problem by adding a number of extra microsteps to compensate( +2 for my yaw motor and +6 for my pitch motor, no idea why they are different). Then when I started operating the motors together I found something very peculiar. It seems that when I am operating motor A, while motor B should be standing still, motor B actually moves a little bit. This was experienced using the above added code, changing the input pins to switch between operating motor A and B. To make sure  there wasnt something wrong with my arduino board I tried the same in plain arduino code, it worked perfectly.

I have measured the voltages which the arduino outputs and the difference between running it with and without LIFA is considerable. With LIFA the step-pin on motor B(digital output 3) shows a voltage of 5 V relative to ground. Without LIFA it is something like 0.2 V while motor A is running. The outputs from the arduino to motor A(the one that is supposed to be running) is also very different. Without LIFA the step pin is at 2.5 V, with it is 0 V.

Right now I am quite puzzeled, I cant understand why LIFA is acting this way(I am not saying I cant have done something wrong, but nothing comes to mind right now).

If anybody knows of some project where LIFA has been used to control steppers precisely it would interesting to take a look.

Pål Egil

Message 4 of 19
(4,597 Views)

Hello,

Yes your problem is quite puzzling.

Did you take take the voltage readings using a digital multi meter or an oscilloscope?

What other functions are you using LIFA for?  Would it be possible to bypass this problem by not using LIFA?  That is used the Arduino cde that works and instead of using Arduino's serial monitor to control the stepper motors use Labview.

hrh1818

Message 5 of 19
(4,597 Views)

Hi,

I wasn't thinking very constructivly last night so I just used a multimeter. I have checked things this morning with a scope and have obtained the results shown below. The first two plots show the voltage at the step pin for the two motors starting right before motor A is told to start stepping.

with_LIFA.pngwithout_LIFA.png

As one can see there is a negative spike in the step pin voltage for stepper B which should be standing still. A similar spike has been seen at the end of the timeseries as well. I suspect very much that this is the problem, but I don't understand how using different softwares/firmware should produce such a result. If I zoom in on the top of the step pulses for stepper A one can also see that the signal with LIFA looks quite bad compared to the signal without LIFA. Also some of the spikes are a well below 5V, which i suppose might be the reason for me loosing some steps now and then(the easydriver can be modified to run on 0-3V, which might fix that problem).

with_LIFA_close_up.pngwithout_LIFA_close_up.png

To me it seems that stepping with LIFA is working as long as you dont need high accuracy. It would be interesting to hear somebody from the LIFA teams thought on my findings, perhaps they could point out to me what it is I am doing wrong.

I suppose I can bypass LIFA if I could take care of the serial communication in some different manner, but I wouldn't quite know where to start.

In the meanwhile I will try some other crude fixes, perhaps running the easydrivers from separate arduino boards and power supplies.

0 Kudos
Message 6 of 19
(4,597 Views)

Hello,

I am confused just like you. 

Quite often when one sees interaction like you are seeing it means power supply problems or coupling between two channels in the wiring.   But you do not see this problem when LIFA is not used.   What is the length of the wires between your Arduino board and the Easy Driver:

I will do some testing to see if I can duplicate your results.

With respect to bypassing LIFA I suggest you use two Arduino Unos.  One will use LIFA and be used for collecting data from your experiment. The other will use the Arduino code that has worked well for you  for driving the step motors.  Initially I suggest you use Arduino's serial monitor to control the stepper motors.  Using Arduino's serial monitor will get you up and running sooner than using Labview to duplicate Arduino's serial monitor functions.  

In the documents section there is a VI that uses Adafruit's Motor Shield for driving two step motors and that does not use LIFA.  To get you started I could modify it for use with Easy Drivers.  The name of the VI is Adafruit Motor Shield Stepper Driver.

hrh1818

0 Kudos
Message 7 of 19
(4,597 Views)

Hi again, thanks for your suggestions.

I have had some "progress" since my last post.

First i added an extra arduino board, such that the easydrivers were connected to individual boards. This removed the spikes in the above shown timeseries, but the problem with motor A turning when motor B was being operated was still there.

Next I connected individual power supplies to the two easydrivers, this changed nothing.

Since the chassis of the two motors where connected through the aluminum frame of the calibration rig I also wanted to try to isolate them from one another. I did this by disconnecting one of the motors and connecting a third motor which was just standing on my desk. This changed nothing.

I then decided to go for a correction. I calculated how many steps the error amounted to and added this when i moved the motor.

Then somehow  the error dissapeared(at least nearly) when I was using two arduinos. At least i think so, there could be something random going on.  I dont think I changed anything which should produce this effect, but you never know.

I have now gone back to using one arduino(the error is still there then) and correcting for the drift. From my experiences I have concluded that I need to monitor the accuracy of the calibration rig continously as long as I am using LIFA. But it seems to be working ok for now(but for how long...?). I have to start doing some measurements now if I am ever going to finish my phd, so this will hopefully work.

If you decide to look into things it would however still be very interesting to hear about your findings. A vi which can control the easydriver without LIFA would be very interesting, perhaps also for other people.

The length of the cables between the Uno and the easydrivers are about 10 cm.

Thanks again for your help and comments.

Pål Egil

0 Kudos
Message 8 of 19
(4,597 Views)

Hello

It is good to see you found an acceptable solution to your problem.  As time permits I will work on a VI  for controlling 2 stepper motors that doesn't use LIFA.  In the past a request was made for simultaneously controlling 2 stepper motors.  Brian Schmalz has posted an Arduino sketch for running multiple stepper motors at the same time.   His code will be a good starting point.

hrh1818

0 Kudos
Message 9 of 19
(4,597 Views)

Dear Pål_Egil

I went through your VI and the link you share where you have an easy driver.

Me i use L298 but my LIFA code is not working accordingly.

I try to use the same code that is on the link but the motor does not run.

Can you please help me out.

I will share my LIFA here where i wanted the stepper to rotate once the qr code is scanned.

I am unable to upload my file here.

0 Kudos
Message 10 of 19
(4,597 Views)