MikeSpagnol
Posts: 1
Joined: Thu Jul 12, 2018 2:47 pm

Reading Serial data and saving it to a file

Thu Jul 12, 2018 2:54 pm

Hi There, I have the raspberry pi 3 and I would like to save data received from the serial port to a file. I have tried using screen and the script command, but I can't figure out how to do this automated with a script. Any Ideas will be appreciated. Thanks!

User avatar
topguy
Posts: 4750
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading Serial data and saving it to a file

Thu Jul 12, 2018 7:58 pm

Is it "text" data or "binary" data ?
If it is text data, does it have line breaks ?

The simplest way is

Code: Select all

cat /dev/ttyUSB0  >> /home/pi/myfile.txt
But that might only work for certain types of data, and there is no clear way of stopping it.
Is it supposed to run until the Pi is shutdown or disk is full ?

Most likely someone can come up with a 5-line Python script that does it for you.

User avatar
scruss
Posts: 1769
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reading Serial data and saving it to a file

Fri Jul 13, 2018 12:25 am

better yet, grabserial.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Beginners”

Who is online

Users browsing this forum: Baidu [Spider], LTolledo, mooblie and 35 guests