Why is my RFM69 Radio not working?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Why is my RFM69 Radio not working?

Post by animefruit »

Hello.

This is Neal Cole.

I do Arduino Projects and have used Adafruit support for a while to ask questions about my projects.

I am trying to connect my Arduino Nano to a Adafruit RFM69 Radio.

I connected my Arduino Nano just like the image of the connections attached to the post from this website:

https://learn.adafruit.com/adafruit- ... wiring


Although, now it seems like it is not working.

I am following the guide from the “Using the RFM69 Radio” section on the same website here:

https://learn.adafruit.com/adafruit- ... radio

I uploaded the code "RadioHead69_RawDemo_TX" after adding the "RadioHead file to my library.

Here is the code from the website:

Code: Select all

     // 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
#define RF69_FREQ 433.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) || defined(ADAFRUIT_FEATHER_M0_EXPRESS) || defined(ARDUINO_SAMD_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) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #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

#elif defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17

#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);
  }
}     
      

The problem is that when I uploaded this code it does not show what it is supposed to be shown on the serial monitor from the website.

What is supposed to be shown in the serial monitor from the website is shown in the file attached to this post.

The photo of the serial monitor that is attached to this post with random question marks and letters is my serial monitor.

Can you tell me what to make the code work so that my serial monitor looks like the serial monitor from the website?


Also, is it ok to use the same pin on my Arduino Nano for 2 different things?
Right now I have D13 being used from my Arduino Nano on the RFM69 Radio and some LEDs.
Is that ok?
Is that the problem?

Another problem could be that I have to change the code for my Arduino Nano because this code from the website is meant for the Arduino Feather?
Is this the problem, and if so ,how could I change this code to work on my Arduino Nano?
Attachments
2EFE9D40-6EC1-4AAD-B23C-16DB706CD414.jpeg
2EFE9D40-6EC1-4AAD-B23C-16DB706CD414.jpeg (139.37 KiB) Viewed 481 times
1D2679AB-4678-45F1-923F-2BF58EFC0FF0.jpeg
1D2679AB-4678-45F1-923F-2BF58EFC0FF0.jpeg (252.63 KiB) Viewed 481 times
7EE608C5-69E3-4B4A-9C01-BBF196F55FF8.jpeg
7EE608C5-69E3-4B4A-9C01-BBF196F55FF8.jpeg (68.21 KiB) Viewed 481 times

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Why is my RFM69 Radio not working?

Post by adafruit_support_carter »

Set your Serial Monitor baud rate to 115200 to match the sketch code.

You're currently set to 9600:
baud.jpg
baud.jpg (32.9 KiB) Viewed 475 times

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Why is my RFM69 Radio not working?

Post by animefruit »

Thank you!

That worked changing it to 115200!

Now I want to do the RadioHead69_RawDemoTXRX_OLED sketch from this article:

https://learn.adafruit.com/adafruit-r ... -radio

This sketch detects button presses that are connected to each radio.

But I don’t know how I will connect the buttons because the Adafruit article only talks about how to connect them to an Arduino Feather.

My attached picture shows what the article says to connect it to an Arduino Feather.

The other attached picture shows how my Arduino Nanos are being connected to the RFM69 Radios.

How would I do the button connections for my Arduino Nanos being connected to RFM69 Radios?
Attachments
2E7B417F-B4CB-4A5E-91F0-B0EBC6C5A207.png
2E7B417F-B4CB-4A5E-91F0-B0EBC6C5A207.png (812.98 KiB) Viewed 460 times
AF24368B-517B-4256-B591-637F3535BFC2.jpeg
AF24368B-517B-4256-B591-637F3535BFC2.jpeg (126.68 KiB) Viewed 460 times

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Why is my RFM69 Radio not working?

Post by adafruit_support_carter »

See here for basic info on button usage:
https://learn.adafruit.com/adafruit-ard ... tal-inputs

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Why is my RFM69 Radio not working?

Post by animefruit »

Ok.
I set up my button connections and now I am trying to upload the code, RadioHead69_RawDemoTXRX_OLED.ino
But it is not working because it says "Adafruit_GFX.h: No such file or directory"
I don't know why it is having problems when this is a simple examle code from this website:
https://learn.adafruit.com/adafruit- ... 69-radio

How do I fix this?

Here is the code from RadioHead69_RawDemoTXRX_OLED.ino :

Code: Select all

 // rf69 demo tx rx oled.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>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ 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
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #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"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // 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(14, true);

  // 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");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()
{  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }
}

    

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Why is my RFM69 Radio not working?

Post by adafruit_support_carter »

The OLED example requires a couple more libraries:

Code: Select all

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
You can just install the SSD1306 library. It has the GFX library as a dependency, so the GFX library will also get installed at the same time as the SSD1306 library.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Why is my RFM69 Radio not working?

Post by animefruit »

Ok I did that.

Now the RadioHead69_RawDemoTXRX_OLED.ino sketch works perfectly fine.

But now I want to replace it with a servo rather than a button.

And I would like to implement my code from earlier.

My code from earlier makes it to where when piezo sensors gets pressed to much, the servo sweeps

Both of my boards have piezo sensors and a servo connected.

Here is that code:

Code: Select all

  #include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"


#define LED 13// FOR LED



Adafruit_LiquidCrystal lcd(0);

Servo myservo1;
Servo myservo2;

//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;


const int threshold = 0;
int health = 500;

// 6 total sensor readings (from 0 to 5)

int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;


int pos =0;



int deaths=1;// gonna be number of deaths



void setup()

{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED

  Serial.begin(9600);
  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

// sg90

  lcd.begin (20 , 4);
  lcd.clear();


  Serial.begin(9600);
  myservo1.attach(9);
  myservo1.write(0);//was 0

  myservo2.attach(10);
  myservo2.write(45);//was 179




}

void loop()
{
  do
  {


    myservo1.detach();
    myservo2.detach();

    sensorReading = analogRead(knockSensor);
    

    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);

    if (sensorReading > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading;

      
      
      Serial.print(sensorReading);
      lcd.print(sensorReading);


      int sensorValue = analogRead(A0);

      Serial.println(sensorValue);


      
      


      
      delay(1);

    }

//duplicate 

sensorReading1= analogRead(knockSensor1);

 if (sensorReading1 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading1;

      
      
      Serial.print(sensorReading1);
      lcd.print(sensorReading1);


      int sensorValue = analogRead(A1);

      Serial.println(sensorValue);


      delay(1);

    }

  

//duplicate

sensorReading2= analogRead(knockSensor2);

 if (sensorReading2 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading2;

      
      
      Serial.print(sensorReading2);
      lcd.print(sensorReading2);


      int sensorValue = analogRead(A2);

      Serial.println(sensorValue);


      delay(1);

    }


 

//duplicate 

sensorReading3= analogRead(knockSensor3);

 if (sensorReading3 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading3;

      
      
      Serial.print(sensorReading3);
      lcd.print(sensorReading3);


      int sensorValue = analogRead(A3);

      Serial.println(sensorValue);


      delay(1);

    }

 

//duplicate 



sensorReading4= analogRead(knockSensor4);

 if (sensorReading4 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading4;

      
      
      Serial.print(sensorReading4);
      lcd.print(sensorReading4);


      int sensorValue = analogRead(A6);

      Serial.println(sensorValue);


      delay(1);

    }

 

//duplicate 

sensorReading5= analogRead(knockSensor5);

 if (sensorReading5 > threshold) {

      Serial.println("Knock!");
      health = health - sensorReading5;

      
      
      Serial.print(sensorReading5);
      lcd.print(sensorReading5);


      int sensorValue = analogRead(A7);

      Serial.println(sensorValue);


      delay(1);

    }







  } while (health > 1);

  
  
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);

  delay(15);

 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
  
  
  }

 delay(1000);


 lcd.setCursor(0, 2);
      Serial.println(deaths); //showind number of deaths on the lcd
      lcd.println(deaths);


deaths= deaths + 1;// adding deaths






  
  health = 500;
}

    

I would like to make it to where both boards have the same code but print in the serial monitor when one of the boards have the servo move, just like with what the RadioHead69_RawDemoTXRX_OLED.ino does with the buttons.

Can you tell me how to do so?

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Why is my RFM69 Radio not working?

Post by adafruit_support_carter »

Sorry, no. We don't provide engineering support for writing code for custom applications. We can help if specific items are not working as advertised - like if the servo won't work with the basic servo example as shown in Learn guide. But putting all the pieces together is up to you.

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Why is my RFM69 Radio not working?

Post by animefruit »

Ok.

I tried to combine both of the code together, my code from earlier and the RadioHead69_RawDemoTXRX_OLED.ino code.

I tried combining them twice and got 2 different errors.

The images of the errors are attached below.

I also replaced "BUTTON" as "SERVO" so it would print something when one of the servos move instead.

My first code was this:

Code: Select all

   // rf69 demo tx rx oled.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 <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"  //from other


#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define LED 13 //from other

Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2; //from other

const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;//from other
 
 
const int threshold = 0;
int health = 500; //from other


int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;//from other
 

int pos =0;// from other

int deaths=1;

/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define SERVO_A 0
  #define SERVO_B 16
  #define SERVO_C 2
  #define LED      0
