Problem with RF12 communication

Hello everybody,

I’m trying to communicate between two Arduino uno boards via RF12. Tried to establish the example on page 486 in Arduino Cookbook from Michael Margolis. Both programs compile and I can upload them but I think the communication doesn’t work. Tried to proof it by the Serial Monitor in the IDE. But no success… Can anybody help me getting it working? How can I test the programm step by step. Any opportunity to see values of variables in the arduino itself? My code is as follows:

transceiver:

/* Simple Send
 * Sends values of analog inputs 0 through 6
 */
#include <Ports.h>
#include <RF12.h> //from jeelabs.org mit Anpassung RF12 -> RFM12B
#include <LiquidCrystal.h>
LiquidCrystal lcd(3,8,7,6,5,4);                     // set of lcd pins (Variable lcd)
 
 // RF12B constants:
 const byte network = 100;                      // network group (can be in the range 1-255)
 const byte myNodeID = 1;                       // unique node ID of receiver (1 through 30)
 const int sensorPin = A0;                           // analog input for TMP36
 
 // Frequency of RF12B can be RF12_433MHz, RF12_868MHz or RF12_915MHz.
 //const byte freq = RF12_868MHZ; // Match freq to module
 const byte freq = RF12_868MHZ; // Match freq to module
 
 const byte RF12_NORMAL_SENDWAIT = 0;
 
 // Grad Celsius byte                                // individual user sign "degree"
byte degree[8] = {
  B01110,
  B01010,
  B01110,
};
 
 void setup()
 {
   Serial.println("setup...");
   rf12_initialize(myNodeID, freq, network);    // initialize RFM12
   
   // LCD setting
  lcd.begin(16,2);                                  // lcd dimensioning
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("akt.-Temperatur:");
// Grad Celsius setting
  lcd.createChar(1, degree);
  lcd.setCursor(6,1);
  lcd.write(byte(1));
  lcd.setCursor(7,1);
  lcd.print("C");
 }
 
 const int payloadCount = 6;                    // the number of integers in the payload message
 int payload[payloadCount];
 
 void loop()
 {
   // temperature measurment
  int sensorVal = analogRead(sensorPin);            // value of sensor
  float sensorVoltage = (sensorVal / 1024.0) * 5.0; // output voltage of sensor
  float sensorTemp_tr = (sensorVoltage - .5) * 100; // tmeperature of sensor

// output of temperature on lcd
  lcd.setCursor(0,1);
  lcd.print(sensorTemp_tr);
  //delay(1000);
   
   
   for( int i = 0; i < payloadCount; i++)
   {
     //payload[i] = analogRead(i);
     payload[i] = sensorTemp_tr;
     Serial.println(i);
     Serial.print(": ");
     Serial.print(sensorTemp_tr);
     //payload[i] = sensorTemp_tr;
   }
   while (!rf12_canSend())                      // is the driver ready to send
   {
   rf12_recvDone();                             // no, so service the driver
   Serial.println("Treiber nicht sendebereit!");
   }
   
   rf12_sendStart(rf12_hdr, payload, payloadCount*sizeof(int));
   rf12_sendWait(RF12_NORMAL_SENDWAIT);         // wait for send completion
   
   delay(1000);                                 // send every second
 }

Receiver:

/* SimpleReceive
 * RFM12B wireless demo - receiver - no ack
 */
#include <Ports.h>
#include <RF12.h> //from jeelabs.org mit Anpassung RF12 -> RFM12B
#include <LiquidCrystal.h>

LiquidCrystal lcd(3,8,7,6,5,4);                     // set of lcd pins (Variable lcd)

// Grad Celsius byte                                // individual user sign "degree"
byte degree[8] = {
  B01110,
  B01010,
  B01110, 
};
 
 // RF12B constants:
 const byte network = 100;                      // network group (can be in the range 1-255)
 const byte myNodeID = 2;                       // unique node ID of receiver (1 through 30)
 
 // Frequency of RF12B can be RF12_433MHz, RF12_868MHz or RF12_915MHz.
 //const byte freq = RF12_868MHZ; // Match freq to module
 const byte freq = RF12_868MHZ; // Match freq to module
 
 void setup()
 {
   
   Serial.println("setup...");
   rf12_initialize(myNodeID, freq, network);    // initialize RFM12
   Serial.begin(9600);
   Serial.println("RFM12B Receiver ready");
   Serial.println(network,DEC);                  // print the network
   Serial.println(myNodeID,DEC);                  // and node ID
   
   // LCD setting
  lcd.begin(16,2);                                  // lcd dimensioning
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Funk-Temperatur:");
// writing Grad Celsius
  lcd.createChar(1, degree);
  lcd.setCursor(6,1);
  lcd.write(byte(1));
  lcd.setCursor(7,1);
  lcd.print("C");
 }
 
 const int payloadCount = 6;                    // the number of integers in the payload message
 
 void loop()
 {
   if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0)
  {
    int *payload = (int*)rf12_data;            // access rf12 data buffer as an array of ints
    Serial.println("if(rf12...)");
    for( int i = 0; i < payloadCount; i++)
    {
      Serial.print(payload[i]);
      Serial.print(" ");
        // LCD ansteuern - Temperaturausgabe
  lcd.setCursor(0,1);
  lcd.print(payload[i]);
    }
    Serial.println();
  }
 }

Thank you for your help,
David

  1. how are you connecting the RFM12s to the Arduinos? You need 5V-to-3.3V level-shifters between the UNO board and RFM12 modules, and also Vcc=3.3V on the modules.

  2. if connected properly, then the Cookbook examples should work straightaway.

  3. OTOH, I've had loads of trouble trying to use the examples that come with jeelib itself, and use the low power labs library instead. Most people have found that the Send+Receive examples ther ework immediately. https://github.com/LowPowerLab/RFM12B

  4. remove the LCD code until you get the RFM12s working properly. It's much easier to do one thing at a time.