I'm new to Arduino. I'm h开发者_JAVA技巧aving some problems connnecting two Arduino's together via an RF module. Everything looks correct to me, but the receiver isn't outputting any text sent from the transmitter. I've also tried connecting pins 10 together directly to both Arduino nano's and again, nothing received on the receiver.
How can this problem be fixed?
// ARDUINO NANO TRANSMITTER
#include <VirtualWire.h>
int i;
void setup() {
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(10);
}
void loop() {
const char *msg = "Test Message";
digitalWrite(13, true);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
digitalWrite(13, false);
delay(200);
}
// ARDUINO NANO RECEIVER
#include <VirtualWire.h>
int i;
void setup() {
Serial.begin(9600);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(10);
vw_rx_start();
}
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) {
Serial.println("Found Something:");
for (i = 0; i < buflen; i++) {
Serial.print(buf[i]);
}
Serial.println("");
}
}
Depending on the transmitters, you may have to do some tuning. I had a couple of RF modules that had potentiometers that I could adjust with a small screwdriver. Another issue I had was not sending enough data quickly enough - sending a single character failed, but sending a whole string worked fine. This does not appear to be the problem in your case, however.
精彩评论