Go Down

Topic: serial monitor to text file (Read 17747 times) previous topic - next topic


Hello, I was wondering if there was an easy way to output the results in the serial monitor to a text file?
Seems like there should be an easy way of doing that..

thanks for the help and sorry if its been asked before. didn't come up in a search.


This is what I do: I receive data coming from Arduino into Hyperterminal. When finished, I copy/past the received data into notepad and save it for later use.



a little bit more fancy way would be to write a small little program in processing which receive all the data from the serial port and print it to a text file,
if you want i can pass the code to you, but on the other hand it is really easy, you know the processing GUI  is the same as for Ardunio,

ha det bra



I haven't actually tried this, but you should be able to pipe input from a serial port directly to a file by typing something like

COPY COM1 filename.txt

at the "DOS" command line. A Ctrl-Z (hex character 0x1A, ASCII  26) coming in will close the file.

See http://chrio.org/serial/ for ideas.


If you use hyperterminal then it is easy to save any incoming serial data. Just connect to your Arduino, and then go to the 'Transfer->Capture Text' menu option. Select a file to save your data and away you go! All incoming serial data will then be automatically saved for you.


Probably illegal but in fedora linux at 9600 baud for standard ascii characters:

tail -f /dev/ttyUSB0 > myfile

to append

tail -f /dev/ttyUSB0 >> myfile

To watch it in another terminal do

tail -f myfile


If they're not standard covert them to decimal or something. You can even output data to a cvs format if you're a bit creative.
If it was designed by man it can be repaired by man.



Can anyone send me program code to save serial port data in text file format please?



If you are on a Windows system, GoBetwino can do that:



If you have python installed a small script does the job. Below a capture-script for an Arduino generated csv file.

Python - http://www.python.org/ -
Serial Lib - http://pyserial.sourceforge.net/ -

Code: [Select]

import sys, os, serial, threading

def monitor():

   ser = serial.Serial(COMPORT, BAUDRATE, timeout=0)

   while (1):
       line = ser.readline()
       if (line != ""):
           #print line[:-1]         # strip \n
           fields = line[:-1].split('; ');

           // ID = fields[0]
                 // TIME = int(fields[1])
           # print fields
           print "device ID: ", ID
           # write to file
           text_file = open("Pdata.log", "w")
           line = str(TIME) + ": " + str(CT) + "\n"

       # do some other things here

   print "Stop Monitoring"

""" -------------------------------------------

print "Start Serial Monitor"

BAUDRATE = 115200

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131