Python Forum
Getting values from Arduino into python and saving it as csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting values from Arduino into python and saving it as csv file
#1
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
Reply
#2
Are you accessing other ports, COM1, etc. If not, how is the data coming into the computer?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python error on mentioned Arduino port name dghosal 5 845 Aug-22-2023, 04:54 PM
Last Post: deanhystad
  save values permanently in python (perhaps not in a text file)? flash77 8 1,187 Jul-07-2023, 05:44 PM
Last Post: flash77
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,684 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  Saving the times a script is run to a file or ... 3Pinter 7 1,385 Oct-19-2022, 05:38 PM
Last Post: 3Pinter
  Code Assistance needed in saving the file MithunT 0 807 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Saving the print result in a text file Calli 8 1,759 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Saving progress in a Python program to use later Led_Zeppelin 9 2,133 Sep-11-2022, 01:32 PM
Last Post: snippsat
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,641 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Overwrite values in XML file with values from another XML file Paqqno 5 3,293 Apr-01-2022, 11:33 PM
Last Post: Larz60+
  How to split file by same values from column from imported CSV file? Paqqno 5 2,765 Mar-24-2022, 05:25 PM
Last Post: Paqqno

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020