如何通过串行w/Arduin将动态文本写入LED显示屏

2024-06-26 18:02:22 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我觉得我很接近,但我撞到了一堵墙。我要实现的是:我有一个程序,它计算点击次数,并在值更新时向Arduino(UNO)发送串行数据。在

到目前为止,我有以下工作: -在LED显示屏上滚动字幕(来自Freetronics-http://www.freetronics.com/products/dot-matrix-display-32x16-red#.UOBeKInjmdM) -通过Serial(使用PySerial)将新数据写入Arduino的Python脚本 -Arduino在串行监视器中正确接收数据。。。在

所以我的问题是我不能让它写入LED显示屏,请帮忙!在

我的代码是:

import serial
import argparse

myserial = serial.Serial('/dev/tty.usbmodemfd121', 9600)

parser = argparse.ArgumentParser(description='Example with non-optional arguments')

parser.add_argument('count', action="store", type=str)

results = parser.parse_args()

count = results.count
message = "total clicks: " + count

print message

myserial.write(message)

{cd1>示例:^ 这将向Arduino发送“总点击次数:200次”

这是我的Arduino素描:

^{pr2}$

我一直在运行的错误是^ {< CD2>}将第一个参数作为字符串,而我对C++一无所知,所以我认为我正在扰乱数据类型。在

任何帮助都将不胜感激。在


Tags: 数据import程序parsermessageledcountserial
1条回答
网友
1楼 · 发布于 2024-06-26 18:02:22

因此,虽然我担心串行读取如何与显示驱动混合,但以下是如何将串行读取更改为以字符串形式读取:

连读部分:

if(Serial.available()) {    
...
}

只是读单个字符。你需要把它们存储在缓冲区中。在

更改:

^{pr2}$

收件人:

char serIn[40]; //buffer that will hold the bytes in read from the serialBuffer

然后是串行循环:

if(Serial.available()) {  
    int chars_in = 0;
    //keep reading and printing from serial untill there are bytes in the serial buffer
    while (Serial.available()>0 && chars_in<39){
        serIn[chars_in] = Serial.read();    //read Serial   
        Serial.write( byte(serIn[chars_in]));
        chars_in++;
    }
    serIn[chars_in] = 0;
    //the serial buffer is over just go to the line (or pass your favorite stop char)               
    Serial.println();
}

相关问题 更多 >