serial-port - 在没有 ttyUSB 串行连接的情况下,两个 Arduino 之间通过 RF 433MHz 传输的数据不会显示在 TFT LCD1.8 上
问题描述
发射器工作正常。但是如果没有 ttyUSB 串行连接,接收器就无法工作。我的意思是每当我断开 PC 与接收器的连接时,它都不会显示从发射器获取的数据。我希望它可以在没有 PC 的情况下仅通过外部电源工作。可能出了什么问题?
当我添加外部电源断开 USB 插头与 PC 的连接时,它显示“未连接”
/*
SimpleReceive
This sketch displays text strings received using VirtualWire
Connect the Receiver data pin to Arduino pin 3 (default 11)
*/
#include <VirtualWire.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
//char temperatureChar[4];
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen=VW_MAX_MESSAGE_LEN;
const int buzzer = 2; //buzzer to arduino pin 2
void setup()
{
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255, 255, 255);
// set the font size
TFTscreen.setTextSize(1);
// write the text to the top left corner of the screen
TFTscreen.text("Temp :\n ", 5, 5);
// ste the font size very large for the loop
TFTscreen.setTextSize(2);
pinMode(buzzer, OUTPUT); // Set buzzer - pin 2 as an output
// Initialize the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if(vw_get_message(buf, &buflen)) //non-blocking
{
// set the font color
TFTscreen.stroke(255, 255, 255);
// print the sensor value
TFTscreen.text((char *)buf, 20, 20);
// wait for a moment
delay(1000);
// erase the text you just wrote
TFTscreen.stroke(0, 0, 0);
TFTscreen.text((char *)buf, 20, 20);
tone(buzzer, 2000); // Send 1KHz sound signal...
delay(1000);
noTone(buzzer);
}
else {
// set the font color
TFTscreen.stroke(255, 255, 0);
TFTscreen.setTextSize(1);
// print the sensor value
TFTscreen.text("Not connected", 20, 20);
// wait for a moment
delay(500);
// erase the text you just wrote
TFTscreen.stroke(0, 0, 0);
TFTscreen.setTextSize(1);
TFTscreen.text("Not connected", 20, 20);
}
}
解决方案
解决了。USB 电缆实际上用作天线(无线电)。当我断开它时,它会失去连接。
推荐阅读
- kubernetes - 跟踪 kubeevents 的查询
- ajax - 使用 Spring loginUrlAuthenticationEntryPoint 对服务进行 ajax 调用
- python - Exchangelib 关闭连接
- variables - 将值中包含双引号 (") 的变量从 K8s 部署传递给容器
- python - 根据单元格内容组合来自不同行的数据,并使用 pandas 和 python 根据单元格值创建新列
- c++ - Clang 的 Parallel STL 进展如何?
- ios - AVPlayer 开始播放音频直播后暂停
- python - 在 python 中的 selenium 中将表的内容写入 csv
- kubernetes - pods 是否可以随时超过replicas 中提到的replicas
- google-app-engine - 在 GCP AppEngine 上推送文件的最简单方法是什么?