Author Topic: "radio" not declared error  (Read 4013 times)

DonpK

  • Jr. Member
  • **
  • Posts: 76
  • Country: us
"radio" not declared error
« on: June 19, 2018, 09:02:06 PM »
I've started a new sketch and am getting a  "'radio' was not declared in this scope" error. The "RFM69_LowPowerLab" library is installed in the Arduino/libraries folder. All my other Moteino sketches still compile fine.

I copied the following includes into the new sketch from one of the other functioning sketches:

Code: [Select]
/ **********************************************************************************
#include <RFM69.h>         //get it here: https://www.github.com/lowpowerlab/rfm69
#include <RFM69_ATC.h>     //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPIFlash.h>      //get it here: https://www.github.com/lowpowerlab/spiflash
#include <SPI.h>           //included with Arduino IDE install (www.arduino.cc)

When I comment out the two RFM69 radio.  functions used in my new sketch, it compiles with no errors.

Suggestions?
 

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: "radio" not declared error
« Reply #1 on: June 19, 2018, 10:14:31 PM »
My suggestion is to include the entire sketch without any changes.  What you included is not only incomplete, but the very first line does not look like a valid SINGLE comment line.

DonpK

  • Jr. Member
  • **
  • Posts: 76
  • Country: us
Re: "radio" not declared error
« Reply #2 on: June 20, 2018, 08:20:06 AM »
Below is the entire sketch.

Code: [Select]
//**********************************************************************************
#include <RFM69.h>         //get it here: https://www.github.com/lowpowerlab/rfm69
#include <RFM69_ATC.h>     //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPIFlash.h>      //get it here: https://www.github.com/lowpowerlab/spiflash
#include <SPI.h>           //included with Arduino IDE install (www.arduino.cc)
#include "LowPower.h" //Ver. 1.60 corrected problem with BOD not being turned off turn power down mode.
#include <avr/wdt.h>
//*********************************************************************************************//
#define NODEID        3   //must be unique for each node on same network (range up to 254, 255 is used for broadcast)
#define NETWORKID     100 //the same on all nodes that talk to each other (range up to 255)
#define GATEWAYID     1
#define FREQUENCY     RF69_915MHZ
#define ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HW_HCW  //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
#define ENABLE_ATC    //comment out this line to disable AUTO TRANSMISSION CONTROL
#define ATC_RSSI      -80
//*********************************************************************************************//
int sensorPin = A0;     // select the input pin for moisture sensor
int sensorValue = 0;    // variable to store the value coming from the sensor
int moisturePercent = 0;// sensorValue mapped to a percentage of sensors dry & wet values.
int sensorPower = 2;    // Vcc power for moisture sensor
int wdtCounter = 0;     // Number of time WDT will restart the specified sleep period
//-----Transmit & Receive Variables-----
int txPacketSize = 0; //Actual size is set with strlen before radio.sendWithRetry()
char txPacket[30]; // array to hold data transmitted to Gateway

void setup()
{
//--------------
        radio.initialize(FREQUENCY,NODEID,NETWORKID);
      #ifdef IS_RFM69HW_HCW
        radio.setHighPower(); //must include this only for RFM69HW/HCW!
      #endif
      #ifdef ENABLE_ATC
        radio.enableAutoPower(ATC_RSSI);
      #endif
//-----------------
      pinMode(sensorPower, OUTPUT);
      analogReference(DEFAULT);
      wdt_reset();
      Serial.begin(9600);
      Serial.println("Starting measurement...");
}
void loop()
{   
       sensorValue = checkMoisture();
       Serial.print(sensorValue ); Serial.print("\t");
       moisturePercent = (map(sensorValue, 380, 785, 100, 0));
       Serial.print(moisturePercent); Serial.println("%");         
       delay(100);       
       digitalWrite(sensorPower, LOW); // turn sensor power off
       WDTimer(1); //For testing: Call WDT every WDTimer(n x 8 secs) for interval between sensor measurement 

// ---------Send packet------------
       char buff[20];
       sprintf(buff,"%d", moisturePercent); 
       Serial.print("Packet returned to Gateway = "); Serial.println(txPacket);       
       txPacketSize = strlen(txPacket);
       radio.sendWithRetry(GATEWAYID, txPacket, txPacketSize);
       Serial.println();     
 
 }//----End of Main Loop----------
//-------------------Called Functions-----------------------------
//---------------Check Moisture Function----------------
 int checkMoisture()
    {
           digitalWrite(sensorPower, HIGH); // turn sensor power on
           delay(100);
           return(analogRead(sensorPin)); //read sensor value
    }
  //************* Watchdog Timer Function*********
 void WDTimer (int wdtCounter)
{
  wdt_reset(); //reset WDT
    int i;
    for (i = wdtCounter; i > 0; i--)
    {
      //  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //wake up after 8 secs.
      LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF); //For testing: wake up after n secs.
    }
 }

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: "radio" not declared error
« Reply #3 on: June 20, 2018, 08:24:48 AM »
I do believe you've left out:
Code: [Select]
RFM69 radio;
Maybe the error message meant something.

DonpK

  • Jr. Member
  • **
  • Posts: 76
  • Country: us
Re: "radio" not declared error
« Reply #4 on: June 20, 2018, 10:42:41 AM »
Thanks, Tom. My effort to prune as I copied and pasted from the working sketch to the new sketch went seriously wrong. I added:

Code: [Select]
#ifdef ENABLE_ATC
  RFM69_ATC radio;
#else
  RFM69 radio;
#endif

Speaking of copying and pasting. I notice in this post and my last post of the full sketch that the original IDE text formatting (font weight, color, etc.) is not always accurate when I post it in a Forum message between the tags. What am I doing wrong here?

Thanks for your help.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: "radio" not declared error
« Reply #5 on: June 20, 2018, 11:48:48 AM »
Speaking of copying and pasting. I notice in this post and my last post of the full sketch that the original IDE text formatting (font weight, color, etc.) is not always accurate when I post it in a Forum message between the tags. What am I doing wrong here?
The formatting does not copy at all, it's simply the way the forum styling is applied to code blocks, has nothing to do with how the IDE formats it.