【问题标题】:Serial data logging using Arduino and pySerial使用 Arduino 和 pySerial 进行串行数据记录
【发布时间】:2015-04-27 02:20:03
【问题描述】:

我有一个与 Arduino 板连接的温度传感器 (LM35),我的 sketch 能够将值记录到串行端口,比如 Ubuntu 中的 /dev/ttyACM0,我能够安装 pySerial 并记录温度值到文件中...我使用了命令

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

所以它会记录类似的值

27
28
27

进入 templogger.csv 文件。

我的要求是同时记录系统时间,也就是像

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

然后可能将存储在CSV 文件中的这些值绘制到Android 客户端。我应该如何进行?什么是同时记录时间和温度的脚本?

【问题讨论】:

    标签: android python arduino pyserial


    【解决方案1】:

    将以下脚本另存为“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()
    

    并运行以下命令:

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

    【讨论】:

    • 最好在安卓客户端中绘制时间-温度图怎么样
    • 安卓客户端?您使用哪个应用程序?
    【解决方案2】:

    试试 qcsvlog - 它直接从串口绘制图表:https://github.com/ncp1402/qcsvlog

    【讨论】:

    猜你喜欢
    • 2014-09-10
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    相关资源
    最近更新 更多