Tutorial – Guest Blog – Using SunControl WatchDog Timer on OurWeather

Tutorial – Guest Blog – Using SunControl WatchDog Timer on OurWeather

Editors Note:  We were tickled to receive another guest blog by Larry Bonnette.   He did a great job on building this Solar Powered OurWeather Kit and by adapting the GroveWeatherPi solar panel kit to the OurWeather Kit.   This blog post talks about how to use the WatchDog Timer on the new SunControl board with the OurWeather Kit.   While this article is specifically about the “Arduino Like” WeatherPlus board, you can apply the same techniques to a Raspberry Pi Based system like GroveWeatherPi.

What is OurWeather?

OurWeather is an ESP8266 based  connected weather station containing 7 different sensors that will teach about electronics, software and theunspecified-8 copy weather.   It contains all 0070Gthe sensors and wires to make a fully functional, WiFi weather station.   No software programming is required, it works right out of the box. However, if you want to change the way OurWeather works, add your own software or do something entirely different, we have the Open Source software available.   And what is one of the coolest features of OurWeather?   Building the kit requires NO SOLDERING. It uses Grove Connectors.    It is all plug and play based building, with a full step-by-step photograph based instruction manual.  It is a safe and educational way to learn about weather, electronics and science topics.   You can watch our successful kickstarter video here: https://youtu.be/pw6hSNSQnsM

See the Grove Connector Tutorial Here.

What is SunControl?

The SunControl Solar Power Controller Board for Raspberry Pi, Arduino and Cell Phone Charger is a 4th Generation Solar Charging and Sun Tracking Board designed by and manufactured by SwitchDoc Labs.

You can use this board to power, measure  and control your Solar Power projects. It incorporates a number of outstanding features in a very compact, inexpensive single fully assembled and tested PC Board.  SunControl is customizable with your software and hardware.  It’s even used on Project Curacao2.

 

Using the SunControl WatchDog Timer – Larry Bonnette

I have a Switchdoc.com “OurWeather” weather station set up at our RC flying field in New Waverly Texas.

You can see it here: https://tri-countybarnstormers.com/weathsta.htm

It works pretty well but every so often it stops working.  Iit is a 20 mile drive from my house to the field and sometimes I just can’t find the time to go out there to reset it.

Using an external watchdog timer may remedy the problem.

Switchdoc has a dual watchdog timer for sale. But, I am controlling my solar system with SwitchDocs newest board called the “Sun Controller-Advanced Solar Controller”.

The SunControl board has a watchdog timer built right into it (circled in red).

A watch dog timer is a simple timer that runs independently of a circuit (in our example the WeatherPlus board is the circuit). The watch dog timer runs for a set amount of time (say 60 seconds). When the 60 seconds has elapsed, it resets the WeatherPlus board. The timer is kept from continuously timing out by embedding code in the software to periodically reset the timer so it never times out. This is called “patting the dog”.

The theory is, that as long as the WeatherPlus board is running code (and resetting the timer) It does not need resetting. If the WeatherPlus stops running code. The timer will time out and the WeatherPlus will be reset.

The watch dog timer on the SunControl board has jumpers that allow you to change the time out value of the timer. You can choose a timeout value from 1 second to 64 seconds. Just ground the appropriate pin. I chose to operate the timer using the 64 second setting (no jumpers grounded). But, I added a jumper pin to the board so that I can test the timer at 30 second intervals. Grounding this pin sets the timeout to 30 seconds. There is a handy red LED (circled in red) that blinks when the timeout occurs

.
I tested the watchdog by grounding the indicated pin. Every thirty(ish) seconds the LED blinked indicating a timeout.

OK, the timer works. But, will it reset the WeatherPlus board? How do I hook it all up?

What is the WeatherPlus Board?

The heart of the OurWeather Weather kit is the SwitchDoc Labs WeatherPlus board.

The major features of the WeatherPlus Board are:

  • – Provides an excellent controller for a Weather Station hooked up to Raspberry Pi or Arduino
  • – Includes Arduino and Raspberry Pi Software
  • – Supports SwitchDoc Labs WeatherRack Wind Vane / Anemometer / Rain Bucket
  • – Contains I2C BMP280 Barometer/Temperature
  • – Includes DS3231 RTC/EEPROM
  • – Directly powers Raspberry Pi / Arduino
  • – Works with Raspberry Pi (3.3V) GPIO and Arduino (5.0V) GPIO
  • – Works with 3.3V and 5.0V I2C bus
  • – All onboard devices are 3.3V
  • – Supports I2C Lightning Detector MOD-1016
  • – Supports I2C AM2315 Temp/Hum Sensor
  • – Supports I2C Optional 32KB FRAM

 

Here is the specification for the WeatherPlus board.

 

Back to the WatchDog Timer

The WeatherPlus board is an Adruino (like) board and it has a reset pin on JP17. If you pull this pin low (ground it), It will reset the WeatherPlus board.
To test this, I connected the output of the watchdog timer to the RST pin on the WeatherPlus.

 

The watchdog timer output is the pin on JP7 marked RESETN. There are other pins that activate during a timeout but the only one that goes low is the RESETN pin on JP7.  I powered the WeatherPlus from the SunControl board using the USB connectors on both boards.

I turned on the power to the SunControl board and in 30 seconds the red (watchdog) LED flashed and the WeatherPlus board reset.

Cool !

We now know that the watchdog works, and that it can reset the WeatherPlus board. But, we need to figure out how to “pat the dog” so that the WeatherPlus board does not keep resetting.
We need a pin on the WeatherPlus board that is free and we need to connect that pin to the watchdog timer.

I looked at the documentation for the WeatherPlus board and found that GPIO #2 on JP18 is free. So, I will use that pin to “pat the dog”.
Where do we connect the GPIO #2 pin ?

We connect it to the “Done” pin on JP5 on the SunControl board.

The “Done” pin wants to see a pulse going from a low to a high. This will reset the timer (before it times out).
The code I use is:

#define RESET_WATCHDOG 2 //To the Watchdog timer input on JP5 “done” on the SunControl board
 void ResetWatchdog() //Watchdog timer routine toggles pin #2 from low to high and then back to low
 {
    digitalWrite(RESET_WATCHDOG, HIGH);
    delay(200);
    digitalWrite(RESET_WATCHDOG, LOW);
 }

I am using Switchdocs version 023 code and I placed the code above at about line 470 in the SDL_ESP8266_WeatherPlus.ino file.

I added:

   pinMode(RESET_WATCHDOG, OUTPUT);
   digitalWrite(RESET_WATCHDOG, LOW);
   delay(200);

just under the Setup(); line (around line 535). This ensures that the pin is set to “OUTPUT” and starts at a LOW setting. I then pat the dog (at line 539).

 

I then “sprinked”

ResetWatchdog();

Throughout the code.

Specially at:
Line 539, 986, 1000, 1024, 1169, 1287, 1366, 1440, 1530, 1564 and 1695
The point is to make sure that the “dog” gets attention often enough so that the watchdog timer does not fire.

Is the above overkill ? Maybe, but it seems to be working.

I will report back on the reliability improvement. Less 20 mile trips to reset! More airplane flying!

1 Comment

  1. It has been a month now and the weather station at the flying field is still humming right along.
    The addition of the watchdog time in my opinion is a rousing success

Comments are closed.