Adafruit Feather M0 Radio with RFM69 Packet Radio problems

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chrisplusian
 
Posts: 28
Joined: Fri Jun 10, 2016 8:34 am

Adafruit Feather M0 Radio with RFM69 Packet Radio problems

Post by chrisplusian »

Hello, I am working with the feather and another piece of equipment which uses Uart (9600 Baud 8 bit no parity with one stop bit). I am using the suggested radiohead library, and I am trying to do two things: 1) Collect the data from the outside device. 2) Send the data collected to another feather and save it on a computer. I am using Tera-Term to save a .CSV on the computer side. I am able to successfully use the outside device when it is set in a different mode. There are three modes, two of which send the same amount of information at the same rate, while the third mode sends different data at a different rate. One mode sends 8 bits of data one time per second, while the other sends a packet of 25 frames three times in a second (25 frames is 125 bytes of data). Each frame, or 5 bytes of data, has significance and must be parsed, but I intend to deal with that on the computer side. The problem has to do with the checksum. The literature included with the device says this about the checksum: CHK = (Byte1) + (Byte2) + (Byte3) + (Byte4) modulo 256. I am certain I have the two feathers communicating I wrote test codes to make sure they were sending and receiving information. I read and did all the tutorials on your website and they work just fine. When on the receiving side it seemed the checksum was correct for a period of time, but then it went haywire. The data I was receiving seemed wrong too. So I stopped using the receiver and just went to the transmitter. I wrote a code that would allow me to see a few things including the computed checksum, and the checksum byte. The checksum byte is always the fifth byte in the frame. I wrote the code to only send five bytes of data at a time because I was reading somewhere that the controller only has a 64 byte buffer. I don't know if my approach is wrong. My original thought was to read all 125 bytes in, and then send them, but it didn't work, so I went to the 5 byte method. The funny part is I have run the code several times, and the calculated checksum is correct for the first 165 bytes, 33 frames, but then it fails. It consistently fails it reaches 165 bytes of data stored. I started thinking this may have something to do with the buffer length and I tried to see what was in the buffer, or how fast it was filling up, but I have not been successful at this yet. I am at a sticking point and you guys always help me when I get to this point. I would appreciate any help.

Code: Select all

// rf69 demo tx rx.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple addressed, reliable messaging 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 <RHReliableDatagram.h>


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

// Radio Frequency
#define RF69_FREQ 433.0

// Where to send packets
#define DEST_ADDRESS   10
// change addresses for each client board, any number 
#define MY_ADDRESS     15


#define RFM69_CS      8
#define RFM69_INT     3
#define RFM69_RST     4
#define LED           13


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

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram rf69_manager(rf69, MY_ADDRESS);

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
  Serial1.begin(9600);
  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);
  //Serial.println("Feather Addressed RFM69 TX Test!");
  //Serial.println();

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69_manager.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

  // Set encryption key[] has to be same as server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  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);  // range from 14-20 for power, 2nd arg must be true for 69HCW


  

  //Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");
}


// Dont put this on the stack:
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
uint8_t data[] = "  OK";

void loop() {
  
  static uint8_t  inByte1 = B00000000;
  static uint8_t  inByte2 = B00000000;
  static uint8_t  inByte3 = B00000000;
  static uint8_t  inByte4 = B00000000;
  static uint8_t  chkSum = B00000000;
  static uint8_t  valueCheck = B00000000;
  static int loopIteration = 0;
  static int multiplier = 5;
  static int bytesStored = 0;
  Serial.print("inByte1 = ");
  Serial.println(inByte1);
  Serial.print("inByte2 = ");
  Serial.println(inByte2);
  Serial.print("inByte3 = ");
  Serial.println(inByte3);
  Serial.print("inByte4 = ");
  Serial.println(inByte4);
  Serial.print("chkSum = ");
  Serial.println(chkSum);
  Serial.print("loop iteration = ");
  Serial.println(loopIteration);
  Serial.print("multiplier = ");
  Serial.println(multiplier);
  Serial.print("The number of bytes stored = ");
  Serial.println(bytesStored);
  uint8_t len = sizeof(buf); 
  buf[len] = 0;
  for (int i=0; i < len; i++){
    Serial.print("Buffer"); Serial.print(i); Serial.print(" = "); Serial.println(buf[i]);
  }

  
  while(1){
   if(Serial1.available()>4){
        inByte1 = Serial1.read();
        inByte2 = Serial1.read();
        inByte3 = Serial1.read();
        inByte4 = Serial1.read();
        chkSum = Serial1.read();
        loopIteration++;
        bytesStored = loopIteration * multiplier;
        Serial.print("The number of bytes Stored is: ");
        Serial.println(bytesStored);
        if (bytesStored == 125){
          Serial.flush();
        }
        for (int i=0; i < 60; i++){
          Serial.print("Buffer"); Serial.print(i); Serial.print(" = "); Serial.println(buf[i]);
        }
              }
        uint8_t radiopacket[5] = {inByte1, inByte2, inByte3, inByte4, chkSum};

       valueCheck = (inByte1) + (inByte2) + (inByte3) + (inByte4) % 256;
       Serial.print("chkSum = ");
       Serial.println(chkSum);
       Serial.print("valueCheck = ");
       Serial.println(valueCheck);
       
       if(valueCheck == chkSum){
         Serial.println("Hallelujah!");
       }

        radiopacket[0] = inByte1;
        radiopacket[1] = inByte2;
        radiopacket[2] = inByte3;
        radiopacket[3] = inByte4;
        radiopacket[4] = chkSum;

        //Blink(LED, 40, 3); //blink LED 3 times, 40ms between blinks
          // Send a message to the DESTINATION!
      if (rf69_manager.sendtoWait(radiopacket, 5, DEST_ADDRESS)) {  
        // Now wait for a reply from the server
        uint8_t len = sizeof(buf);
        uint8_t from;   
        if (rf69_manager.recvfromAckTimeout(buf, &len, 2000, &from)) {
          buf[len] = 0; // zero out remaining string
          Serial.println("Problem Here");
          }
      }
          
      
//          Serial.print("Got reply from #"); Serial.print(from);
//          Serial.print(" [RSSI :");
//          Serial.print(rf69.lastRssi());
//          Serial.print("] : ");
//          Serial.println((char*)buf);     
//        } 
//        else {
//          Serial.println("No reply, is anyone listening?");
//        }
//      } 
//      else {
//        Serial.println("Sending failed (no ack)");
//      }
      
  }// end while loop
}

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



User avatar
chrisplusian
 
Posts: 28
Joined: Fri Jun 10, 2016 8:34 am

Re: Adafruit Feather M0 Radio with RFM69 Packet Radio proble

Post by chrisplusian »

Just curious.... does adafruit still reply to these posts? I am not complaining, I just ask because all the other times I asked questions on here there response time absolutely amazed me (less than 24 hours). Again Not complaining just asking. Thanks in advance.

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

Return to “Feather - Adafruit's lightweight platform”