Go Down

Topic: Minimal arduino RF transmitter in fritzing (Read 6 times) previous topic - next topic


Ah yes, I was looking for receiver, not radio. :) Going with these instead, much easier than making it from scratch ;)

Can read up on how to put them into sleep instead then.
captain-slow.dk | non contagious!


You can out the arduino into sleep mode pretty easily.

Need  these
#include <avr/sleep.h>      // powerdown library
#include <avr/interrupt.h>  // interrupts library

An easy way to wake up is external interrupt on Int0 or Int1 (low on pins D2, D3).
Set up D2 or D3 as an input with pullup resister enabled, pulling it low via a switch will wake it up.

Not sure what you can do with the transceiver. I only have a transmitter, it doesn't seem to draw much power when no data is sent to it for transmission.
Have to read the transceiver spec, maybe it has something built in. Or maybe add an external transistor to cut Vcc to it.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.


Sleep isn't that important, it is going to be on a wall wart adapter. But it could be fun to try.

How fast is it to wake up?

I am going to use the Int0 as the trigger for when mail is hitting one of the switches inside the mailbox. But that might only be a very short impulse, and no problems if it runs without sleeping.

So what this needs to do, is to wake up when getting an impulse on the Int0, send the message, then go back to sleep.
captain-slow.dk | non contagious!


Jan 28, 2011, 05:41 pm Last Edit: Jan 28, 2011, 05:45 pm by CrossRoads Reason: 1
I think the ATmega spec says something like 6 clock cycles to wake up.
The code I have for my remote  wakes up from sleep,
Code: [Select]

// *  Name:        pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
 /* This brings us back from sleep. */

then restores the output state so reading of the keypad can be done (I had to set low as part of going to sleep so a keypad press could cause a Low interrupt)
Code: [Select]

// *  Name:        enterSleep
void enterSleep()
 /* Setup pin2 as an interrupt and attach handler. */
 attachInterrupt(0, pin2Interrupt, LOW);
 delay(50); // need this?
 /* the sleep modes
  SLEEP_MODE_IDLE - the least power savings
  SLEEP_MODE_PWR_DOWN - the most power savings
 set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
 sleep_enable();                       // setting up for sleep ...
 sleep_mode();                         // now goes to Sleep and waits for the interrupt 

The last line is what actually puts into sleep mode.
Then when the interrupt occurs we keep going
Code: [Select]

 /* The program will continue from here after the interrupt. */  
detachInterrupt(0);                 //disable interrupts while we get ready to read the keypad

 /* First thing to do is disable sleep. */

 // set all the keypad columns back high so can read keypad presses again
 digitalWrite(7, HIGH);
 digitalWrite(8, HIGH);
 digitalWrite(9, HIGH);
 digitalWrite(10, HIGH);
 // then go to the void Loop()

and it does all that so fast the keypad library still catches the button presses to send them over the RF transmitter
Code: [Select]

// this code is in the Void loop
{ // part of code that determines if should go to sleep
if (enter_sleep_mode == 1){
   enterSleep();                             // call Sleep function to put us out
                                             //  THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()
 }                                           // end of checking to go to sleep

   // go read the keypad
 char key = keypad.getKey();                 // reading the keypad
 if(key)                                     // same as if(key != NO_KEY)- did something change?
   msg[0]=key;                               // load the array with the key character
   // msg[1]=NULL;                           // Rx side seems to work without this

   digitalWrite(ledPin, true);               // Flash a light to show transmitting

   vw_send((uint8_t *)msg, strlen(msg));     // send the character out via VirtualWire command

//    Serial.println(key);                // for debugging only

   vw_wait_tx();                             // Wait until the whole message is gone

// other code to turn off the LED and basically start a counter to see if should go back into sleep mode

the order looks a little funny, but the ISR and entersleep functions are defined outside of void loop().
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.


Got the JeeNode v5 today, and assembled it, but is way too tired to figure out how to actually use it... :smiley-sleep:

Very small though, and fits my purpose perfectly. ^_^
captain-slow.dk | non contagious!

Go Up