Porting VirtualWire to Arduino Due

Hello,

I am a new Arduino owner, but I have extensive programming experience and some electronics experience.

I have purchased two sets of RF modules online, one operating at 315 MHZ, the other at about 433 MHZ. I know they work, since I receive streams of 1’s and 0’s using digitalread then I send data along the pin. I have verified that the data is coming from the transmitter and not background radiation.

I am trying to use an arduino Due as a receiver and a Nano as a transmitter for one set of these modules, and I can’t figure out how to do it. I know the problem is with the interrupts, I have modifed all of the code required to set up interrupts on the due, and I’ve tried sending/receiving from the due to the nano and vice versa, and no dice either way. I just know it’s something to do with the interrupt, I just can’t see what. I have tried every version of the VirtualWire Library, 1.0,1.4, and my current one, 1.9. I have also tried the “Manchester Class” that I found on these forums somewhere, and I got that to at least send data from the nano to the Due, which confirms my interrupt suspicion, since the only difference in the code between the platforms is the interrupt.

I will post my virtual wire files here, as well as my sketches, I’d be very grateful if someone could offer and pointers. I didn’t make any changes to the virtualwire.h file, so I won’t post that.

Rx Sketch:

// RF Link using VirtualWire to receive messages
// simplex (one-way) receiver with a 315MHz RF Link Receiver module
// rx pin 23 on mega

#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
    Serial.begin(9600);    

// Initialise the IO and ISR
 //   vw_set_ptt_inverted(true);    // Required for RX Link Module
  pinMode(4,INPUT);
  vw_setup(2000);                   // Bits per sec
    vw_set_rx_pin(4);           // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
    vw_rx_start();                      // Start the receiver
Serial.println("Setup Receiver...");
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // check to see if anything has been received
    {
    int i;
     // Message with a good checksum received.
         digitalWrite(13, true); 
    for (i = 0; i < buflen; i++)
    {
        Serial.print(buf[i]);  // the received data is stored in buffer
        }
    Serial.println("");
     }
}

and Tx Sketch:

// RF Link using VirtualWire to Transmit messages
// simplex (one-way) receiver with a 315MHz RF Link Transmitter module
// tx pin 3 on Duemilanova (arduino)

 
#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
  Serial.begin(2400);
     // Initialise the IO and ISR
  //  vw_set_ptt_inverted(true); // Required for RF Link module
    vw_setup(2000);                 // Bits per sec
     pinMode(4,OUTPUT);
    vw_set_tx_pin(4);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs.
}

void loop()
{
    const char *msg = "LMR-II Rocks";       // this is your message to send
 digitalWrite(13, true); 
 Serial.println("SENDING...");
   vw_send((uint8_t *)msg, strlen(msg));
   vw_wait_tx();                                          // Wait for message to finish
   digitalWrite(13, false);
   delay(200);
}

VirtualWire.cpp (18.7 KB)

(Resurrecting this as I only just saw it whilst looking for an answer to the other VirtualWire thread)

Your modification very nearly works :slight_smile: I just needed to change one line:

uint32_t frequency = speed*8;

because VirtualWire uses 8 samples per bit.

Then I deleted all the Serial.print debugging statements - you shouldn’t really use them in an ISR, they are too slow and will ruin the timing of the code.

Attached is the modified file.

VirtualWire.cpp (19 KB)