Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JBous
Novice
1,936 Views

How to write (float) values to a file?

Jump to solution

Hi everyone,

For my project I'm reading a lot of sensor data (float values).

I want to save those values in a file(.txt) so when I'm done reading data I can see all the collected data at once.

Is there a simple way to realise this? Does somebody has some example code of how to do this?

Thanks in advance.

Regards,

Jonas

1 Solution
Diego_V_Intel
Employee
224 Views

Hi JonasBous,

Check the following site: http://www.instructables.com/id/Converting-Float-to-string-and-character-array-in-/?ALLSTEPS Converting Float to string and character array in a few simple steps - arduino - All. At the end, there is an Arduino code that converts a float value to a string value. It might be helpful for you.

You could also use the Datalogger example available under File>Examples>SD to check how a string value can be saved in a text file.

Regards,

Diego

View solution in original post

3 Replies
Diego_V_Intel
Employee
225 Views

Hi JonasBous,

Check the following site: http://www.instructables.com/id/Converting-Float-to-string-and-character-array-in-/?ALLSTEPS Converting Float to string and character array in a few simple steps - arduino - All. At the end, there is an Arduino code that converts a float value to a string value. It might be helpful for you.

You could also use the Datalogger example available under File>Examples>SD to check how a string value can be saved in a text file.

Regards,

Diego

View solution in original post

JBous
Novice
224 Views

Hi Diego,

I don't use an Arduino (I forgot to mention this in my previous post).

I'm using the Intel Edison with the mini breakout board so I'm programming in C-code using the mraa libraries.

Do you have some example code working using that set up?

I want to save the file on the memory of the Edison so I don't use a SD card.

Thanks for your help.

Regards,

Jonas

Diego_V_Intel
Employee
224 Views

Hi JonasBous,

Unfortunately, I don't have a C example code for this. However, you could write your own code. Basically, you have to do two things:

  • Convert from float to string: There are several ways to do this on the web. Actually, the one I posted above might work. You only have to understand how the algorithm works and implement it in C (or any other language). You could also look for other ways to implement this conversion in C, for example:

http://stackoverflow.com/questions/7228438/convert-double-float-to-string http://stackoverflow.com/questions/7228438/convert-double-float-to-string

http://ubuntuforums.org/showthread.php?t=800110 Ubuntu Forums

https://www.youtube.com/watch?v=mc4A5loPWnM C Programming Tutorial 74, Converting Ints and Floats to Strings

  • Save a text file in memory: There are several examples for this on the web too. I recommend you to check the following sites, but you could also look for other examples as well:

http://stackoverflow.com/questions/11573974/write-to-txt-file http://stackoverflow.com/questions/11573974/write-to-txt-file

http://www.programiz.com/c-programming/examples/write-file C Program to Write to a Sentence to a File - C Example

Regards,

Diego

Reply