This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to write and save the data in .txt file on my computer?

Hi guys,

Based on the examples that I found in Zephyr samples documentation, I created the program where I am able to measure the voltage and temperature, and then send the data via BLE to my mobile phone. Now, I am interested to know how can I save the values (for example the voltage values) in .txt file on my computer? I tried to use the regular code in C as I did so many times before, but I am still not able to flash my board and run the code. There are multiple errors such as:

1) note: 'fopen' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'? - even if I have already included this library

2) warning: assignment to 'FILE *' {aka 'int *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
   64 |  voltage_value = fopen("voltage_values.txt", "a+");

3) warning: passing argument 2 of 'fprintf' makes pointer from integer without a cast [-Wint-conversion]
84 | fprintf(voltage_value, batt_mV);

Is there maybe the different code for nRF52832 board and Zephyr? Can you maybe give me some advice or even send me an example which will be definitely the better option. I am looking forward to hear your answer.

Best regards,

Adnan.

  • I created the program where I am able to measure the voltage and temperature, and then send the data via BLE to my mobile phone. Now, I am interested to know how can I save the values (for example the voltage values) in .txt file on my computer?

     So how is the nRF connected to your computer? Or do you intend to transfer the file from the mobile phone to the computer? I am not sure I understand your setup.

    BR,

    Edvin

  • The board is connected via USB to my computer and I just want to write some values (in this case the voltage) in .txt file and save that file to my computer, for example in the same folder where my example is. For the second example, I will use the external power source (in my case the environment emulator) and try to do the same thing. This is the simple example in regular C, but as I mentioned I tried using that code but unsuccessfully. Do you understand better now, what I need. 

    Thanks in advance for any type of help.

    Best regards,

    Adnan.

  • Aduka_27 said:
    The board is connected via USB to my computer

     What board do you refer to? The DK? You are using the nRF52832 DK, right?

    The reason I ask these questions is that the nRF52832 doesn't have a USB peripheral. The USB port on the DK is connected to the programmer. I suspect that you are not developing a commercial product, if you intend to use the nRF52832 DK directly. However, in that case, you can use a UART terminal, such as Termite. This has an option to log the incoming data. You can do this through the Termite settings:

    This is probably possible using other UART terminals as well.

    Best regards,

    Edvin

  • I use the nRF52832 DK board. I just use the existing solutions that are included in Zephyr samples and mix 2 or 3 different samples (read the voltage, measure the temperature, and send the data via BLE). I found that is possible to use MicroPython for creating and reading files in Zephyr. I only need that, to create a txt file, read the temperature, write this file in the file, and close it. That's only what I need for now. And after that, I will be possible to open that file in my application folder. Is that possible with my board and Zephyr, but to program that in embedded C, not in MicroPython.

    If you still cannot understand what I need, this is the link where I found these functions in MicroPython: http://docs.micropython.org/en/v1.8.2/esp8266/esp8266/tutorial/filesystem.html

    Thanks in advance and best regards, 

    Adnan.

  • Aduka_27 said:
    I found that is possible to use MicroPython for creating and reading files in Zephyr.

     That will not work on the nRF52832. Remember that the code is running on the nRF52832 chip, and not on your computer. Since the nRF52832 is not connected to your computer, it can not access the file system on your computer. I am sorry.

    BR,

    Edvin

Related