Joystick Weather Clock, 15 months on

joystick-weather-clock

The original post for this project can be found here  A link to all the files on GitHub can be found here.

Following a suggestion from Alan Powell I decided to add a Humidity Sensor. The DHT11 is cheap and suited to this project. A lack of variable space meant that I was unable to save the data to the SD Card but as a bonus, the Humidity screen displays the Dew Point. See the end of this blog for more details.

Back in September 2015, I built this Joystick Weather Clock and it has sat on my desk recording pressure and temperature on an SD Card for fifteen months, without missing one hourly record. The data was stored as a CSV file so that it would load into EXCEL or similar spreadsheet program. I decided to see how it was faring after running all that time uninterrupted.

The fact that it was still saving data meant that there had been no stack overflow caused by unused variables filling up available free memory. The DS1307 Real time clock had not done too well, it was now 45 minutes fast, gaining around 38 seconds per week. The OLED display seemed to have lost a number of pixels and in places the display looked a little ragged, the LEDs used to light up under the display were still going strong. The pressure sensor was working perfectly.

So much for the hardware, what about the software? The calendar was perfect, having come through a leap year and the moon phase display was spot on. Data had been recorded exactly as designed and the whole file on the SD Card took up less than 4mb. Over 11,000 hourly temperature and pressure readings had been recorded and I believe this unit could run unattended for several years.

The pressure information was the most interesting, it was possible to follow the remains of a hurricane that hit the UK at the start of January 2016.

pressure-graph

The pressure had remained fairly stable at around 102000 pascals until New Year’s Eve, dropping to below 98000 pascals over four days. The result was high winds and flooding.

I am really pleased with the software side, but I feel that a better Real Time Clock module is needed. To protect the OLED I think some kind of simple Screen Saver is needed and I will add this in the new year sometime. The subroutines to calculate the calendar and moon phase have worked flawlessly and, although the data saved on the SD Card is OK, I think that a VBA routine for EXCEL to extract the Pressure and/or the Temperature data and to place it all in a single column is needed. This will allow a graph to quickly be drawn. Please note that the hourly data builds up throughout the 24 hours and only the data saved at  2300 hours contains all the days’ data.

One final addition would be to use a 5-volt power bank as a backup battery, it can be left plugged into the Arduino and would only be used if the mains power was lost. The software saves the last 48 hours in a temporary file on the SD card, if the power is lost then once power is restored this temporary data is loaded, but if the power is lost for more than one hour the data for the time during power down would be lost.

Adding another Sensor:

The Sketch uses 74% of the available space for variables and at 78% usage the Arduino  IDE starts to complain, so I have tried to keep below this figure. I decided to try to fit a Humidity sensor, following a suggestion from Alan Powell. The DHT11 although slow is quite cheap and as long as you don’t request data too often it should work well. I started by installing the library and the routine to read the Humidity data. That consumed very little precious variable space. I then added a new screen to display the data. Now I had a working Humidity screen that also displayed the Dew Point.

The DHT11 is a slow device that should not be addressed more than once every few seconds. I decided to save the Humidity value and only update it once an hour when data is saved to the SD card. When you display the Humidity screen the value could be up to an hour out of date, but simply press the joystick and the value is updated immediately.

I fitted a ChronoDot board with a DS3231 RTC chip, this is just a simply plug in replacement, I just needed to swap the SDA and SCL lines. No change to Library or Sketch is needed.

Heres to the next 18 months when I can see how well the new RTC performs.

humidity

The new Humidity screen, accessed by moving the Joystick one place left from the Analog Clock Screen. The age of the reading is shown and although this is updated once an hour it can be updated manually at any time by pressing the joystick switch in this screen.

The DHT11 has three pins 5v, OUT and GND. Connect 5v and Gnd to the Arduino and OUT to digital pin 12. While I was fitting the DHT11 I took the opportunity to swap the DS1307 RTC for a (hopefully) more accurate DS3231.

The picture at the top of this post shows the new ChronoDot RTC and DHT11 fitted to the clock.

weather-clock-wiring-diagram

Use this connection diagram in conjunction with the wiring instructions in the sketch. Check the pinouts on your devices before wiring as they may not match those shown above. The OLED will die instantly if not connected correctly.

Joystick Control with Arduino


This code is available on my GitHub page here

Keyes version is KY023

There are a number of different versions of this and sometimes the pin outs will differ from those shown here. The joystick consists of two potentiometers at right angles, one controlled when the stick is moved in the Y direction (up/down) and the other in the X direction. There is normally a switch operated when the button is pushed. The potentiometers are connected to Vcc and ground and the value is read from the middle pin.

This sketch is a basic way of testing the joystick, later blogs will show how to use the joystick to select items from a menu. The values for X and Y as well as the switch state are printed in the Serial Monitor.

Use this sketch to measure the values of X and Y when the joystick is in its home position in the centre. Up is when the value of Y increases, down is when the value of Y decreases. Left is when the value of X increases, Right is when the value of X decreases.


/*************************************************
Joystick Test
prints the output from the joystick on the Serial Monitor

Connections:
Gnd on Joystick to Gnd on Arduino
Vcc on Joytick to 5 volts on Arduino
VrX on Joystick to A0 on Arduino
VrY on Joystick to A1 on Arduino
Sw on Joystick to pin 2 on Arduino

*************************************************/
// definitions for pins
#define xPin 14
#define yPin 15
#define joySwitch 2
#define ledPin 13

// variables
boolean switchState = true; // it will be false when pressed
int xValue = 0;
int yValue = 0;

void setup(void){
Serial.begin(9600);
pinMode(joySwitch, INPUT_PULLUP); // turn on pullup resistor
pinMode(ledPin, OUTPUT); // onboard LED
}


void loop (){

// main code will go here and joyStick() is called as a subroutine
joyStick();
}


void joyStick(){
// this routine reads the joystick values
xValue = analogRead(xPin);
yValue = analogRead(yPin);
switchState = digitalRead(joySwitch);
// remove following lines if not required
Serial.print("X value = ");
Serial.println(xValue);
Serial.print("Y value = ");
Serial.println(yValue);
Serial.print("Switch state = ");
Serial.println(switchState);
if (switchState == false){ // switch pressed
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
//
delay(1000); // delay to allow data to be seen
}