How do I save Arduino serial data to excel?

How do I save Arduino serial data to excel?There are no simple examples?

This question can hardly be answered without knowing your board and knowing how you want to transmit the data “to excel”, or to a computer or cloud service that can create such a file.

arduino uno R4 wifi this circuit board

There’s multiple ways. For once, you can Serial.println() the data you want to be logged and run a Python script on the host computer that uses the pySerial library to read that serial output, which can then save it to a .csv (csv module) or Excel .xlsx file (OpenPyXML). That is, logging the data coming from the USB cable. There are thousands of tutorials for this out there, see e.g. here and here.

Another approach would be to use the WiFi connnection of the board to send data to a cloud, for example, Google Sheets. You can e.g. use a HTTPClient and Google Scripts for this. Then, no connection to your PC is required.

1 Like

First of all, thank you for your reply, “NO such file or directory serial” error when running python files,But I already have the serial library installed.

What exactly is the content of your Python script and how do you run the Python script?

Only

import serial

And this

import serial
import time
import csv

with open('SensorData.csv', mode='a') as sensor_file:
    sensor_writer = csv.writer(sensor_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    sensor_writer.writerow(["Value", "Time"])
    
com = "COM3"
baud = 9600

x = serial.Serial(com, baud, timeout=0.1)

while x.isOpen() is True:
    data = str(x.readline().decode('utf-8')).rstrip()
    if data is not '':
        print(data)
        with open('SensorData.csv', mode='a') as sensor_file:
            sensor_writer = csv.writer(sensor_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
            sensor_writer.writerow([int(data), str(time.asctime())])

^-- And what about this one.

Because with my Python version installed and running python <file in which script is stored>, it does not even run because it’s using if data is not '' instead of if data != ''

>python test.py
C:\Users\Max\test.py:16: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if data is not '':

That’ with

>python --version
Python 3.11.1

cmd run
import serial

can't open file 'C:\\Users\\xiang\\1.py': [Errno 2] No such file or directory

cmd run sensor_plot.py

import serial
import time
import csv

with open('SensorData.csv', mode='a') as sensor_file:
    sensor_writer = csv.writer(sensor_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    sensor_writer.writerow(["Value", "Time"])
    
com = "COM3"
baud = 9600

x = serial.Serial(com, baud, timeout=0.1)

while x.isOpen() is True:
    data = str(x.readline().decode('utf-8')).rstrip()
    if data is not '':
        print(data)
        with open('SensorData.csv', mode='a') as sensor_file:
            sensor_writer = csv.writer(sensor_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
            sensor_writer.writerow([int(data), str(time.asctime())])
C:\Users\xiang\Desktop\pytest\sensor_plot.py:16: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if data is not '':
202
270
443
541
332
229

Thank you. We can save the data, but there seems to be a problem.

You cannot run Python scripts in the Commandline (cmd.exe) or Powershell. You have to download and install the Python interpreter (from e.g. https://www.python.org/) and run python <your script file> on the commandline.

Thanks for your reply, I installed conda, installed a low version of python and the library, chose the right compiler, and it has been able to run normally

Or you can use the free Excel Datastreamer plug-in, and then send data to Excel !!
Arduino to Excel

1 Like

Thank you for replying. That’s a great way

I use windmill comdebug from windmill software, and both Excel and LO calc have append serial input function

If it’s just about saving the serial data (which is already CSV formatted) to a file, you can also use a builtin PlatformIO “monitor filter” (extra program) with

monitor_filters =
  time      ; Add timestamp with milliseconds for each new line
  log2file  ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory

(docs) and start the serial monitor.

Again, there’s a thousand ways to implement this.

Is it added to platformIO.ini? But I don’t know why the error was reported

Yes it’s added to the platformio.ini. Then you start the serial monitor as normal.

But an error was reported after the addition

I don’t have my crystal balls around me at the moment. You’ll need to post the exact error message and your platformio.ini.