Transfer of serial data to arduino | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
Transfer of serial data to arduino
October 30, 2016
3:00 am
Avatar
KKG
New Member
Members
Forum Posts: 2
Member Since:
October 22, 2016
sp_UserOfflineSmall Offline

Hi Geverywhere, 

First of all - I am fairly new to labview and programming in C. I have used the Arduino IDE for small projects a lot of times.

This is my first post on any forum - so I hope i bring enough information about the things I am currently working on.

The first thing that I would like to accomplice it to efficiently transfer a set of instructions to the Arduino and making sure that it receives all of the information, the arduino should then split up the data and input that into the specific variables (controlling motors etc...). In the arduino IDE I would accomplish this by making use of special characters like < > to indicate the start and the end of the serial information stream. I would specify what the information is by using code like this <Speed500Speed!Rotation250Rotation!> (in reality it would be simplier). In the example below I have tried to construct something similar - but it is for some reason not very stable - especially if you send code similar to the one mentioned before. I am sure that I am doing something wrong and to most the code would look strange - maybe this is mostly because I have been troubleshooting for some time now. I would be grateful for any tips on best practices on this topic!

At a later stage I would like to have the Arduino send time,current speed, current rotations, rotations left ...etc.. back at a running vi on my computer. The vi running on my computer is fairly good, but I would like too make sure that it still have time to listen if there is new settings/instructions/updates for it on the serial connection.

I would be extremely happy if anyone could give any information or best of all - examples on how to accomplish this task.

If anyone have examples also related something like this then I would also be very interested.

Best regards,

Kenneth

 

SerialComTest5-picture.pngImage Enlarger

sp_PlupAttachments Attachments
October 31, 2016
4:16 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

There are a few problems off hand.  First, you are checking for any bytes at the port and as soon as you read more than 0, you read the buffer immediately.  But if there are still bytes being transferred, you will likely not receive all the bytes because the read will be done before all bytes are received.  A crude improvement is to have a delay between the check for bytes and the read.  But a better way is to use the Serial Read Bytes Until.vi which will terminate the read either after a specified termination character is received or a timeout.  You could trigger off the ending '>' character.  This is very similar to how you would do serial transfer in LabVIEW.  There is an example project we created that has a serial handler you could certainly reference.  It is located here.

Also, you are always writing back out to the serial port even if nothing is received.  This may not be what you want as I think you are trying to write back what was received in, in which case you would not want to keep writing.  You should also eliminate the use of the sequence structure and local variable in this situation, and use the provided delay functions which have error in/out for flow control.  Take a look at the referenced example which should help you.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
22
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356