简体   繁体   English

使用Arduino和pySerial进行串行数据记录

[英]Serial data logging using Arduino and pySerial

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 我有一个与Arduino开发板连接的温度传感器( LM35 ),我的草图能够将值记录到串行端口,例如Ubuntu中的/dev/ttyACM0 ,并且我能够安装pySerial并将温度值记录到文件中。 ..我用的命令

python -m serial.tools.miniterm /dev/ttyACM0 >> templogger.csv

So it will log values like 因此它将记录类似的值

27
28
27

into the templogger.csv file. 放入templogger.csv文件。

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. 然后可能会将存储在CSV文件中的这些值绘制到Android客户端。 How should I proceed? 我应该如何进行? What would be a script to log time and temperature together? 一起记录时间和温度的脚本是什么?

Save following script as 'with_time.py': 将以下脚本另存为“ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM