LowPowerLab Forum

Hardware support => General topics => Topic started by: Kilo95 on October 02, 2017, 07:44:12 PM

Title: Incorrect readings on Weathershield, does not wake up [solved]
Post by: Kilo95 on October 02, 2017, 07:44:12 PM
I just updated two of my Weathershields to the new sketch located here:
https://github.com/LowPowerLab/RFM69/blob/master/Examples/WeatherNode/WeatherNode.ino

I am getting incorrect readings. Both are Moteinos. (One is R4 and one is R6). Both Weathershields are R2. I added the sparkfunbme library and changed passwords etc to fit my setup but I'm getting incorrect H and P on one and all metrics are incorrect on the other. The Moteino R4 setup was working flawlessly before I put the latest sketch on it and I don't have the old sketch to fall back on. Any suggestions? 
The erroneous readings:
https://imgur.com/gallery/Zogtn
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 03, 2017, 07:12:51 AM
Enable serial in the sketch, what do the DEBUG statements output on that node?
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 03, 2017, 08:21:08 AM
i figured that out. I was wrong, one was a Weathershield R1 (on the Moteino R4). I was also using the Gateway sketch instead of the PiGateway sketch. Different issue now...I am using this sketch on the WS R:
https://github.com/LowPowerLab/RFM69/blob/0c0e3455b544116b2140d0f2759268aafce3e2da/Examples/WeatherNode/WeatherNode.ino

and this on the R2:
https://github.com/LowPowerLab/RFM69/blob/master/Examples/WeatherNode/WeatherNode.ino

both give one reading to the Gateway and then stay asleep. The ATC is enabled on the Gateway Moteino and the WS node. I have another WS that I haven't updated the software on and it still works fine and also a Sonarmote that still updates correctly.
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 03, 2017, 09:13:38 AM
Can you try the sketch (for WeatherShield R2) below instead please and let me know if it still doesn't wake up:

// **********************************************************************************
// Sample RFM69 sender/node sketch for the WeatherShield
// https://lowpowerlab.com/guide/weathershield/
// Copyright Felix Rusu 2017, http://www.LowPowerLab.com/contact
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it
// and/or modify it under the terms of the GNU General   
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or       
// (at your option) any later version.                   
//                                                       
// This program is distributed in the hope that it will   
// be useful, but WITHOUT ANY WARRANTY; without even the 
// implied warranty of MERCHANTABILITY or FITNESS FOR A   
// PARTICULAR PURPOSE. See the GNU General Public       
// License for more details.                             
//                                                       
// Licence can be viewed at                               
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************
#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 <SPI.h>      //comes with Arduino IDE (www.arduino.cc)
#include <LowPower.h> //get library from: https://github.com/lowpowerlab/lowpower
                      //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/
#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash
#include <SparkFunBME280.h> //get it here: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/tree/master/Libraries/Arduino/src
#include <Wire.h>     //comes with Arduino

//*********************************************************************************************
//************ IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************
//*********************************************************************************************
#define NODEID        100    //unique for each node on same network
#define NETWORKID     100  //the same on all nodes that talk to each other
#define GATEWAYID     1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY     RF69_915MHZ
//#define IS_RFM69HW    //uncomment only for RFM69HW! Remove/comment if you have RFM69W!
#define ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
//*********************************************************************************************
#define ENABLE_ATC    //comment out this line to disable AUTO TRANSMISSION CONTROL
#define ATC_RSSI      -75
//*********************************************************************************************
#define ACK_TIME      30  // max # of ms to wait for an ack
#define ONBOARDLED     9  // Moteinos have LEDs on D9
#define FLASH_SS      8 // and FLASH SS on D8 on regular Moteinos (D23 on MoteinoMEGA)
#define BATT_MONITOR  A7  // Sense VBAT_COND signal (when powered externally should read ~3.25v/3.3v (1000-1023), when external power is cutoff it should start reading around 2.85v/3.3v * 1023 ~= 883
#define BATT_FORMULA(reading) reading * 0.00322 * 1.52 // >>> fine tune this parameter to match your voltage when fully charged
                                                       // details on how this works: https://lowpowerlab.com/forum/index.php/topic,1206.0.html
#define PACKET_INTERVAL  60000  // report data every minute

