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:
/ **********************************************************************************
#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?
Below is the entire sketch.
//**********************************************************************************
#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.
}
}
Thanks, Tom. My effort to prune as I copied and pasted from the working sketch to the new sketch went seriously wrong. I added:
#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.