Logging data to a CSV or text file from an I2C Sensor

Hello All,

I have several operational pressure, temperature, and humidity I2C sensors. They are taking measurements. My next endeavor is to take that data and write it to a CSV or a text file. I want to graph the data and do other kinds of math to it. Any advice? I looked around, and I can only find data logger shields and SD cards. Is there a way to log data via software?

Thank you

If you can read the sensor data and print it to the Serial monitor then you can also "print" it to a CSV file on an attached SD card

You do not need any extra hardware apart from an SD card module

1 Like

what arduino are you using?
if you have WiFi or Ethernet or a modem available you could upload data to a desktop such as cayenne for display using grpahs, picharts, etc, e.g. how-to-get-data-through-iot

1 Like

An old PC or a RaspberryPi can easily be used; also get a "free" webserver from the configuration ... all free software.

Serial output directly into NodeRED - Arduino for STM32 (stm32duino.com)

You can use USB-serial wired of if PC has Bluetooth, you can go wireless. PC must have Ethernet if you wish to use the webserver.

1 Like

Really? Would the line be CSV.print() instead of Serial.print() . Is there a library to enable this function?

1 Like

If you have an Arduino with an SD card, use the SD library to print data to a file on the card. The library docs and examples show you how.

You can also connect the Arduino to a desktop or laptop via the USB connection, and instead of using the Arduino serial monitor, use any terminal program (TerraTerm, PuTTY, etc.) to log the data to a file on the laptop.

1 Like

Do you mind explaining this further? Thank you

1 Like

What's to explain ?

You open a file on the SD card to write or append to. When you want to save some data you "print" the data to the file. At the appropriate time you close the file

It is your choice whether you open and close the file for each batch of data, say each line, or whether you open it at the start of the sketch and close it at a point in the sketch when data recording is complete

Job done

1 Like

Hi @oxygen02

Here's a tutorial by Adafruit for their micro SD card breakout board:

1 Like

If the file is named CSV.CSV, then yes, that is what you do record to an on-board SD card.

If you have PC to hand, you can record directly thereto, using a standard terminal like RealTerm.

You can also record directly to Excel and display graphs in real time.

The latter two options enable you to timestamp the data using the PC clock.

1 Like

This is what I want know how to do. What do I need for this?

Thank you

1 Like

Stream Data from Arduino into Excel - Arduino Project Hub

2 Likes

If you have Microsoft 365, then it is really easy to do.

There is a 'Data Streamer' Add-In that you can install. After that you just set Excel to read from the correct COM port, and send the data by using Serial.print()

There is more information about it here

1 Like

I will try this

1 Like

I subscribed to Microsoft 365 just for this new feature. As far as I know, it is not available for previous versions of Excel.

1 Like

We ancient humans used locally owned Excel and USB-HID to do similar magic.

String numeric output with V-USB HID - Community / Exhibition / Gallery - Arduino Forum

V-USB and arduino - Using Arduino / Microcontrollers - Arduino Forum

Sorry to hear that you have been "assimilated" ... I hear "resistance is futile" but I am fighting the evil empire.

2 Likes

You have been able to do this with Excel since at least Office 2000, by using the PLX macro, and it's free. If you have the latest Office, fine, if not, look here. I don't suppose Office 365 has any advantage to offer over PLX.

1 Like


PLX-DAQ Version 2
works with all versions of Excel.

1 Like

I believe you are building a data acquisition system using Arduino that will log data to a file in a Windows/Linux/PC .
I have a solution for you

  1. You can use an Arduino to read all your data (pressure, temperature, and humidity values ) and send the data to the PC using USB virtual COM port.
  2. On the PC side you can then use a program written in Python, C# or Java to read from the serial port and log to a file

I was also facing a similar issue where i have to log analog temperature sensors coming from an Arduino UNO to a CSV file on a Windows PC .

Here is my Solution,
I wrote a simple Python script to read all the data send by the Arduino to the Serial Port (Virtual COM) and log into a CSV file.

Screen shot is shown below.

You can use my code to do the same(MIT Licensed Code ).

I have also made a detailed video on

How to write a Python code to log data coming from Arduino Serial port to a CSV file here

  • Source Code link is available in the description of the Video
  • Source code is open source (MIT) feel free to use for commercial or non commercial use

Let me know about your experience with the code.

Feel free to ask me abt the code

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.