Author Topic: Getting/Setting radio Frequency [solved]  (Read 436 times)

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Getting/Setting radio Frequency [solved]
« on: September 25, 2018, 09:58:13 AM »
I have a Motion with the RFMHCW69 915mhz transceiver.  When I do a call to

radio.getFreqency()  the number 1023999936 is returned.  Is that correct?


 
« Last Edit: September 26, 2018, 06:59:56 PM by Felix »

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #1 on: September 25, 2018, 10:04:44 AM »
Forgot to mention this happens even after a radio.setFrequency(n) call, no matter what n is

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Radio Frequency
« Reply #2 on: September 25, 2018, 10:59:07 AM »
The arguments are in Hz.
How do you make those calls?
Can you add the code you're using including variables?

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #3 on: September 25, 2018, 02:16:59 PM »
Using a very slightly modified version of the example file Struct_send.

My mods are marked with //KDW

Code: [Select]
#include <RFM69.h>
#include <SPI.h>
#include <SPIFlash.h>

#define NODEID      99
#define NETWORKID   100
#define GATEWAYID   1
#define FREQUENCY   RF69_915MHZ // KDW
#define KEY         "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
#define LED         9
#define SERIAL_BAUD 115200
#define ACK_TIME    30  // # of ms to wait for an ack
#define IS_RFM69HW_HCW  //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!

int TRANSMITPERIOD = 300; //transmit a packet to gateway so often (in ms)
byte sendSize=0;
boolean requestACK = false;
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
RFM69 radio;

typedef struct {
  int           nodeId; //store this nodeId
  unsigned long uptime; //uptime in ms
  float         temp;   //temperature maybe?
} Payload;
Payload theData;

void setup() {
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
 
#ifdef IS_RFM69HW_HCW
  radio.setHighPower(); //must include this only for RFM69HW/HCW!
#endif
  radio.encrypt(KEY);
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
 
  if (flash.initialize())
    Serial.println("SPI Flash Init OK!");
  else
    Serial.println("SPI Flash Init FAIL! (is chip present?)");
 
  radio.setFrequency(FREQUENCY); //KDW
}

long lastPeriod = -1;
void loop() {
 
  Serial.println(radio.getFrequency()); //KDW
  //process any serial input
  if (Serial.available() > 0)
  {
    char input = Serial.read();
    if (input >= 48 && input <= 57) //[0,9]
    {
      TRANSMITPERIOD = 100 * (input-48);
      if (TRANSMITPERIOD == 0) TRANSMITPERIOD = 1000;
      Serial.print("\nChanging delay to ");
      Serial.print(TRANSMITPERIOD);
      Serial.println("ms\n");
    }
   
    if (input == 'r') //d=dump register values
      radio.readAllRegs();
    //if (input == 'E') //E=enable encryption
    //  radio.encrypt(KEY);
    //if (input == 'e') //e=disable encryption
    //  radio.encrypt(null);
   
    if (input == 'd') //d=dump flash area
    {
      Serial.println("Flash content:");
      int counter = 0;

      while(counter<=256){
        Serial.print(flash.readByte(counter++), HEX);
        Serial.print('.');
      }
      while(flash.busy());
      Serial.println();
    }
    if (input == 'e')
    {
      Serial.print("Erasing Flash chip ... ");
      flash.chipErase();
      while(flash.busy());
      Serial.println("DONE");
    }
    if (input == 'i')
    {
      Serial.print("DeviceID: ");
      word jedecid = flash.readDeviceId();
      Serial.println(jedecid, HEX);
    }
  }

  //check for any received packets
  if (radio.receiveDone())
  {
    Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
    for (byte i = 0; i < radio.DATALEN; i++)
      Serial.print((char)radio.DATA[i]);
    Serial.print("   [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]");

    if (radio.ACKRequested())
    {
      radio.sendACK();
      Serial.print(" - ACK sent");
      delay(10);
    }
    Blink(LED,5);
    Serial.println();
  }
 
  int currPeriod = millis()/TRANSMITPERIOD;
  if (currPeriod != lastPeriod)
  {
    //fill in the struct with new values
    theData.nodeId = NODEID;
    theData.uptime = millis();
    theData.temp = 91.23; //it's hot!
   
    Serial.print("Sending struct (");
    Serial.print(sizeof(theData));
    Serial.print(" bytes) ... ");
    if (radio.sendWithRetry(GATEWAYID, (const void*)(&theData), sizeof(theData)))
      Serial.print(" ok!");
    else Serial.print(" nothing...");
    Serial.println();
    Blink(LED,3);
    lastPeriod=currPeriod;
  }
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Radio Frequency
« Reply #4 on: September 25, 2018, 03:04:19 PM »
Try 915000000 instead of RF69_915MHZ which is a library directive (value==91 which is an invalid Hz argument).
915mhz = 915 million hertz.

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #5 on: September 25, 2018, 03:10:40 PM »
Same result

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Radio Frequency
« Reply #6 on: September 25, 2018, 03:30:53 PM »
Ensure you write the sketch with new 915000000 value, then recycle power to clear any invalid saved value.
Here's a working example that conditionally sets frequency to 916mhz:
https://github.com/LowPowerLab/RFM69/blob/master/Examples/WirelessProgramming_OTA/Target/Target.ino

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #7 on: September 25, 2018, 04:17:19 PM »
Still same result.

I added a line to get/print the frequency at the end of loop.

Attached is screenshot of output.

Is it possible I have a bad radio?  That I did something to fry the radio?  Only soldering was for FTDI and antenna.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Radio Frequency
« Reply #8 on: September 25, 2018, 09:34:15 PM »
Try 915000000 instead of RF69_915MHZ which is a library directive (value==91 which is an invalid Hz argument).
915mhz = 915 million hertz.
Are you sure it shouldn't be 915000000UL? I'm not sure if it gets truncated to an unsigned int without the UL bit.

Mark.

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #9 on: September 26, 2018, 08:27:17 AM »
Still same result when using 915000000UL.

Here is screenshot


kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #10 on: September 26, 2018, 08:34:02 AM »
On a lark, I decided to go back to an older version of the RFM69 library.(1.1.0) and older version of SPIFlash Library(101.1.0).

Now I get the proper readout.

kwalkerk

  • Newbie
  • *
  • Posts: 34
  • Country: us
Re: Radio Frequency
« Reply #11 on: September 26, 2018, 01:07:00 PM »
UPDATE:

I reloaded the current RFM69 libraries and now it all works.  Regardless of whether I use 915000000UL or 915000000.

I must have had a bad update before.

Thanks for all the suggestions/help.

Ken

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5934
  • Country: us
    • LowPowerLab
Re: Radio Frequency
« Reply #12 on: September 26, 2018, 06:59:22 PM »
Thanks for the update, I was gonna look into it, but I was pretty confident no such bug was introduced in the latest releases.
I will mark this solved but please verify the library you now have installed is the latest available on github.
Also, there should never be 2 versions of the library (renamed / in separate folders) in your libraries folder or strange things will happen if it even compiles.