Z-Control Grove Thermostat

From openPicus Wiki
Jump to: navigation, search

Contents

Summary

My winter garden has no heating during winter time. I had a heating system in place, but the thermostat did not work that well, so I decided to build a thermostat with a Flyport and Grove modules. On top of an accurate thermostat I could control it over my iPad. The result is documented in this article.

Components used

  • Flyport version B (I had no G model available).
  • Grove Board, we need I2C, Digital in, Digital out for our solution
  • Grove Relay 10Amp, that should be enough Amps for many loads to be switch on/off
  • Grove Temperature/Humidity sensor Pro
  • One I2C memory chip (I used a 24c08 SO8 chip I glued with a Grove connector).
  • Diverse Grove libraries from the Openpicus Web page.

Firmware

Web page

My idea was to keep it simple, so the current code only supports precompiled internet connection, in my case simple Ad-hoc mode. I decided to use the user interface I found in Alex Donatelli project, grat look, so thanks to him for that very nice interface. I added a temperature and humidity level buttons that would be used to increase/decrease the switch level of the relay.

Z-control-grove-thermostat-webserver.png

Functionality, cabling

Both Temperature and Humidity sensor can be used simultaneously. This means you can connect two relays on the Grove-Nest. A relay connected to DIG3 will react on the temperature level, a relay connected to DIG4 will switch Humidity. An LED was added to the original WEB layout to show if the relay is activated or not. Depending on the electric cabling, you can decide if the electric equipment needs to be switched on or off when reaching the selected level. In practice this means that you can switch air condition on if the temperature is below the selected level or you can switch a heater on if the temperature is above a certain level. Same logic applies for Humidity on DIG4. In order to avoid the relay to jitter when temperature/humidity is near the critical level, a hysteresis of 0.5 deg/% was added to the comparison function inside the Flyport code. Feel free to increase it if 0.5 is not enough. The Temperature/Humidity Sensor was connected to DIG1.

Building Grove non volatile memory

In order to keep the temperature and humidity selection even after reset or power failure, we need to keep the parameters inside non volatile memory. As the PIC24 has no EEPROM, I decided to use an I2C memory chip that would be easier to handle than writing into Program Memory. Also I2C memory allows much more write cycles than Program Memory. The current implementation will save the parameters after each click on the web-page. A reset or power cycle will read the i2c memory and set it to the last selected level. On the first power-up, the temperature level will be set to 20degC and Humidity level to 40%.

Z-control-grove-thermostat-i2c-24c08.jpg Soldering an original Grove cable to the I2C 24C08 chip


Z-control-grove-thermostat-glue-on-memory.jpg Pour hot glue on the memory to protect and solidifying the soldering

Relay case

In order to protect high voltage contact from the environment the relay was installed inside a plastic case. One cable connects it to the Grove-Board, a second cable manages the 220V switched side.

Z-control-grove-thermostat-relay-scheme.jpg Pin 1-2 are connected to grove


Z-control-grove-thermostat-relay-box.jpg Ideal solution for the power switch, plug with bypass to the relay, relay inside the box.

Code

The thermostat code is based on standard grove code from the Openpicus library. You will find the standard documentation if you have any question regarding the grove functionality. Grovelib.h, GroveBoard.h to connect the board and relays RTH03.c includes the code for reading the sensor 24c08.h includes the memory i2c address and a structure to store data. The following code part in TaskFlyport.c checks if memory exists and sets default values if the memory was never uses.

......
	report = I2CReadMulti(MEM_ADDR,0,(BYTE*)&dat,sizeof(dat),100);
 
	if (report)
		UARTWrite(1, "I2C Memory Reading SUCCEDED\r\n");
	else
		UARTWrite(1, "I2C Memory Reading NOT SUCCEDED\r\n");
 
// set memory if zero inside
	if(dat.Temp==0 || dat.Hum == 0)
	{
	dat.Temp=20.0;
	dat.Hum=40.0;
	I2CWriteMulti(MEM_ADDR,0,(BYTE*)&dat,(size_t)sizeof(dat));
	}
......

Standard Openpicus i2c code was used to store and recover the data on i2c memory.
Here is Source Code

Summary

The current solution works pretty well, the WEB interface with large characters can be read from a good distance, i.e. when iPad is on the shelf. The Only feature to add is a configutation menu allowing WIFI connection changed when on Infrastructure network.

Enjoy using the code, send your comments if any to info@z-control.ch Rolf Ziegler, www.z-control.ch, February 2014

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox