I'm planning to have multiple transmitter then send it to one receiver. The problem for sending data is when the two transmitter will send the data at the same time. So my sketch code for my transmitter will be this:
#include <VirtualWire.h>
void setup()
{
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
}
void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}
this means that if the sending of data was not successful it will send it again and again. Does my code is right? I'm just a newbie here. Thanks for your help.
You don't know if the sending of data was succesful.
If the receiver got the message and the checksum was okay, the data was succesfully transmitted. However, the transmitter will never know.
The function "vx_tx_active()" returns the state of the transmitter (active or not).
Sometimes a message is transmitted 10 times, to be sure that one of them reaches the receiver.
The transmitter will send as often as you tell it to.
A better solution is a transceiver; the host tells slave 1 to transmit, so it does, then the host tells slave 2 to transmit, so it does.
If you are just checking to see that both slaves are alive, you can have each one transmit with different time periods between sends so they both transmit at the same time only occasionally.