It really doesnt have a lot to do with the actual control of the heat mat, but i thought itd be nice to have a clock on the display since ill have something up anyway, depending on the feedback i get. I might do another video where we set the clock through the next shin im, going to wait and see if i get feedback for that first. Otherwise, this might be the last part of this series. So the only thing were going to do with the nection is were going to add another text field so that we can write to it, whether its on the whatever page its on im, going to set it to global im going to set the font to 2.. I added another font: itll just make it a little bit bigger, but if you see the size of the room i wont be able to fit if i put the month year date and the time so you can see its just a little bit bigger. Then im going to make the length of it 25 im, not 100 sure probably 20 would be fine, but well just set it to 25 and then im going to put a fake date in there that uses all the characters so that way, im using up all The spaces i know that it fits and we should be good. I just have to remember that its called t3 and thats it for this now were going to switch over to the arduino im going to add another tab to the arduino page.

For this im going to call it rtc in every video in the series, ive started right from where the other one left off. So if you want the files, you should be able to go to and download it for each part in this one, since were just adding the real time clock it works over the i squared c bus, so theres really not too much to add to this Page im going to put it right underneath the software serial, so all we have to do is include the wire.h library and then in the setup. Well, just have to start it. You can do some error detection here, like if wire began, to do some things, but at this point, since its not crucial to the application im, just im not going to do any of that were just going to keep it simple thats. All we have to do on the main file. The other work is going to happen in the delay, tab and then im going to add some functionality into the rtc tab. I didnt add a library for the clock itself. I generally dont with the with the real time clocks. I just do it through the i squared c bus, and so it will add a little bit of complexity to this page, but were going to start just by adding a function called rtc and were going to return a string from it and thats. Why? I have that string in front of it now the real time clock works in something called bcd instead of decimal.

So i have two helper functions that convert bcd to decimal and decimal to bcd, and they just help out im not going to go into it too much in this video. I have another video if you once again, if you head over to cheap controls, do a search for real time clock. This is something that i include if i have the space in my arduino files, and it just shows the addresses on the i squared c bus, where the different aspects of the device that youre using it in this case its the real time clock. So we want to where the seconds minutes hour date month and year, theres also a day, but were not going to use that. That tells you the day of the week 1 through 7 monday, tuesday wednesday through sunday and theres, also a way to read the temperatures. But were not going to worry about that were going to create an integer called error in this application were not going to look at that error, but i collect it whenever i end the transmission and then that way. If there is a problem, i could serial print it just to see what what the state is for. I squared c you begin the transmission with the address of the device itself and thats separate from the addresses of the memory within the device, so theres the address of the device and then within it the way i look at it as memory locations and so im Going to start from location 0.

, so we write to that. I squared c address 0 and thatll, be the starting point for when i do all of my reads and then im going to request seven locations and im going to start with the seconds the minutes. The hours the days the date the month and the year i dont use the day, but just to keep it simple and i dont have to stop and then send another begin transmission. I just collect all seven at once and then you have to do some manipulation on that, because it doesnt always come back correctly youll notice on the month. I do a modulus command to get it in the format that i want and then were going to create a string called time string and now were going to go through those variables that we collected and were going to create one long string that we can send To the nextion now im going to return that string back to the asynchronous delay and in the next step, well go to the asynchronous delay and collect that string. But what i do is i just if the month is less than 10, then its only going to be one value, and so i add a 0 in front of it, and i do that with for all the values and then for the month and the day I put forward slashes to denote those month day and year and then i put a space after the year and then for the time i put colons so hopefully that thats fairly clear when we read it out and then at the bottom.

I return that string. So this doesnt do anything unless its called so were going to go over to the asynchronous delay and add a line in there. So were going to place this right after we do the uart check and thats that little box. That tells us if we have a connection, so we do a serial two dot print. We have to put that page 0 because its a global variable t3 text, and then we have to put that backslash or escape sequence. Another quote, so we actually send the quote in the string and then im going to collect the rtc, which will, when i run that it will get the the string that we want to send. We have to put another quote after it and then we have to follow it up with those three double fs, so we should be all set to go. The only problem is going to be is if the date isnt set right, and i purposely left the battery out of the real time clock so that we will get a bad date. And then what well have to do is were going to come back here and well have to set the date now like i said, i purposely left the battery out. So when i connected the power to the real time clock it set it to 1, 1 0 and then the time is all zeros. So you can see that its working, because were counting our seconds up, were still getting our temperatures.

But what we have to do is we have to figure out either in the next shin or in the arduino, how to set the time now, for the most part youre going to have a battery in your real time, clock and youre not going to have to Set it very often so for this video im just going to set it up in the arduino and then ill comment. Those lines out when i dont need to set the time so were going to set it right after the int error and what i normally do is i just leave. It commented out so well begin. The transmission with the address just like before well write to the location we want to start at which is 0 and then it automatically increments. So as long as we keep writing data to it, it will write it to location zero. One two three four: five, six and seven, and then after that there are some other things, some alarms you can set but thats beyond the scope of this video. So now i just have to uncomment this and make sure my time is set right. So the date is 5 9 of 2022 and then its 8 ‘ in the morning, the date doesnt matter but thats, just because i cant remember if one is monday or if one is sunday or how it does that so im just gon na leave it at Four for right now now ill upload it and go back to the display.

Now the problem is going to be is once i upload it and go back to the display its going to be set. It will always be at this exact time its going to keep. Writing it over every time it goes through the loop, so you wont see the time change until we come back here comment and then upload it again and there you can see 5 4, 20 22 and its 857 or approximately there. So you can see that it works, but you can see that its also stuck because it keeps writing that over and over and over so im going to go back and set it and then what ill do is im going to upload it again with the correct Time and then im going to upload it again with it commented out, because a couple minutes has gone by since i did this okay. Now you can see that the seconds are counting up and its working. I did do one thing wrong. It appears that i had the minutes going. I thought they were in bcd, but it appears that theyre in decimal so im going to go back and make that change and ill show it to you. So i set it to 23 and it came up 37 and well just send the value. It makes me wonder about all of these. If i needed that or not im going to upload this now there now, the time is correct.

I cant remember right now which way that goes, but i do have an older video, so, if youre concerned with when to use bcd and when not, you can go back to that video. So at this point we have a clock, weve reading our temperatures. We know that the relay is clicking on and off. So i pretty much have a working floor. Mat now, of course, now its the summer and i dont need it anymore, but come next fall, though i should be ready.