How to send/receive sensor data with Adafruit Feather M0 RFM69HCW - 868 -915Hz

Hello,
I need some help explaining how to send and receive MPU6050 accelerometer data with Adafruit Feather M0 RFM69HCW Using the RFM69 Radio | Adafruit Feather M0 Radio with RFM69 Packet Radio | Adafruit Learning System

For now its Part I, how to send values.
Below is a demo sketch that is on Adafruit's learning page. I used it as a starting point. Sending HELLO WORLD works fine, the boards are talking.

#include <SPI.h>[color=#2e8b57][/color]
#include <RH_RF69.h>[color=#2e8b57][/color]
[color=#2e8b57][/color]
// Change to 434.0 or other frequency, must match RX's frequensy![color=#2e8b57][/color]
#define RF69_FREQ 915.0[color=#2e8b57][/color]
[color=#2e8b57][/color]
#define RFM69_CS      8[color=#2e8b57][/color]
#define RFM69_INT     3[color=#2e8b57][/color]
#define RFM69_RST     4[color=#2e8b57][/color]
#define LED           13[color=#2e8b57][/color]
[color=#2e8b57][/color]
// Singleton instance of the radio driver[color=#2e8b57][/color]
RH_RF69 rf69(RFM69_CS, RFM69_INT);[color=#2e8b57][/color]
[color=#2e8b57][/color]
int16_t packetnum = 0;  // packet counter, we increment per xmission[color=#2e8b57][/color]
[color=#2e8b57][/color]
void setup()[color=#2e8b57][/color]
{[color=#2e8b57][/color]
  Serial.begin(115200);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer[color=#2e8b57][/color]
[color=#2e8b57][/color]
  pinMode(LED, OUTPUT);[color=#2e8b57][/color]
  pinMode(RFM69_RST, OUTPUT);[color=#2e8b57][/color]
  digitalWrite(RFM69_RST, LOW);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  Serial.println("Feather RFM69 TX Test!");[color=#2e8b57][/color]
  Serial.println();[color=#2e8b57][/color]
[color=#2e8b57][/color]
  // manual reset[color=#2e8b57][/color]
  digitalWrite(RFM69_RST, HIGH);[color=#2e8b57][/color]
  delay(10);[color=#2e8b57][/color]
  digitalWrite(RFM69_RST, LOW);[color=#2e8b57][/color]
  delay(10);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  if (!rf69.init()) {[color=#2e8b57][/color]
    Serial.println("RFM69 radio init failed");[color=#2e8b57][/color]
    while (1);[color=#2e8b57][/color]
  }[color=#2e8b57][/color]
  Serial.println("RFM69 radio init OK!");[color=#2e8b57][/color]
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)[color=#2e8b57][/color]
  // No encryption[color=#2e8b57][/color]
  if (!rf69.setFrequency(RF69_FREQ)) {[color=#2e8b57][/color]
    Serial.println("setFrequency failed");[color=#2e8b57][/color]
  }[color=#2e8b57][/color]
[color=#2e8b57][/color]
  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the[color=#2e8b57][/color]
  // ishighpowermodule flag set like this:[color=#2e8b57][/color]
  rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW[color=#2e8b57][/color]
[color=#2e8b57][/color]
  // The encryption key has to be the same as the one in the server[color=#2e8b57][/color]
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,[color=#2e8b57][/color]
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08[color=#2e8b57][/color]
                  };[color=#2e8b57][/color]
  rf69.setEncryptionKey(key);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  pinMode(LED, OUTPUT);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");[color=#2e8b57][/color]
 [color=#2e8b57][/color]
}[color=#2e8b57][/color]
[color=#2e8b57][/color]
void loop() {[color=#2e8b57][/color]
  delay(1000);  // Wait 1 second between transmits, could also 'sleep' here![color=#2e8b57][/color]
 [color=#2e8b57][/color]
  char radiopacket[20] = "HELLO WORLD #";[color=#2e8b57][/color]
  itoa(packetnum++, radiopacket + 13, 10);[color=#2e8b57][/color]
  Serial.print("Sending "); Serial.println(radiopacket);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  // Send a message![color=#2e8b57][/color]
  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));[color=#2e8b57][/color]
  rf69.waitPacketSent();[color=#2e8b57][/color]
[color=#2e8b57][/color]
  // Now wait for a reply[color=#2e8b57][/color]
  uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];[color=#2e8b57][/color]
  uint8_t len = sizeof(buf);[color=#2e8b57][/color]
[color=#2e8b57][/color]
  if (rf69.waitAvailableTimeout(500))  {[color=#2e8b57][/color]
    // Should be a reply message for us now[color=#2e8b57][/color]
    if (rf69.recv(buf, &len)) {[color=#2e8b57][/color]
      Serial.print("Got a reply: ");[color=#2e8b57][/color]
      Serial.println((char*)buf);[color=#2e8b57][/color]
      Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks[color=#2e8b57][/color]
    } else {[color=#2e8b57][/color]
      Serial.println("Receive failed");[color=#2e8b57][/color]
    }[color=#2e8b57][/color]
  } else {[color=#2e8b57][/color]
    Serial.println("No reply, is another RFM69 listening?");[color=#2e8b57][/color]
  }[color=#2e8b57][/color]
}[color=#2e8b57][/color]
[color=#2e8b57][/color]
void Blink(byte PIN, byte DELAY_MS, byte loops) {[color=#2e8b57][/color]
  for (byte i = 0; i < loops; i++)  {[color=#2e8b57][/color]
    digitalWrite(PIN, HIGH);[color=#2e8b57][/color]
    delay(DELAY_MS);[color=#2e8b57][/color]
    digitalWrite(PIN, LOW);[color=#2e8b57][/color]
    delay(DELAY_MS);[color=#2e8b57][/color]
  }[color=#2e8b57][/color]
}

I understand that I would have to modify the lines in the loop and to change Hello World to call for accelerometer's values mpu6050.getAccX(); (as an example, from one of the libraries). I tried to change Hello World to accelerometer's code but no data is showing.

void loop() {[color=#2e8b57][/color]
  delay(1000);  // Wait 1 second between transmits, could also 'sleep' here![color=#2e8b57][/color]
 [color=#2e8b57][/color]
  mpu6050.update();[color=#2e8b57][/color]
 [color=#2e8b57][/color]
  float acc = mpu6050.getAccX();[color=#2e8b57][/color]
  char radiopacket[20] = {acc};[color=#2e8b57][/color]
  itoa(packetnum++, radiopacket + 13, 10);[color=#2e8b57][/color]
  Serial.print("Sending "); 
  Serial.println(radiopacket);

  // Send a message![color=#2e8b57][/color]
  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));[color=#2e8b57][/color]
  rf69.waitPacketSent();

Also, what does 20 in the square brackets mean? same for the line below, numbers 13 and 10?

  char radiopacket[20] = "Hello World #";[color=#2e8b57][/color]
  itoa(packetnum++, radiopacket + 13, 10);

Thanks

When I started out with RFM69 I found the LowPowerLab forum and their github repository a great starting point. I used their library for RFM69 to get me going. They have a lot of examples in github. Once I got their examples going, the auto tx power control option works well with battery powered nodes.

Thank you for pointing to a great source, I'll definitely look through their examples.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.