Python Forum

Full Version: Getting values from Arduino into python and saving it as csv file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi totally newbie to python here.
I was following this tutorial on how to get data from arduino and saving it as a csv file https://engineersportal.com/blog/2018/2/...g-pyserial

I would like to know how to log multiple sensor values. I know it should be something to do with data parsing.
Here is the code which I use to get the value of just one sensor.

import serial
import time
import csv

ser = serial.Serial('COM3')
ser.flushInput()

while True:
    try:
        ser_bytes = ser.readline()
        decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
        print(decoded_bytes)
        with open("test_data.csv","a", newline='') as f:
            writer = csv.writer(f,delimiter=",")
            writer.writerow([time.strftime("%H : %M : %S"),decoded_bytes])
    except:
        print("Keyboard Interrupt")
        break
Are you accessing other ports, COM1, etc. If not, how is the data coming into the computer?