// RFM69HCW Example Sketch // Send serial input characters from one RFM69 node to another // Based on RFM69 library sample code by Felix Rusu // http://LowPowerLab.com/contact // Modified for RFM69HCW by Mike Grusin, 4/16 // This sketch will show you the basics of using an // RFM69HCW radio module. SparkFun's part numbers are: // 915MHz: https://www.sparkfun.com/products/12775 // 434MHz: https://www.sparkfun.com/products/12823 // See the hook-up guide for wiring instructions: // https://learn.sparkfun.com/tutorials/rfm69hcw-hookup-guide // Uses the RFM69 library by Felix Rusu, LowPowerLab.com // Original library: https://www.github.com/lowpowerlab/rfm69 // SparkFun repository: https://github.com/sparkfun/RFM69HCW_Breakout // Include the RFM69 and SPI libraries: #include #include #include #include // Addresses for this node. CHANGE THESE FOR EACH NODE! #define NETWORKID 0 // Must be the same for all nodes #define MYNODEID 2 // My node ID #define TONODEID 1 // Destination node ID // RFM69 frequency, uncomment the frequency of your module: //#define FREQUENCY RF69_433MHZ #define FREQUENCY RF69_915MHZ // AES encryption (or not): #define ENCRYPTKEY "TOPSECRETPASSWRD" // Use the same 16-byte key on all nodes // Use ACKnowledge when sending messages (or not): #define USEACK true // Request ACKs or not // Packet sent/received indicator LED (optional): #define LED A3 // LED positive pin #define PGOOD 3 // PGOOD #define MOSFET 9// // Create a library object for our RFM69HCW module: int level; RFM69 radio; void setup() { // Open a serial port so we can send keystrokes to the module: pinMode(LED,OUTPUT); digitalWrite(LED,LOW); pinMode(MOSFET,OUTPUT); //mosfet pinMode(PGOOD, INPUT); // PGOOD } void loop() { wdt_enable(WDTO_8S); level = digitalRead(PGOOD); if(level == HIGH) { char Tstr[10]; digitalWrite(MOSFET, HIGH); // turn on MOSFET delay(100); radio.initialize(FREQUENCY, MYNODEID, NETWORKID); radio.setHighPower(); // Always use this for RFM69HCW // Turn on encryption if desired: radio.encrypt(ENCRYPTKEY); double T = radio.readTemperature(); char buffer[50]; dtostrf(T, 3,3, Tstr); static int sendlength = strlen(buffer); sprintf(buffer, " T:%s", Tstr); radio.sendWithRetry(TONODEID, buffer, sendlength); Blink(LED,100); } else { sleep(); } } void Blink(byte PIN, int DELAY_MS) // Blink an LED for a given number of ms { digitalWrite(PIN,HIGH); delay(DELAY_MS); digitalWrite(PIN,LOW); } void sleep(void) { digitalWrite(MOSFET, LOW); // turn on MOSFET set_sleep_mode(SLEEP_MODE_PWR_DOWN); //select PWR DOWN, the most power savings sleep_enable(); //set SE bit sei(); // enable global interrupts sleep_cpu(); //actually sleep sleep_disable(); //code reaches this point after interrupt }