13walkec
Posts: 5
Joined: Wed Aug 10, 2016 4:04 am
Location: Central Wisconsin, USA

Temp reading + print to LibreOffice Calcs

Mon Aug 15, 2016 1:50 pm

Hello all, I have a project I'm doing with a buddy and we are stuck. First I'll go over what the project is to give some background.

We have have permit to make homemade ethanol. We used to do it all manually by sight, sound, and smell but we wanted to add some automation and sensors to the device. I have pretty a pretty in-depth knowledge of the Arduino system so we went that rout to begin with. We have an Arduino Mega, 3 thermocouples, an LCD screen for the temps, a couple relays to turn our water circulation and cooling system on as well as a contractor switch to turn on our heating element to heat the "mash". This worked pretty well however now we wanted to be able to read the temp data online as well as plot the data (the data being the specific temperatures of the different thermocouples among other things) on a spreadsheet for later review. The spreadsheet part was easy I simply downloaded a program called PLX-DAQ (an excel add on) that reads serial data from the Arduino and makes it into an excel sheet, this worked very well. However the printing on a webpage was more difficult we were going to do this with a WiFi or Internet shield. However when we tried this it didn't work, long story short there was so much going on with the Arduino it crashed after 5min every time. So we decided to go with a Raspberry Pi and make the Arduino essentially a slave to it. I'm new to the python language but I feel like I'm catching on pretty quickly however I'm stuck. Below is what I currently have with the Pi setup and in bold is what I can’t figure out.

We currently have 2 ways of reading the thermocouple data on the pi. Either with the terminal window using the code

Code: Select all

 python grabserial 
this will print the three thermocouple temps in the terminal window. If I add

Code: Select all

 >> test.ods 
after this it will create an .ods file on my pi and print the data to that. This would work as we don’t need to see that printed data right away it’s just for further use anyway and we can see that data on the Arduino LCD screen anyway however I can’t figure out how to get this code to run on startup without manually putting it in. The other way I have printed the data is with the code below:

Code: Select all

 
import time 
from datetime import datetime
import serial
datetime.now()
ser = serial.Serial(‘/dev/ttyACM0’,9600)
while True:
	print (ser.readline())
	print(“%s:%s:%s” % (datetime.now().hour, datetime.now().minute, datetime.now().second))
	time.sleep(2)
This will print all three thermocouple temperatures with a time stamp like I want in the python 2 shell. The problem with this code is I can’t figure out how to get it to print the data to an .ods file.

If someone could help me that would be great. If there is an easier way than the two methods I have shown above please let me know I’m open to any advice. Also remember I would like the thermocouple data to be able to be printed on a webpage at some point in the figure but that is a different topic that I haven’t researched as much yet so I’m not too worried about it yet.

Currently using python 2 but can use python 3.
Any fool can write code that a computer can understand. Good programmers write code that humans can understand
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"You know you're in the wrong class when more than 3 students are female, and they're all hot."

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

Re: Temp reading + print to LibreOffice Calcs

Mon Aug 15, 2016 3:25 pm

Does it have to be a true ODS file (that is, a zipped collection of XML files in a very particular format), or can it be CSV? CSV's a pretty good format for logging, and you can open it into any spreadsheet. There are a couple of ways of writing CSV:
  1. The right way: Read up on python's csv module.
  2. The wrong (but very quick) way: print out the header fields once at the top of the file, then every record with the fields separated by commas. Something like: print(','.join(map(str,(val1, val2, val3))))
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

13walkec
Posts: 5
Joined: Wed Aug 10, 2016 4:04 am
Location: Central Wisconsin, USA

Re: Temp reading + print to LibreOffice Calcs

Mon Aug 15, 2016 3:54 pm

scruss wrote:Does it have to be a true ODS file (that is, a zipped collection of XML files in a very particular format), or can it be CSV? CSV's a pretty good format for logging, and you can open it into any spreadsheet. There are a couple of ways of writing CSV:
  1. The right way: Read up on python's csv module.
  2. The wrong (but very quick) way: print out the header fields once at the top of the file, then every record with the fields separated by commas. Something like: print(','.join(map(str,(val1, val2, val3))))
Awesome! Like I said I am pretty new to Python. I didn't realize ODS files were
a zipped collection of XML files...
so it sounds like a CSV file should work. I'll do some reading on the csv module. I'll get back with an update tonight (1050 here) with an update on what I come up with. Thanks Much
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"You know you're in the wrong class when more than 3 students are female, and they're all hot."

Return to “Automation, sensing and robotics”