Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two new examples #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions Examples/Simple_receive/Simple_receive.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// This code was modified from: https://learn.adafruit.com/adafruit-feather-32u4-radio-with-rfm69hcw-module/using-the-rfm69-radio
// by John Sampson (jcps), with the intention of being a beginner's guide to the RMF69.
// Intended to be used with the Adafruit feathers, but can be modified to use just the RFM69
// **********************************************************************************/

#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>

//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************
//*********************************************************************************************
#define NETWORKID 100 // The same on all nodes that talk to each other
#define NODEID 2 // The unique identifier of this node

//Match frequency to the hardware version of the radio on your Feather
#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************
#define SERIAL_BAUD 115200

/* for Feather 32u4 Radio
#define RFM69_CS 8
#define RFM69_IRQ 7
#define RFM69_IRQN 4 // Pin 7 is IRQ 4!
#define RFM69_RST 4
*/

// for Feather M0 Radio
#define RFM69_CS 8
#define RFM69_IRQ 3
#define RFM69_IRQN 3 // Pin 3 is IRQ 3!
#define RFM69_RST 4
//

/* ESP8266 feather w/wing
#define RFM69_CS 2
#define RFM69_IRQ 15
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
#define RFM69_RST 16
*/

/* Feather 32u4 w/wing
#define RFM69_RST 11 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_IRQ 2 // "SDA" (only SDA/SCL/RX/TX have IRQ!)
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
*/

/* Feather m0 w/wing
#define RFM69_RST 11 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_IRQ 6 // "D"
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
*/

/* Teensy 3.x w/wing
#define RFM69_RST 9 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_IRQ 4 // "C"
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
*/

/* WICED Feather w/wing
#define RFM69_RST PA4 // "A"
#define RFM69_CS PB4 // "B"
#define RFM69_IRQ PA15 // "C"
#define RFM69_IRQN RFM69_IRQ
*/

#define LED 13 // onboard blinky
//#define LED 0 //use 0 on ESP8266

int16_t packetnum = 0; // packet counter, we increment per xmission

RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);

void setup() {
while (!Serial); // wait until serial console is open, remove if not tethered to computer. Delete this line on ESP8266
Serial.begin(SERIAL_BAUD);

Serial.println("Feather RFM69HCW Reciever");

// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);

// Initialize radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)

pinMode(LED, OUTPUT);
Serial.print("\rReceiving at ");
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");
}


void loop() {
if (radio.receiveDone()) // if the radio has recieved a message
{
Serial.print((char*)radio.DATA); //print the message received to serial
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); // print the RSSI (relative received signal strength), basically how "loud" it was to the reciever.
Serial.println("");
}

radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU
}

void Blink(byte PIN, byte DELAY_MS, byte loops)
{
for (byte i=0; i<loops; i++)
{
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
delay(DELAY_MS);
}
}
132 changes: 132 additions & 0 deletions Examples/Simple_send/Simple_send.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// This code was modified from: https://learn.adafruit.com/adafruit-feather-32u4-radio-with-rfm69hcw-module/using-the-rfm69-radio
// by John Sampson (jcps), with the intention of being a beginner's guide to the RMF69.
// Intended to be used with the Adafruit feathers, but can be modified to use just the RFM69
// **********************************************************************************/

#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>

//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************
//*********************************************************************************************
#define NETWORKID 100 // The same on all nodes that talk to each other
#define NODEID 1 // The unique identifier of this node
#define RECEIVER 2 // The recipient of packets

//Match frequency to the hardware version of the radio on your Feather
#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define IS_RFM69HCW true // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************
#define SERIAL_BAUD 115200

/* for Feather 32u4 Radio
#define RFM69_CS 8
#define RFM69_IRQ 7
#define RFM69_IRQN 4 // Pin 7 is IRQ 4!
#define RFM69_RST 4
*/

// for Feather M0 Radio
#define RFM69_CS 8
#define RFM69_IRQ 3
#define RFM69_IRQN 3 // Pin 3 is IRQ 3!
#define RFM69_RST 4
//

/* ESP8266 feather w/wing
#define RFM69_CS 2
#define RFM69_IRQ 15
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
#define RFM69_RST 16
*/

/* Feather 32u4 w/wing
#define RFM69_RST 11 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_IRQ 2 // "SDA" (only SDA/SCL/RX/TX have IRQ!)
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
*/

/* Feather m0 w/wing
#define RFM69_RST 11 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_IRQ 6 // "D"
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
*/

/* Teensy 3.x w/wing
#define RFM69_RST 9 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_IRQ 4 // "C"
#define RFM69_IRQN digitalPinToInterrupt(RFM69_IRQ )
*/

/* WICED Feather w/wing
#define RFM69_RST PA4 // "A"
#define RFM69_CS PB4 // "B"
#define RFM69_IRQ PA15 // "C"
#define RFM69_IRQN RFM69_IRQ
*/

#define LED 13 // onboard blinky
//#define LED 0 //use 0 on ESP8266

RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);

void setup() {
while (!Serial); // wait until serial console is open, remove if not tethered to computer. Delete this line on ESP8266
Serial.begin(SERIAL_BAUD);

Serial.println("Feather RFM69HCW Transmitter - Simple_send");

// Hard Reset the RFM module
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH);
delay(100);
digitalWrite(RFM69_RST, LOW);
delay(100);

// Initialize radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
if (IS_RFM69HCW) {
radio.setHighPower(); // Only for RFM69HCW & HW!
}
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm)

pinMode(LED, OUTPUT);
Serial.print("\nTransmitting at ");
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(" MHz");
}


void loop() {
delay(1000); // Wait 1 second between transmits, could also 'sleep' here!

String packet = "Hello, RFM69!"; // the data you want to send.

Serial.print("Sending: ");
Serial.println(radiopacket);

if (radio.sendWithRetry(RECEIVER, packet, strlen(packet.length()))) { //target node Id, message as string or byte array, message length
Serial.println("OK");
Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks
}

radio.receiveDone(); //put radio in RX mode
Serial.flush(); //make sure all serial data is clocked out before sleeping
}

void Blink(byte PIN, byte DELAY_MS, byte loops)
{
for (byte i=0; i<loops; i++)
{
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
delay(DELAY_MS);
}
}