Board: Adafruit Feather 32u4 Radio with RFM69HCW Module
I need to transmit to an Arduino UNO with a RFM69HCW Breakout (SparkFun).
I have been transmitting to the Arduino Uno with a Arduino pro mini with a RFM69HCW Breakout.
Not sure where to begin. The radio setup appears very different for the Feather.
Example code block for each follows.
I had expected them to be quite the same. If I upload my Arduino pro mini code to the Feather
it seems to lock it up.
Please tell me how to alter the Feather code to transmit if you can.
In other words, I need to change the feather code to agree with the Arduino pro mini code.
I need to transmit to an Arduino UNO with a RFM69HCW Breakout (SparkFun).
I have been transmitting to the Arduino Uno with a Arduino pro mini with a RFM69HCW Breakout.
Not sure where to begin. The radio setup appears very different for the Feather.
Example code block for each follows.
I had expected them to be quite the same. If I upload my Arduino pro mini code to the Feather
it seems to lock it up.
Please tell me how to alter the Feather code to transmit if you can.
In other words, I need to change the feather code to agree with the Arduino pro mini code.
Code:
//
// RFM69HCW Example Sketch for Arduino pro mini
//
// 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 <RFM69.h>
#include <SPI.h>
// Addresses for this node. CHANGE THESE FOR EACH NODE!
#define NETWORKID 0 // Must be the same for all nodes
#define MYNODEID 1 // My node ID
#define TONODEID 2 // Destination node ID
// RFM69 frequency, uncomment the frequency of your module:
//#define FREQUENCY RF69_433MHZ
#define FREQUENCY RF69_915MHZ
// AES encryption (or not):
#define ENCRYPT true // Set to "true" to use encryption
#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 9 // LED positive pin
#define GND 8 // LED ground pin
// Create a library object for our RFM69HCW module:
RFM69 radio;
void setup()
{
// Open a serial port so we can send keystrokes to the module:
Serial.begin(9600);
Serial.print("Node ");
Serial.print(MYNODEID,DEC);
Serial.println(" ready");
// Set up the indicator LED (optional):
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
pinMode(GND,OUTPUT);
digitalWrite(GND,LOW);
// Initialize the RFM69HCW:
// radio.setCS(10); //uncomment this if using Pro Micro
radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
radio.setHighPower(); // Always use this for RFM69HCW
// Turn on encryption if desired:
if (ENCRYPT)
radio.encrypt(ENCRYPTKEY);
}
void loop()
{
// Set up a "buffer" for characters that we'll send:
static char sendbuffer[62];
static int sendlength = 0;
// SENDING
// In this section, we'll gather serial characters and
// send them to the other node if we (1) get a carriage return,
// or (2) the buffer is full (61 characters).
// If there is any serial input, add it to the buffer:
if (Serial.available() > 0)
{
char input = Serial.read();
if (input != '\r') // not a carriage return
{
sendbuffer[sendlength] = input;
sendlength++;
}
// If the input is a carriage return, or the buffer is full:
if ((input == '\r') || (sendlength == 61)) // CR or buffer full
{
// Send the packet!
Serial.print("sending to node ");
Serial.print(TONODEID, DEC);
Serial.print(", message [");
for (byte i = 0; i < sendlength; i++)
Serial.print(sendbuffer[i]);
Serial.println("]");
// There are two ways to send packets. If you want
// acknowledgements, use sendWithRetry():
if (USEACK)
{
if (radio.sendWithRetry(TONODEID, sendbuffer, sendlength))
Serial.println("ACK received!");
else
Serial.println("no ACK received");
}
// If you don't need acknowledgements, just use send():
else // don't use ACK
{
radio.send(TONODEID, sendbuffer, sendlength);
}
sendlength = 0; // reset the packet
Blink(LED,10);
}
}
// RECEIVING
// In this section, we'll check with the RFM69HCW to see
// if it has received any packets:
if (radio.receiveDone()) // Got one!
{
// Print out the information:
Serial.print("received from node ");
Serial.print(radio.SENDERID, DEC);
Serial.print(", message [");
// The actual message is contained in the DATA array,
// and is DATALEN bytes in size:
for (byte i = 0; i < radio.DATALEN; i++)
Serial.print((char)radio.DATA[i]);
// RSSI is the "Receive Signal Strength Indicator",
// smaller numbers mean higher power.
Serial.print("], RSSI ");
Serial.println(radio.RSSI);
// Send an ACK if requested.
// (You don't need this code if you're not using ACKs.)
if (radio.ACKRequested())
{
radio.sendACK();
Serial.println("ACK sent");
}
Blink(LED,10);
}
}
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);
}
Code:
//
// FEATHER
//
// rf69 demo tx rx.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem
// configuration
#include <SPI.h>
#include <RH_RF69.h>
/************ Radio Setup ***************/
// Change to 434.0 or other frequency, must match RX's freq!
#define RF69_FREQ 915.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
#define RFM69_CS 8
#define RFM69_INT 7
#define RFM69_RST 4
#define LED 13
#elif defined(ADAFRUIT_FEATHER_M0) // Feather M0 w/Radio
#define RFM69_CS 8
#define RFM69_INT 3
#define RFM69_RST 4
#define LED 13
#elif defined (__AVR_ATmega328P__) // Feather 328P w/wing
#define RFM69_INT 3 //
#define RFM69_CS 4 //
#define RFM69_RST 2 // "A"
#define LED 13
#elif defined(ESP8266) // ESP8266 feather w/wing
#define RFM69_CS 2 // "E"
#define RFM69_IRQ 15 // "B"
#define RFM69_RST 16 // "D"
#define LED 0
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
#define RFM69_INT 9 // "A"
#define RFM69_CS 10 // "B"
#define RFM69_RST 11 // "C"
#define LED 13
#elif defined(ESP32) // ESP32 feather w/wing
#define RFM69_RST 13 // same as LED
#define RFM69_CS 33 // "B"
#define RFM69_INT 27 // "A"
#define LED 13
#endif
/* 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
*/
// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);
int16_t packetnum = 0; // packet counter, we increment per xmission
void setup()
{
Serial.begin(115200);
//while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer
pinMode(LED, OUTPUT);
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, LOW);
Serial.println("Feather RFM69 TX Test!");
Serial.println();
// manual reset
digitalWrite(RFM69_RST, HIGH);
delay(10);
digitalWrite(RFM69_RST, LOW);
delay(10);
if (!rf69.init()) {
Serial.println("RFM69 radio init failed");
while (1);
}
Serial.println("RFM69 radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
// No encryption
if (!rf69.setFrequency(RF69_FREQ)) {
Serial.println("setFrequency failed");
}
// If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
// ishighpowermodule flag set like this:
rf69.setTxPower(20, true); // range from 14-20 for power, 2nd arg must be true for 69HCW
// The encryption key has to be the same as the one in the server
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
pinMode(LED, OUTPUT);
Serial.print("RFM69 radio @"); Serial.print((int)RF69_FREQ); Serial.println(" MHz");
}
void loop() {
delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
char radiopacket[20] = "Hello World #";
itoa(packetnum++, radiopacket+13, 10);
Serial.print("Sending "); Serial.println(radiopacket);
// Send a message!
rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
rf69.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf69.waitAvailableTimeout(500)) {
// Should be a reply message for us now
if (rf69.recv(buf, &len)) {
Serial.print("Got a reply: ");
Serial.println((char*)buf);
Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks
} else {
Serial.println("Receive failed");
}
} else {
Serial.println("No reply, is another RFM69 listening?");
}
}
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);
}
}
Last edited: