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 4 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
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

Attachments
October 31, 2016
4:16 am
Avatar
Steffan
Admin
Forum Posts: 304
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: 33

Currently Online:
5 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

John: 18

RTSLVU: 15

Dan6077: 11

Member Stats:

Guest Posters: 0

Members: 80

Moderators: 0

Admins: 3

Forum Stats:

Groups: 1

Forums: 2

Topics: 58

Posts: 289

Newest Members: Geraldkix, ThomasSoogs, Angelvor, AngelaMuh, Nsneilohone

Administrators: geadmin: 5, filipealtoe: 35, Steffan: 89