User avatar
bltsandwich1
Posts: 60
Joined: Fri Feb 08, 2013 3:22 pm
Location: Chicago
Contact: Website

Printing to file from arduino serial output

Thu Mar 21, 2013 6:06 pm

I'm looking for a way to send the serial output from an Arduino connected via USB to the Pi.

I am going to be constantly reading data from a simple temperature sensor, and I am wondering if it is possible to copy the serial output to a file. Ideally I would like to do this with python because it is the language I know by far the most about.

I would like to be able to do this so that I don't need a GUI to copy and paste the info from the serial readout, and also because the Pi may lose power, and I want to make sure that the serial data is saved.

Thanks for any help!
John
facebook.com/chicagoraspberryjam - join in the fun
Majoring in ChemE at the University of Houston.

User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Re: Printing to file from arduino serial output

Thu Mar 21, 2013 7:24 pm

You can use pyserial to handle the serial comms http://pyserial.sourceforge.net/shortintro.html, then just standard python file io to write the file. If you need more details, just ask.

cae2100
Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: Printing to file from arduino serial output

Thu Mar 21, 2013 7:32 pm

and here's a simple program to get user input and outputs it to a file

Code: Select all

fob = open('output.txt', 'w')
blahvar = raw_input()
print fob.write(blahvar)
fob.close
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

User avatar
bltsandwich1
Posts: 60
Joined: Fri Feb 08, 2013 3:22 pm
Location: Chicago
Contact: Website

Re: Printing to file from arduino serial output

Thu Mar 21, 2013 9:59 pm

So using Pyserial all I would have to do is flash the arduino with a code that included a serial output of the temperature reading, and then run that sketch with the arduino connected to the pi correct?

Thanks for pointing me to pyserial!
John
facebook.com/chicagoraspberryjam - join in the fun
Majoring in ChemE at the University of Houston.

User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Re: Printing to file from arduino serial output

Fri Mar 22, 2013 7:15 pm

Yes, absolutely. Just check which port the Arduino uses - run dmesg just after you plug it in, and it will be in the output at the end.

cae2100
Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: Printing to file from arduino serial output

Fri Mar 22, 2013 7:28 pm

most of the time, arduino is attached to /dev/ttyACM0
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

Return to “Python”