#define SERIAL_EN   //comment this out when deploying to an installed Mote to save a few KB of sketch size
#define SERIAL_BAUD    115200
#ifdef SERIAL_EN
#define DEBUG(input)   {Serial.print(input); delay(1);}
#define DEBUGln(input) {Serial.println(input); delay(1);}
#define DEBUGFlush() { Serial.flush(); }
#else
#define DEBUG(input);
#define DEBUGln(input);
#define DEBUGFlush();
#endif

#ifdef ENABLE_ATC
  RFM69_ATC radio;
#else
  RFM69 radio;
#endif

SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit  Windbond chip (W25X40CL)

BME280 bme280;

char sendBuf[100];
byte sendLen;
char Pstr[10];
char Fstr[10];
char Hstr[10];
float batteryVolts = 5;
char BATstr[10];
void checkBattery(void);

void setup() {
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
  radio.setHighPower(); //uncomment only for RFM69HW!
#endif
  radio.encrypt(ENCRYPTKEY);

//Auto Transmission Control - dials down transmit power to save battery (-100 is the noise floor, -90 is still pretty good)
//For indoor nodes that are pretty static and at pretty stable temperatures (like a MotionMote) -90dBm is quite safe
//For more variable nodes that can expect to move or experience larger temp drifts a lower margin like -70 to -80 would probably be better
//Always test your ATC mote in the edge cases in your own environment to ensure ATC will perform as you expect
#ifdef ENABLE_ATC
  radio.enableAutoPower(ATC_RSSI);
#endif
 
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  DEBUGln(buff);
  pinMode(ONBOARDLED, OUTPUT);
  radio.sendWithRetry(GATEWAYID, "START", 5);
 
#ifdef ENABLE_ATC
  DEBUGln("RFM69_ATC Enabled (Auto Transmission Control)\n");
#endif

  if (flash.initialize())
    flash.sleep(); //if Moteino has FLASH-MEM, make sure it sleeps

  bme280.settings.commInterface = I2C_MODE;
  bme280.settings.I2CAddress = 0x77;
  bme280.settings.runMode = 3; //Normal mode
  bme280.settings.tStandby = 0;
  bme280.settings.filter = 0;
  bme280.settings.tempOverSample = 1;
  bme280.settings.pressOverSample = 1;
  bme280.settings.humidOverSample = 1;
}

uint16_t batteryReportCycles=0;
uint32_t time=-1, now=0, lastPacketTime=0;
byte motionRecentlyCycles=0;

void loop() {
  now = millis();
  checkBattery();

  if (time-lastPacketTime > PACKET_INTERVAL)
  {
    lastPacketTime = time; //save timestamp of this package

    //read BME sensor
    bme280.begin();
    dtostrf(bme280.readTempF(), 3,2, Fstr);
    dtostrf(bme280.readFloatHumidity(), 3,2, Hstr);
    dtostrf((bme280.readFloatPressure()/100)*0.0295333727, 3,2, Pstr);
    bme280.writeRegister(BME280_CTRL_MEAS_REG, 0x00); //sleep the BME280
    sprintf(sendBuf, "V:%sv F:%s H:%s P:%s", BATstr, Fstr, Hstr, Pstr);
    sendLen = strlen(sendBuf);

    if (radio.sendWithRetry(GATEWAYID, sendBuf, sendLen))
    {
      DEBUG(radio.RSSI);
      batteryReportCycles = 0;
    }
    else DEBUG("ACK:NOK...");

    DEBUG(" VIN: ");
    DEBUGln(BATstr);

    radio.sleep();
  }
  DEBUGFlush();

  time = time + 8000 + millis()-now;
  radio.sleep();
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  DEBUGln("WAKEUP8s");
  batteryReportCycles++;
}

