I have a temperature sensor ( LM35 ) interfaced with an Arduino board and my sketch is able to log values to the serial port, say /dev/ttyACM0
in Ubuntu, and I was able to install pySerial and log the temperature values into a file... I used the command
python -m serial.tools.miniterm /dev/ttyACM0 >> templogger.csv
So it will log values like
27
28
27
into the templogger.csv file.
My requirement is to log the system time also along with this, that is, like
Tue Jun 11 18:42:37 IST 2013,27
Tue Jun 11 18:42:38 IST 2013,28
Tue Jun 11 18:42:39 IST 2013,27
and then possibly plot these values stored in the CSV file to an Android client. How should I proceed? What would be a script to log time and temperature together?
Save following script as 'with_time.py':
import sys
import time
import subprocess
p = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE, bufsize=-1)
# for line in sys.stdin: # This cause buffering!
while True:
line = p.stdout.readline()
if not line:
break
line = time.ctime() + ',' + line
sys.stdout.write(line)
p.wait()
and run following command:
python with_time.py python -u -m serial.tools.miniterm /dev/ttyACM0 >> templogger.csv
尝试qcsvlog-它直接从串行端口绘制图表: https : //github.com/ncp1402/qcsvlog
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.