ILI9327 TFT, BME280, DS3231: Display Date, Time, Temp, Humidity and Pressure, Heat Index, DST, With Min and Max Values Saved on Micro SD.

by giano2002 in Circuits > Arduino

1109 Views, 4 Favorites, 0 Comments

ILI9327 TFT, BME280, DS3231: Display Date, Time, Temp, Humidity and Pressure, Heat Index, DST, With Min and Max Values Saved on Micro SD.

Display_HI_low.jpg
20230413_095502.jpg

I have used an Arduino Mega 2560, with an Open Smart 3.2" TFT LCD Shield display, with ILI9327, a BME280 temperature, Humidity and Pressure sensor, a RTC DS3231 precision clock module, and the sketch that is attached.

Added the record, on micro SD card, of the date and minimum and maximum values of temperature, pressure and humidity of the last 24 hours, and backlight management.

Also added the Daylight saving time for Europe and USA.

Latest update: added Heat index value - that will be displayed in the upper right box - when Temperature and Humidity values will be equal or higher, respectively, to 27° and 40%.

The device works as follows:

1) after loading the sketch, or every time it connects to a power supply with 5 V output, the program verifies that the sensor is connected and initializes the micro SD card;

2) writes "SD" on the display and this writing will be canceled after the first refresh of the display;

3) starts displaying the date, hour and minutes, temperature and humidity, with the minimum and maximum values ​​recorded in the 24 hours;

4) if the temperature and humidity exceeds 27 degrees Celsius and 40%, it also displays the heat index in the upper right box;

5) at 23:59 it saves the Min and Max values ​​and the date on the micro SD and writes "Mem" on the display;

6) at 00:01, the program resets and restars the Arduino;

7) at 00:06 it switches off the backlighting, which will be reactivated at 07:00. The backlighting can be switched on using the push button switch.

Supplies

20230211_125724.jpg
20230211_125755.jpg
20230211_125123.jpg

1 Arduino Mega 2560;

1 RTC DS3231;

1 display TFT ILI9327 3.2";

1 BME280

1 micro SD

1 n.o. button

Clock, Calendar and Accurate Thermometer and Hygrometer.


In order to use the ILI9327 3.2" display, I used the only library I could find on the Internet, the MCUFRIEND_kbv, on https://github.com/prenticedavid/MCUFRIEND_kbv.

The other libraries used are:

<BME280I2C.h>

<Wire.h>

<RTClib.h>

<TimedAction.h>

<SPI.h>

<SD.h>

"DST_RTC.h"


The biggest challenge was getting the ILI9327 TFT display to work. I have used that display because I had it in my drawer for a couple of years and hadn't been able to find a way to make it work so far. I succeeded only after modifying three lines of the library MCUFRIEND.cpp file.


To be precise: it is necessary to uncomment line n. 16, which becomes:

<#define SUPPORT_8352B //HX8352B In the original file this line #16 was commented>;

add line no. 25, whith the following:

<#define SUPPORT_9327 //UNTESTED In the original file this line #25 was empty>;

uncomment line no. 28, which becomes:

<#define OFFSET_9327 32 //costs about 103 bytes, 0.08s In the original file this line #28 was commented>.

For your convenience, I am attaching the modified MCUFRIEND.cpp file.

The connections between the Arduino board and the BME280 sensor and RTC module are very simple: +5v, GND, pin 21 for SCL and pin 20 for SDA.

To set up the device, you need to edit the lines of the sketch and upload it, as follow:

1) uncomment line 75 or 76, according to your DST area ("EU" or "US");

2) edit line 95, to set your location heigth on sea level, in meter (it is necessary for the program to be able to calculate the atmospheric pressure related to sea level);

3) uncomment the line 161 <//rtc.adjust(DateTime(2023, 2, 4, 10, 12, 0)>, to set the current year, month, day, hour, minute, seconds, and upload the sketch. It is important to set your local hour (nor DST), even if you are in DST, because the program will calculate the exact time (DST or not)!

4) after that, comment the line 161 and upload again the sketch.

If use a battery on the RTC DS3231 module, the date and time will be retained even if the Arduino board is powered off.

The project works well, I was able to test it for a long time.

The device shows Min and Max values, too, with decimals, and records those values on the micro SD card. The Heat Index is displayed in the upper right box when temperature is equal or higher than 27° C and humidity is equal or higher 40%.

Making changes to the Shield, as shown in the pictures, and to the sketch, the backlight of the display twill turn off between midnight and seven a.m. (these time can be modified), and with the n.o. button is possible to turn on the display momentarly, during the period it is off.

Any suggestion about this project will be welcome.

Manage the Backlight

ILI9327 Shield.png

I made an upgrade by adding some resistors and a push button to the shield, and some lines to the sketch. Now the backlight of display is turned Off at 00:06 and again On at 07:00 (these times could be modified). And during the time the backlight is Off, it is always possible to turn it momentary On, closing the button. I thank for the help FernandoGarcia.

In the photo I drew the changes to be made to the ILI9327 shield. In practice, to be able to control the backlighting of the display, unsolder the jumper marked 3.3V and solder a 4.7K resistor to the upper pad marked D3, then solder another 10K resistor in series with the 4.7K resistor and this last to Ground. Then join the common point between the two resistors to the second pad D3. To be able to control the backlighting with a button, when the backlight is Off, solder a normally open button between PIN D2 and Ground and a 10K resistor between PIN D2 and +5V. In the attached sketch you will find the changes I made for the backlight control.