python - '1234告诉我你更爱我',第4位不连续显示
问题描述
ATTiny85 使用串行通信将 3 位整数 123 发送到 ATtiny45,然后使用串行通信将其发送到 Raspberry pi。这是工作!
但
如果我发送 1234,这意味着多一个数字,它就不再起作用了。我更改了波特率和读取速度,我以多种方式更改了代码,但我无法读取此链末尾的 4 位数字。它不起作用并快速显示随机字符。
ATtiny85 的代码:
#include <Wire.h>
#include <SendOnlySoftwareSerial.h>
#define TX 4
int c1 = 123;
SendOnlySoftwareSerial toA45(TX);
void setup() {
// put your setup code here, to run once:
Wire.begin();
toA45.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
toA45.println(c1);
delay(5000);
}
ATtiny45 的代码
#include <Wire.h>
#include <SendOnlySoftwareSerial.h>
//#include <SoftwareSerial.h>
#include <ReceiveOnlySoftwareSerial.h>
#define RX 3
#define TX 4
//SoftwareSerial toRip(RX,TX);
SendOnlySoftwareSerial toRip(TX);
ReceiveOnlySoftwareSerial fromA85(RX);
void setup() {
// put your setup code here, to run once:
Wire.begin();
toRip.begin(9600); // changing rate does not help
fromA85.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (fromA85.available()){
toRip.println(fromA85.read());
}
}
Raspberry pi0 的代码
import serial
ser=serial.Serial('dev/serial0',9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ON
bytesize=serial.EIGHTBITS,timeout=1)
while True:
data = ser.readline()
print(data)
解决方案
我在同一个面包板上继续开发其他问题。面包板很旧。我有一个全新的。我可以在 99% 的情况下发送 4 位数字而没有问题。我想知道是否有一种简单的方法可以测试面包板并确定何时结束。
推荐阅读
- julia - Julia 中的 objectid()、hash()、pointer_from_obj() 和 pointer() 有什么区别?
- julia - 在 Julia 时间将数据类型 UInt64 更改为 Float
- python - OpenCV 图像编号识别
- php - 保存 git 凭据 ubuntu www-data
- php - 通过 nginx 反向代理时 PHP 不执行
- gcc - 编译器是否真的产生机器码?
- android-studio - Dart 未定义命名参数“home”
- python - Python - 未定义名称“高度”
- python-3.x - Anisible pip3 install 在远程服务上一直失败(在远程主机中没有找到 setuptools,请先安装它)
- git - Git:如何让日志仅显示与模式匹配的标签?