LabVIEW Interface for Arduino Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

LIFA Quadrature Encoder

LIFA Quadrature Encoder

Here is a custom version of LIFA to implement quadrature encoders using an Arduino encoder library (v1.1).  I've included a diff file named LabVIEWInterface.ino.diff in unified diff format which shows the parts that have been changed.

How to Use

If you are not currently using a custom firmware, you simply need to upload this custom firmware instead.

Arduino Uno:

  • Can only implement a single quadrature encoder on pins 2 and 3.  Hook up the A and B channels to these pins.

Arduino Mega 2560:

  • Two encoders implemented by default.  Encoder 0 is on pins 2 and 3 and encoder 1 is on pins 18 and 19.
  • A third encoder may be enabled by uncommenting "// #define ENCODER_OVERRIDE_TWI" (removing the //) and then re-uploading.  If enabled, the two wire interface (TWI) cannot be used.  This includes the I2C protocol.  The third encoder is encoder 2 on pins 20 and 21.

I've tested encoders 2 and 3 an the Arduino Mega 2560 successfully.  Encoder 0 did not seem to work on my Mega for some reason but I have used it in the past successfully on this same Mega.  I do not currently have an Arduino Uno to test.  A US Digital S4-360-250-N-S-B was used.

Please let me know your results and any feedback is appreciated.  Thanks.

(Based on LIFA 2.2.0.79)

Comments
Active Participant Nathan_B.
Active Participant

I don't think that is being caused by code on the Arduino. I'd guess either

a sloppy encoder or an irregular loop execution in your OS.

Member ngdanglong
Member

Hi Nathan

Thank you so much for your answer. I installed LabVIEW 2013 in Windows8.

when i only use Arduino IDE and transfer the data up to Serial Monitor, the speed fluctuate less than when i use labview. the cycle of the loop for both is 30ms.

when i use labview with the loop 500ms, the fluctuation seem disappear. but 500ms is too long

in my projet, i have to sampling with the cycle 10ms

I look forward to hearing from you

Member mhk90
Member

Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Wire -IC:\Program Files (x86)\Arduino\libraries\SPI -IC:\Program Files (x86)\Arduino\libraries\Servo -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal -IC:\Program Files (x86)\Arduino\libraries\RobotIRremote C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\AccelStepper.cpp -o C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\AccelStepper.cpp.o

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Wire -IC:\Program Files (x86)\Arduino\libraries\SPI -IC:\Program Files (x86)\Arduino\libraries\Servo -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal -IC:\Program Files (x86)\Arduino\libraries\RobotIRremote C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\AFMotor.cpp -o C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\AFMotor.cpp.o

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Wire -IC:\Program Files (x86)\Arduino\libraries\SPI -IC:\Program Files (x86)\Arduino\libraries\Servo -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal -IC:\Program Files (x86)\Arduino\libraries\RobotIRremote C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\IRremote.cpp -o C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\IRremote.cpp.o

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\Wire -IC:\Program Files (x86)\Arduino\libraries\SPI -IC:\Program Files (x86)\Arduino\libraries\Servo -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal -IC:\Program Files (x86)\Arduino\libraries\RobotIRremote C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\LIFA_Base.cpp -o C:\Users\MHKHAS~1\AppData\Local\Temp\build4583842850003841044.tmp\LIFA_Base.cpp.o

LabVIEWInterface.ino:18:21: error: Encoder.h: No such file or directory

LabVIEWInterface:30: error: 'Encoder' does not name a type

LabVIEWInterface.ino: In function 'void processCommand(unsigned char*)':

LabVIEWInterface.ino:161: warning: left shift count >= width of type

LabVIEWInterface.ino:161: warning: left shift count >= width of type

LabVIEWInterface:575: error: 'RotEnc0' was not declared in this scope

LabVIEWInterface:597: error: 'RotEnc0' was not declared in this scope

-----------------------------------------------------------------------------------------------------------------------

Hey Nathan, I tried to deploy the firmware in the arduino but I am constantly getting these kinds of errors. Can you please help me out. I have read all the comments of this thread and deleted the imported library of Encoder and reinstall the Arduino software but I am still un able to deploy the firmware (LIFA) into my Uno. Kindly reply.

Hassan

Active Participant Nathan_B.
Active Participant

Because LIFA is old and not supported it does not work with newer versions

if Arduino. You probably need to compile in an older version. However, I

don't recommend using LIFA but instead using this as a reference to create

a custom function in LINX.

Member mhk90
Member

Hey Nathan, I am really a newbie at customm command and all. Can you please convert the custom cammand code on LINX from LIFA? I am really stuck at my project and have to use LabView somehow.

Member KoenVervaeke
Member

Great, this little piece of code fixed it also for me on an Arduino Uno.

Thanks!

Member Tuanliberty92
Member

Hello every one. Hello Nathan_B, help me..please !!!

I have an object about LabView and Arduino..That is "using LabView and Arduino to control speed a DC motor, DC motor is encoder motor. code at LabView and Arduino to display real speed, graph speed".

I must learn about LabView so I can't do this object.

Thanks for reading.

Member vistazo
Member

Hello

My name is Juan, Im from Spain, I did a proyect about arduino and labwiev for a PID control of a cc motor. I dont know if it can help you....I send a part of my proyect....If It can help you tell me and I look for de VIs and I will send you

Member harrypotterdtt
Member

Hi Nathan.

How to use two encoders with arduino Uno?? I know Uno just has two interrupt pins 2,3 but when read your encoder library, i think it will work if i connect encoder 1 to pin 3,5 and encoder 2 to pin 3,4. then i enable them in file Labview interface :

Encoder RotEnc0(2, 5);

//#if defined(__AVR_ATmega2560__)  // Arduino Mega 2560

Encoder RotEnc1(18, 19);

#define ENCODER_OVERRIDE_TWI 

#ifdef ENCODER_OVERRIDE_TWI

Encoder RotEnc2(4, 3);

#endif

//#endif

but it's not work. What wrong with my code ?

Active Participant Nathan_B.
Active Participant

It's been a very long time since I've used this code and I've never

implemented an encoder with a single interrupt pin but IIRC the encoder

library should be able to do it. I'd suggest that you verify that you can

get both encoders working with a basic Arduino sketch using the encoder

library first.

Member harrypotterdtt
Member

thanks u

i haven't arduino mega, i just have arduino uno. i think if use arduino mega it will work because default code write for arduino mega. Now i don't have enough money to buy arduino mega

Active Participant Nathan_B.
Active Participant

Now that I'm at my computer, the code you posted doesn't look correct.  You disable the Arduino Mega check which make the code try and create an encoder on pins 18 and 19 (which an Uno doesn't have).  Also, there are other changes that would be required to do what you want because there are similar checks elsewhere in the code.

Member Tuanliberty92
Member

Hello Juan !

Sorry u ..!! Today I have time to check email.

My name is Tuan. I'm Vietnamese. I'm a student at a univesity of Vietnam.

First, let me thank you for your idea. I feel very happy If you can share to me a part of your project. I think your project is what I need for my project.

Please sent VIs file to me at email address: Tuanliberty92@gmail.com

Thanks you verry much..!!!

Member vistazo
Member

Hello

here I send you a link to my drive where you can donwload de VIs ....I hope it can help you

https://drive.google.com/file/d/0B-91oqgcQaalYmlIR19EZ2VfTzQ/view?usp=sharing

Meet Google Drive - One place for all your files<https://drive.google.com/file/d/0B-91oqgcQaalYmlIR19EZ2VfTzQ/view?usp=sharing>

drive.google.com

Google Drive is a free way to keep your files backed up and easy to reach from any phone, tablet, or computer. Start with 15GB of Google storage - free.

see you

Member Tuanliberty92
Member

thanks you very much, Thank for your project.
it is very well. I hope can keep contact with you in the future to focus about more problem
You're wellcome..!!!

Member anlanl
Member

Hi

I am trying to use your code to get speed of a brushed dc motor from a quadrature encoder. At low speeds, for example upto %30 duty at 3Volts, I correctly read the encoder data. I am using Arduino Uno(Atmega328P). However, when I try to run my motor at higher speeds the program throws "Error 5003". I tried using different byte packet values, baudrate values etc. but I could not solve the issue. Could you help me with this do you have any ideas?

Best.

Member vistazo
Member

Hi

are you using a interuption or PINs? to control via encoder must use interruptions of arduino. If you need i could give you the LIFA code that I used.

Send me a email vistazo123@hotmail.com and I invite you to archives in drive.

bye

Member thanglike5
Member

Untitled.pngHi Nathan_B:

please help me. I used LIFA Encoder LV9.zip and Labview example to count pulse of the encoder but the indicator number only show the level of pulse ( 0,1). I fixed this by changing the labivew code ( I attach labview code below) and it work well. However when the encoder disk rotate fastly, I cant count exactly. example with the pulse is 30% of 255, I count 15pulse/ 1sec. It is the same with the pulse is 50% of 255. I used the arduino uno. Please give me some advice

Member bluebeardx64
Member

Hi Nathan_B.,

 

Can you please guide me on how to get this going. I've tried just about everything but I keep getting an error 5002. I went as far as using Arduino 1.0.3 IDE.

 

The TX and RX light flashes once I run the VI but the encoder values never show on the VI.

 

I'm thinking just maybe I missed a step.

 

I use an UNO and the Encoder Pins are on 2 and 3.

Contributors