Hello all,
I'm currently attempting to build a receiver that will run for hopefully over a year on three AA batteries. For that I am trying to put the MCU into the SLEEP_MODE_PWR_DOWN sleep mode where it only consumes 30uA or so. The sleep code is using the watchdog timer to wake up the device every few seconds for a few milliseconds.
During this wake time the MCU is supposed to read RF-transmitted using the VirtualWire library. However, this doesn't work reliably at all. In the current setup I have the digital output or the TX MCU directly connected to the RX MCU to eliminate any issues with the RF modules.
My plan was to have the following loop:
void loop()
{
vw_rx_start(); // start receiving RF data
if (vw_wait_rx_max(50))
{
if (vw_get_message(buf, &buflen))
{
if (buflen == 1)
{
if (buf[0] == MSG_ON)
{
Serial.println("On");
}
else
{
Serial.print("Invalid command");
}
}
else
{
Serial.print("Invalid message: ");
}
}
delay(2); // wait for completion of serial transmission
}
vw_rx_stop(); // we're done, stop receiving
system_sleep(); // helper method based on sleep_mode()
}
Well, this didn't work reliably at all. On the transmitting side, I'm sending a MSG_ON command every ms (just on char). Here is a sample Serial output, about 25% of the commands are received:
Wake
Wake
On
Wake
On
Wake
Wake
Wake
On
Wake
On
Wake
Wake
Wake
Wake
On
Wake
On
Wake
Wake
Wake
On
Wake
On
Wake
Wake
I made various changes trying to identify the cause:
- Move vw_rx_start() into setup() and never call vw_rx_stop(). Result: Less missed commands, but still not reliable.
- Replace sleep.h-related code with a simple delay(2000) call but reverse vw_rx_start/stop() changes from point #1. Result: Every second (exactly every second) command is missed. Weird!
- Use delay(2000), move vw_rx_start() into setup() and never call vw_rx_stop(). Result: Finally, the code works flawlessly. Result: Not a single missed command.
Question: Has anybody used the VirtualWire library with SLEEP_MODE_PWR_DOWN and seen similar issues? Anybody knows a solution to this?
Thanks, Christoph