Hello,
I'm pretty new to the ardiuno stuff. All I want is to use a 433Mhz sender/receiver pair to communicate with each other. I'm using the VirtualWire libary.
Here is my sending Arduino Nano's code:
#include <VirtualWire.h>
const int tx_pin = 12;
void setup() {
Serial.begin(9600); // Debugging only
Serial.println("setup");
vw_set_tx_pin(tx_pin);
vw_setup(2000);
}
byte count = 1;
char charBuf[3] = {'1','#',' '};
void loop() {
charBuf[2] = char(count++);
bool success = true;
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("sending:");
Serial.print(charBuf[0]);
Serial.print(charBuf[1]);
Serial.println(byte(charBuf[2]));
//vw_send((uint8_t *)charBuf, sizeof(charBuf));
success = vw_send((uint8_t *)charBuf, 3);
vw_wait_tx();
if (success) {
Serial.println("finished");
} else {
Serial.println("error while sending message");
}
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
And here the receiving end of this (running on an Arduino Uno):
#include <VirtualWire.h>
const int rx_pin = 12;
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("initializing....");
vw_set_rx_pin(rx_pin);
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
Serial.println("done");
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
vw_wait_rx_max(2000);
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(LED_BUILTIN, HIGH); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]);
Serial.print(" ");
}
Serial.println("");
digitalWrite(LED_BUILTIN, LOW);
}
Serial.print("Bad messages received:"); Serial.println(vw_get_rx_bad());
Serial.print("Good messages received:"); Serial.println(vw_get_rx_good());
delay(1000);
}
Very rarely I get a bad message received count. But only like 1 in a 500 shows up like that. I never get a good message through.
I'm currently using these 433Mhz modules:
Receiver module (RX470-4)
Transmitter module (WL102-341)
I also tried to connect the two data-out and data-in ports of the two board directly (practically having a real wire for the 433mhz connection), but that led to the same results.
Any ideas on what's wrong here?