#elif defined(ESP32)
  #define SERVO_A 15
  #define SERVO_B 32
  #define SERVO_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define SERVO_A PA15
  #define SERO_B PC7
  #define SERVO_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define SERVO_A 4
  #define SERVO_B 3
  #define SERVO_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define SERVO_A 31
  #define SERVO_B 30
  #define SERVO_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define SERVO_A 9
  #define SERVO_B 6
  #define SERVO_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #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"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);


   pinMode(LED, OUTPUT);//from other
  Serial.begin(115200);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");//from other

  lcd.begin (20 , 4);
  lcd.clear(); //from other

  
  lcd.begin (20 , 4);
  lcd.clear(); //from other

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(SERVO_A, INPUT_PULLUP);
  pinMode(SERVO_B, INPUT_PULLUP);
  pinMode(SERVO_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // 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(14, true);

  // 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");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()
{
  do
  {
 
 
    myservo1.detach();
    myservo2.detach();
 
    sensorReading = analogRead(knockSensor);
   
 
    lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);
 
    if (sensorReading > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading;
 
     
     
      Serial.print(sensorReading);
      lcd.print(sensorReading);
 
 
      int sensorValue = analogRead(A0);
 
      Serial.println(sensorValue);
 
 
     
     
 
 
     
      delay(1);
 
    }
 
//duplicate
 
sensorReading1= analogRead(knockSensor1);
 
 if (sensorReading1 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading1;
 
     
     
      Serial.print(sensorReading1);
      lcd.print(sensorReading1);
 
 
      int sensorValue = analogRead(A1);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading2= analogRead(knockSensor2);
 
 if (sensorReading2 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading2;
 
     
     
      Serial.print(sensorReading2);
      lcd.print(sensorReading2);
 
 
      int sensorValue = analogRead(A2);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
//duplicate
 
sensorReading3= analogRead(knockSensor3);
 
 if (sensorReading3 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading3;
 
     
     
      Serial.print(sensorReading3);
      lcd.print(sensorReading3);
 
 
      int sensorValue = analogRead(A3);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
 
 
sensorReading4= analogRead(knockSensor4);
 
 if (sensorReading4 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading4;
 
     
     
      Serial.print(sensorReading4);
      lcd.print(sensorReading4);
 
 
      int sensorValue = analogRead(A6);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading5= analogRead(knockSensor5);
 
 if (sensorReading5 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading5;
 
     
     
      Serial.print(sensorReading5);
      lcd.print(sensorReading5);
 
 
      int sensorValue = analogRead(A7);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
 
 
 
  } while (health > 1);
 
 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 
  }
 
 delay(1000);
 
 
 lcd.setCursor(0, 2);
      Serial.println(deaths); //showind number of deaths on the lcd
      lcd.println(deaths);
 
 
deaths= deaths + 1;// adding deaths
 
 
 
 
 
 
 
  health = 500;

 {  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(SERVO_A) || !digitalRead(SERVO_B) || !digitalRead(SERVO_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(SERVO_A)) radiopacket[8] = 'A';
    if (!digitalRead(SERVO_B)) radiopacket[8] = 'B';
    if (!digitalRead(SERVO_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }

}

}

    



The error was "Error compiling for Arduino Nano"

My second code was this:

Code: Select all

   // rf69 demo tx rx oled.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 <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"

Adafruit_LiquidCrystal lcd(0);
 
Servo myservo1;
Servo myservo2;

const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;

const int threshold = 0;
int health = 500;

int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
 
 
int pos =0;
 
 
 
int deaths=1;// gonna be number of deaths

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#define LED 13// FOR LED
 

#if defined(ESP8266)
  #define SERVO_A 0
  #define SERVO_B 16
  #define SERVO_C 2
  #define LED      0
#elif defined(ESP32)
  #define SERVO_A 15
  #define SERVO_B 32
  #define SERVO_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define SERVO_A PA15
  #define SERVO_B PC7
  #define SERVO_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define SERVO_A 4
  #define SERVO_B 3
  #define SERVO_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define SERVO_A 31
  #define SERVO_B 30
  #define SERVO_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define SERVO_A 9
  #define SERVO_B 6
  #define SERVO_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #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"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);

 pinMode(LED, OUTPUT);//FOR LED
  
  Serial.begin(115200);

  lcd.begin (20 , 4);
  lcd.clear();

   myservo1.attach(9);
  myservo1.write(0);//was 0
 
  myservo2.attach(10);
  myservo2.write(45);//was 179

 
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  // Initialize OLED display
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();
  delay(500);
  oled.clearDisplay();
  oled.display();

  pinMode(SERVO_A, INPUT_PULLUP);
  pinMode(SERVO_B, INPUT_PULLUP);
  pinMode(SERVO_C, INPUT_PULLUP);

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  Serial.println("Feather RFM69 RX/TX Test!");

  // 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(14, true);

  // 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");

  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();

  delay(500);
}


void loop()

{
  do
  {

myservo1.detach();
    myservo2.detach();

lcd.setCursor(0, 1);
    Serial.println(health);
    lcd.println(health);
 
    if (sensorReading > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading;
 
     
     
      Serial.print(sensorReading);
      lcd.print(sensorReading);
 
 
      int sensorValue = analogRead(A0);
 
      Serial.println(sensorValue);
 
 
     
     
 
 
     
      delay(1);
 
    }
 
//duplicate
 
sensorReading1= analogRead(knockSensor1);
 
 if (sensorReading1 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading1;
 
     
     
      Serial.print(sensorReading1);
      lcd.print(sensorReading1);
 
 
      int sensorValue = analogRead(A1);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading2= analogRead(knockSensor2);
 
 if (sensorReading2 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading2;
 
     
     
      Serial.print(sensorReading2);
      lcd.print(sensorReading2);
 
 
      int sensorValue = analogRead(A2);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
 
//duplicate
 
sensorReading3= analogRead(knockSensor3);
 
 if (sensorReading3 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading3;
 
     
     
      Serial.print(sensorReading3);
      lcd.print(sensorReading3);
 
 
      int sensorValue = analogRead(A3);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
 
 
sensorReading4= analogRead(knockSensor4);
 
 if (sensorReading4 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading4;
 
     
     
      Serial.print(sensorReading4);
      lcd.print(sensorReading4);
 
 
      int sensorValue = analogRead(A6);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
 
//duplicate
 
sensorReading5= analogRead(knockSensor5);
 
 if (sensorReading5 > threshold) {
 
      Serial.println("Knock!");
      health = health - sensorReading5;
 
     
     
      Serial.print(sensorReading5);
      lcd.print(sensorReading5);
 
 
      int sensorValue = analogRead(A7);
 
      Serial.println(sensorValue);
 
 
      delay(1);
 
    }
 
 
   } while (health > 1);
 
 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
  myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 
  }
 
 delay(1000);
 
 
 lcd.setCursor(0, 2);
      Serial.println(deaths); //showind number of deaths on the lcd
      lcd.println(deaths);
 
 
deaths= deaths + 1;// adding deaths
 
 
 
 
 
 
 
  health = 500;
}
 
 {  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
    if (! rf69.recv(buf, &len)) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*)buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);
  }

  if (!digitalRead(SERVO_A) || !digitalRead(SERVO_B) || !digitalRead(SERVO_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(SERVO_A)) radiopacket[8] = 'A';
    if (!digitalRead(SERVO_B)) radiopacket[8] = 'B';
    if (!digitalRead(SERVO_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }
}

  
The error was "expected unqualified-id before '{' token"


Can you help me combine both of this code without errors?
Attachments
Adafruit Buttun with Servo 2 pics.PNG
Adafruit Buttun with Servo 2 pics.PNG (77.81 KiB) Viewed 443 times

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Why is my RFM69 Radio not working?

Post by animefruit »

Can you help me combine both of this code without errors from the above post?

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: Why is my RFM69 Radio not working?

Post by animefruit »

I guess it is too much to ask for you to tell me how to combine those 2 codes together.

But can you simply tell me the code I need to use for servos to be registered rather than button presses?

Do I use the same servo code as usual from the Sweep example sketch or to I have to use something else because it is code for the RFM69 Radio?

I also Simplified the RadioHead69_RawDemoTXRX_OLED

I commented any piece of code that wasn't needed for the code to work.

Here is my Simplified code:

Code: Select all

  #include <RH_RF69.h>



// 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
//#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup() 
{
  delay(500);
  Serial.begin(115200);
  


  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

  
  // manual reset
 

  
  if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }    // 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(14, true);


  delay(500);
}


void loop()
{  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now   
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    
   if (! rf69.recv(buf , & len )) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
    
    Serial.print("Got: "); Serial.println((char*) buf);
   
  }

  if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();
  }
}
   

User avatar
adafruit_support_carter
 
Posts: 29457
Joined: Tue Nov 29, 2016 2:45 pm

Re: Why is my RFM69 Radio not working?

Post by adafruit_support_carter »

Try writing in the new code in the smallest chunks possible (a few lines at a time) instead of copying and pasting large chunks of codes from separate examples, which very commonly leads to copy paste errors like this:
code.png
code.png (59.47 KiB) Viewed 422 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”