首页 > 解决方案 > 在没有 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);

       }
 }

标签: serial-portarduino-unotty

解决方案


解决了。USB 电缆实际上用作天线(无线电)。当我断开它时,它会失去连接。


推荐阅读