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.
#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
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 or both LM317T i tried
Hi-freq noise? Even with several caps that i tried, 0.1uf, 1uf, 10uf?
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... 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.