Virtualwire with external interrupt... arghhhh

Hey guys.

I'm trying to use Virtualwire with an external interrupt to transmit a msg. So i took the Virtualwire transmitter example and modify it to something like this:

#include <VirtualWire.h>

void setup()
{
    attachInterrupt(1, onPulse, FALLING);
    
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec
}

void loop()
{}

void onPulse()
{
    const char *msg = "hello";

    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);
}

It's not working no matter what. Without the external interrupt, i mean, the transmitter code on a loop it works perfectly. I tried both INT0 and INT1 interrupts.

Any ideas? I really need to use interrupts.
Thanks.
Cheers

Do you have a PTT switch? If not, take this line out

vw_set_ptt_inverted(true); // Required for DR3

May also need to add
#include <avr/interrupt.h> // interrupts library
to the top of the sketch100

add this to setup
pinMode (1, INPUT);
digitalWrite (1, HIGH); // turn on internal pullup, keeps the pin High until the interrupt occurs

You're doing a lot of stuff within the ISR. Generally, one just sets a flag in the ISR, and has the code check the flag state; if its set, do something, and then clear the flag. Detach the interrupt while the something is being done so as not to be interrupted in the middle of it, then reattach it when done. This is especially a concern where timers are involved.

Hi. Thanks for the help. :slight_smile:

I modified the code using your advices into this:

#include <VirtualWire.h>
#include <avr/interrupt.h>  // interrupts library

int int_flag=0;

void setup()
{
  
    pinMode(3,INPUT); //interrupt pin
    pinMode(13,OUTPUT);
    
    // Initialise the IO and ISR
    //vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec
    attachInterrupt(1, onPulse, FALLING);
}

void loop()
{
  if(int_flag==1)
  {
    detachInterrupt(1);
    
    //RF CODE
    const char *msg = "hello";
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    
    attachInterrupt(1, onPulse, FALLING);
    int_flag=0;
  }
}

void onPulse()
{
    int_flag=1;
}

It works now... BUT there is a strange behavior.
Once i power the circuit for the first time, it never works.
I need to turn off the power supply and then start it again. Then it works properly.
Im using a pull up resistor on that interrupt pin.

Any tips on this problem?
Thanks once again.
Cheers

Hmm, that's a good one!
It looks good to me.
You're sure the pullup on pin3 is good?

Well i was debugging the hardware pcb and i found this:

  • using Arduino 5v to power my pcb circuit works fine.
  • using 9v adapter with LM317T (with bypass caps) once i power the circuit for the first time, it never works. I need to turn off the power supply and then power it again..

I changed the LM317T, resistors and caps but the problem still occurs.

Then i changed the 9v adapter to a 5v regulated power supply (bypassing the LM317T). Works fine too.

Must be something related with the 9v adapter :cold_sweat: or both LM317T i tried :astonished:
Hi-freq noise? Even with several caps that i tried, 0.1uf, 1uf, 10uf? :astonished:

Suggestions??
Cheers

'This is the first you've mentioned 9V & LM317T. Without seeing a schematic or anything it's hard to comment.

Here it is. As simple as that.. :~

Look at the formula on page 4
http://www.mouser.com/ds/1/149/LM317-59563.pdf
720 and 10K aren't going to provide 5V output.

Vo = 1.25*(1 + R2/R1)
5 =1.25 + 1.25R2/R1
3.75 = 1.25R2/R1
3=R2/R1
R1 = R2/3
R1 = 240 with R2 = 720

Hmm, maybe that's what the big 240 means.
In that case, add 0.1uF caps to Avcc and Vcc (where is Vcc, anyway? Pins 7,8,22 are missing), and connect Aref with a cap to Gnd only, not to +5.

Hey that resistor is indeed 240 ,not 10k! It was my mistake when drawing the schematics. I have 5V on LM317T output (measure with DMM).

Isis Proteus Professional software hides those pins (7,8,22).
They are connected properly otherwise it should not work... ever. XD

I've now added 0.1uF caps to Avcc and Vcc, Aref with a cap to Gnd only as you suggest but the problem remains.

BUT before i added those caps i tested the circuit with a 9v battery...works fine. The problem must come from the adapter. I really dont know why. It's a basic transformer -> full wave rectifier bridge -> caps.
Maybe it's making HF noisy as hell... :astonished: but the caps should that problem.

Sounds like your rectified supply is the problem.
Got a multimeter? Put it on AC and measure the 5V, see if there's a lot of ripple on it.

I have a bunch of adapters around
http://www.dipmicro.com/store/DCA-0510
I order a 5V/7.5V/12V when I order parts, I don't deal with linear power supplies anymore.

On the 5V line - 0.011V AC ripple... Enough to cause those problems?!

Either with 3 switching power supplies / other linear power supply, it work flawlessly.
This one is getting me crazy... XD XD

It's easier to change it, than debugging the problem... but i'm now curious... I just need to know why.. XD

Thanks for your time once again.
Cheers

Don't know at this point.