uint32_t BLR=0;
void checkBattery()
{
  if (time-BLR > 30000) //only read battery every 30s or so
  {
    unsigned int readings=0;
    BLR = time;
    for (byte i=0; i<10; i++) //take 10 samples, and average
      readings+=analogRead(BATT_MONITOR);
    batteryVolts = BATT_FORMULA(readings / 10.0);
    dtostrf(batteryVolts, 3,2, BATstr); //update the BATStr which gets sent every BATT_CYCLES or along with the MOTION message
  }
}
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 03, 2017, 09:33:02 AM
i will do that tonight
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 03, 2017, 09:51:16 PM
I tried that. On both the R1 and the R2 Weathershield. They both go to sleep after the first set of readings come across. The R1 doesn't give a H reading and the T and P are inaccurate. The sketch is the BME280 and the R1 is a BME180. I also tried uninstalling Arduino IDE and reinstalling with no luck. There is not a way I can clone my working Weathershield (R1) that's working and use that sketch on the other R1 is it?
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 04, 2017, 08:12:09 AM
This is for R2.... I should have made that extra explicit in the comments ::)
BME280 is always R2.
R1 is BMP180 and Si7021, different board, different sensors, different libraries. For the WS R1 you need an older sketch that is available here:
https://github.com/LowPowerLab/RFM69/blob/8da8d0c3d4b78a1a67a020dbe644245f8579958f/Examples/WeatherNode/WeatherNode.ino
It's old code and hardware, it should work, but it's no longer actively maintained, also the IDE might have quirks with these old libraries. That's why I stick with IDE 1.0.6.
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 09:00:27 AM
i can try to find IDE 1.0.6 and uninstall/reinstall with that. I did try that sketch on the R2 and it still goes to sleep after the first transmission. i still have the BMP180 and Si7021 libraries. any ideas what's up with the R2?
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 04, 2017, 11:28:02 AM
You can install two IDEs side by side, they can share the same hardware/library/sketch folder and won't eat each other :)
Not sure about R2, if you want, you can send it back and I can debug it.
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 12:19:59 PM
ok. i'll try installing the old IDE next to it and try that first before I see about having you debug it. It has me perplexed since my Sonarmote and my other WS (R1 that I did not reupload to this time) work like a charm.
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 04, 2017, 01:16:50 PM
I'm sure its some small detail, probably software wise. Hard to say when hardware is involved :)
Do you happen to know which IDE and which exact sketch did you use with your other WeatherShield R1? Does that other WS R1 work with a Moteino R4, and this non-waking one is using an R6 Moteino?
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 01:38:55 PM
I have two Moteino R4 with WS R1s. I have a M4 +R1 that's not waking after the first reading (with the BMP180 associated sketch below) and a M6 +R2 (with the latest sketch) that's not waking after the first reading. the other M4+R1 and the Sonarmote are working fine through the same Moteino USB and RPi.

https://github.com/LowPowerLab/RFM69/blob/0c0e3455b544116b2140d0f2759268aafce3e2da/Examples/WeatherNode/WeatherNode.ino

I would think if it was the RPi or Moteino USB on the gateway that all four nodes would be jacked up
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 04, 2017, 01:53:38 PM
Ok please enable debugging in the sketches and see what serial spits out on the nodes.
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 01:55:24 PM
will do
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 06:54:59 PM
looks like its enabled in the R2 sketch. both continue to update when they're connected via FTDI and USB to my computer and i'm watching in the serial monitor. (they also update correctly on the Gateway page). soon as I connect to battery, they fizzle out after one transmission

Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 07:13:41 PM
guess i was wrong.. how do i enable debugging
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 04, 2017, 11:52:41 PM
i reuploaded the gateway sketch. I was using the same power source for both of the Motes in question. i think it has a bad power switch. will update the next day or so
Title: Re: Incorrect readings on Weathershield
Post by: Kilo95 on October 05, 2017, 08:44:03 AM
It appears that it was the power switch on my battery holder. Must have been intermittently cutting out. Both nodes ran fine all night. I would say this is [solved]. Thanks
Title: Re: Incorrect readings on Weathershield
Post by: Felix on October 05, 2017, 10:52:30 AM
Awesome, thanks for the update... those pesky supplies, who would have thought!
Title: Re: Incorrect readings on Weathershield, does not wake up [solved]
Post by: Kilo95 on October 05, 2017, 08:41:43 PM
Exactly. It's a 3xAA battery holder with a switch. I just happened to move it just right and saw the light on the Mote flicker so I wiggled it and that's how I found it. Chinese junk battery holder...
Title: Re: Incorrect readings on Weathershield, does not wake up [solved]
Post by: Felix on October 06, 2017, 10:04:30 AM
Love cheap china huh... just to reflect how much it really cost in terms of wasted time to find a simple problem hiding in plain sight. And its just a switch, nothing complicated!
Title: Re: Incorrect readings on Weathershield, does not wake up [solved]
Post by: Kilo95 on October 06, 2017, 09:18:37 PM
Yeah. No kidding. I went with a battery holder without the switch this time. After all I can just unplug the JST connector