ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
02-15-2022 04:13 AM
Hello,
i have a project where i get a dezimal number with 20 digits after the comma as an string from an Arduino. I want to convert this string into a number so i can plot and display it in LabVIEW. Now to my problem i tried already using the Scan from string (with different formatting types) and the Fract/Exp string to number block but i cant get all the dezimal points into the number value only 3 dezimal points. I already tried to solve this problem now for a long time but just cant figure it out. Does anyone have any idea how i could solve this? Attached my VI and a screenshot of the number i want to have and which number i get (Probe 8 is the string i get and probe 9 is the number after the conversion).
Best regards
Mismatch
Solved! Go to Solution.
02-15-2022 04:39 AM - edited 02-15-2022 04:39 AM
02-15-2022 04:56 AM
GerdW,
thank you for the quick answer.
The thing is that i want to save this value into a csv file but the saved value only has 3 digits after the comma, when i change the display format to more digits everything works fine on the front panel but the value of the line itself only gives me 3 digits (hope you understand what i mean by that)
best regards
02-15-2022 05:11 AM - edited 02-15-2022 05:12 AM
Hi mismatch,
@Mísmatch wrote:
The thing is that i want to save this value into a csv file but the saved value only has 3 digits after the comma
Then you need to set a better format string when converting your numeric data back into strings for CSV file creation!
Forgot to ask in my first message: why and how does your Arduino create numeric data with 20 significant digits? AFAIK its ADC only allows for 10 bit resolution (or <4 decimal digits)…
It would also help when you would attach your VI downconverted to LV2019 or older. Not everybody already uses LV2021.
02-15-2022 06:14 AM
Hey GerdW,
i have a separate ADC which gives the data to the Arduino( its a surface current measurement which deals with currents somewhere in the range of milli to nano amps).
I hope i did the saving correctly for LV2019.
Also i guess its not the best approach to save the numeric data, instead it would be better to convert it back to string (or just take the string itself and only use the numeric value to display it?).
I also got some issues with saving the time stamps, so atm i just use the "Write To Measurement File" quick VI which also isn´t the best approach to do it.
thank you again
Best regards,
Mismatch
02-15-2022 06:33 AM - edited 02-15-2022 06:36 AM
Hi mismatch,
why are there no separator chars between your measurement values?
How do you want to parse a string like "0.0003160.0003180.0003230.0003270.0003340.0003390.000343" into an array of 7 elements???
Have your Arduino place a TAB/SPACE/CR/LF/semicolon between you numeric values!
Ok, I just notice you already use a LF in the serial transmission: also place a separator in your concatenated string…
Which values do you expect when your Arduino sends strings like "0.000316", aka just 3 significant digits per value? Have your Arduino send number using a better formatting to recieve more than 3 significant digits!
02-15-2022 07:03 AM
Hey GerdW,
the saving itself works and i get the data like i want it, the only thing is that i only get 3 digits after the comma and not the 20 my Arduino sends. In the string the data is also correct only after i convert it it only saves the 3 digits after the comma. I guess i will just try and save the string and see if this works then. Attached also a screenshot from the Arduino com port where you can see the data i receive (just some dummy data to test the LabVIEW program).
Best regards,
Mismatch
02-15-2022 07:16 AM
1. I recommend not using the Write To Measurement File Express VI. It is doing a lot behind the scenes that you do not want.
2. Use Write Text File to just write your string straight to your file.
3. You need to close your file after your loop.
4. You should probably have your file have a "txt" extension instead of "csv" since you do not really have Comma Separated Values (you are using the comma as the decimal point due to localization).
5. There is a lot of extra stuff in this VI that you can just remove (looking at the serial port setup since it looks like you are just using the default settings).
02-15-2022 08:02 AM - edited 02-15-2022 08:02 AM
Hi mismatch,
@Mísmatch wrote:
the saving itself works and i get the data like i want it, the only thing is that i only get 3 digits after the comma and not the 20 my Arduino sends. In the string the data is also correct only after i convert it it only saves the 3 digits after the comma.
According to the default data in the "Measurement" string indicator you do NOT receive those 20 digits from your Arduino. There are only 3 significant digits for each number! That's the reason you only get 3 digits after conversion from string to numeric.
See this part of your code:
02-15-2022 08:30 AM - edited 02-15-2022 08:41 AM
Gerd, what is the search and replace doing in there? Just use "%,%.6f" format string
%, use comma radix separator
%. use period ""
%; use local "" <default>
For all following formatting until a new radix separator is declared.
The following %.6f ignores periods and looks for commas and coerces the float to 6 digits after the comma. That does not change the default display format of any probes or FP objects though.
If there really are 20 sig digits the float should be EXT however, with the Arduinos ADC a SGL should suffice.