变送器工作正常。但如果没有ttyUSB串行连接,接收器就无法工作。我的意思是,每当我断开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电缆实际上是作为天线(收音机(工作的。当我断开它的连接时,它就会失去连接。