首页 > 解决方案 > '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)

[编辑:来自 ASCII 表的 3 位和 4 位数字的图片。它需要 1 到 5 个读数,这就是显示的内容。] 3 位数

4 位数

标签: pythonc++serializationraspberry-piattiny

解决方案


我在同一个面包板上继续开发其他问题。面包板很旧。我有一个全新的。我可以在 99% 的情况下发送 4 位数字而没有问题。我想知道是否有一种简单的方法可以测试面包板并确定何时结束。


推荐阅读