11-15-2016 10:32 AM
I have few problems when I try to control the servo motors, which are connected to digital inputs on Arduino Nano, through LabVIEW.
Goal: The goal is to be able to control the motors with a slide I have on the front panel in Labview. And I want it to change continuously. As if I had a physical potentiometer.
Problems:
I attached pictures on my labview code and below you can see the arduino code.
Grateful for some help!
Arduino code:
void setup() {
Serial.begin(115200);
//attach all the servos to the pins on the arduino
for (int currentServo = 0; currentServo < ALL_FINGERS; currentServo++){
servoHand[currentServo].attach(servoPins[currentServo]);
}
for (int currentServo = 0; currentServo < ALL_FINGERS; currentServo++){
servoHand[currentServo].write(LIFT_POS);
}
}
void loop() {
if (Serial.available() > 0) {
str = "";
}
while(Serial.available() > 0){
cmd = ((byte)Serial.read());
if(cmd == '\n'){
break;
}else{
str += cmd;
}
delay(100);
}
finger = getValue(str,';',0);
touch = getValue(str,';',1); //separate the input string from LabVIEW
if (touch == "CHANGE"){
valueServo = finger.toInt();
for (int currentServo = 0; currentServo < ALL_FINGERS; currentServo++){
servoHand[currentServo].write(valueServo);
}
TOUCH_POS = valueServo;
}
}
11-15-2016 04:09 PM
1100ms wait seems like a very long wait to send data, also the timeout on the port is set to default in your program anyways. You set that with the configure serial port function. Also you may lose connection to the port because you are continually flushing and clearing the port, you have no delay in your loop when the slider has not changed value. This seems like a lot on the port and you might drop the connection, also i always put a 100ms wait after clearing a port before i do anything with it. If you dont need to clear it everytime i would remove those functions in the false statement. If you do need to clear it i would wire a 100ms time delay after the clear.
11-15-2016 06:15 PM
Sorry for the double post, but i forgot you can download a labview interface for arduino and get rid of the code running on your arduino. You still have to install it on arduino, but ive played around with it. Might make your life easier.
11-16-2016 05:37 AM
Hi,
To make arduino programming easier using labVIEW, there is and arduino API called LINX, which is available through VIPM. You can try that, it will help and it also has example codes and support for many sensors.
11-16-2016 08:04 AM
Thank you for your reply Matt.
I put the delay when sending data because it doesn't seem like it manage to send something to Arduino. Because when I activate the "highlight execution", then the motors start to move. So I guessed I needed some delay, but maybe it is because of something else?
About the clearing: I thought I needed that to prevent overload of data. But maybe in this case it is not needed?
Now I removed the case structure so there are no clearing. But it still acts the same as before, besides that it doesn't react if holding down the mouse button.
I've tried the LIFA before, but it keeps on running in the init VI. Don't know if it has to do something about when I choose type of board. I use Arudino nano, but I can't choose that on the board type of the VI so I tried Uno. And that is when it gets stuck in "init". Do you know more about that?
11-16-2016 08:07 AM
Hi,
Don't use LIFA anymore. It is slightly buggy and outdated.
Try getting LINX, it should have a subVI dedicated to servo without much bug.
11-16-2016 10:20 AM
Hi Schlok,
you are correct, when i originally downloaded linx i thought it didnt have arduino support. It does have subVI's dedicated for servo control though.
11-17-2016 06:05 AM
Hi,
I attached a VI that might help you.
Check it out.
11-17-2016 10:37 AM
Thank you Shlok, that's very nice.
Sorry for late reply, I wanted to try out another thing before and it took some time.
I wanted to see if Event structure worked before using LINX. Because I've used LINX before in earlier project (one year ago) and then it worked very well to control the motors. But since LINX used a lot of memory already my program got slower when I wanted to do more stuff with it (also, my code could have been not that efficient either since I used a lot of for-loops). So that's why I wanted to try Visa Write instead since my program is much larger now.
Visa write has been working pretty good for the rest of the project (just sending values and which motor I want to control), it was just this small part where I wanted to control the motors with a slide (in labview) which didn't work.
So now, I changed to an event structure instead. And the problem was that I had an delay in the arduino code it didn't manage to read the values continously from the serial port. It works now as I wanted, besides that the labview program got a bit slow instead (but that's another problem).
Thank you both for helping me!
Best regards
Pamela
08-13-2023 09:12 AM
hi , i am very new to LabVIEW can anyone please help me to interface servo motor and Arduino to LabVIEW .