LCD DATE/CLOCK Forget the RTC

by oldmaninSC in Circuits > Arduino

1094 Views, 5 Favorites, 0 Comments

LCD DATE/CLOCK Forget the RTC

open photo.jpg

A NIST 2010 quantum logic clock based on a single aluminum ion .

In 2010 an experiment placed two aluminum-ion quantum clocks close to each other, but with the second elevated 12 in (30.5 cm) compared to the first, making the gravitational time dilation effect visible in everyday lab scales. Thus reproving Einstein's gravity theories. The clocks were reversed in positions and showed the same time offsets. NIST postdoctoral researcher James Chin-wen Chou with the worlds most precise clock, based on the vibrations of a single aluminum ion (electrically charged atom). The ion is trapped inside the metal cylinder (center right). He says 'off by 1 sec in 3.7 Billion years' ...lets wait and see!

SUPER DUPER WOW.

So by using quantum vibrations which is really fast, you think faster is better. The 328 chip in Unos is sorta fast at 16mhz. That is far faster than the typical clock (watch) crystal that is 32.768 khz. That is 500 times faster ! And the 328 has a temperature sensor to compensate the clock.

So why can't the 328 out preform a cheep watch crystal?

WHAT TO EXPECT

IMG_20191127_152619-800x600.jpg

This is my second attempt to make a clock using ONLY the 328 chip. Each 328 runs at different times even though they have a 16mhz crystal. So you get poor results just counting millis(). Which runs at 1,000 hz. This makes ONE millis(1) average out to about +- 3.6 seconds per hour accurate. Arduino mills() dosen't count factional mills or use floats. This makes counting fractions of a mill impossible. So using Arduino micros() is the next choice. But using micros() runs out in just 71 minutes. (this really is NOT a problem). The problem for me is dealing with the large numbers and making repeated adjustments based on gps clocked time. Another choice is an interrupt. This counts the seconds no matter where the code is running inside the loop. This makes the 328 as good as a RTC. Even if the specks of the 'micros()' are considered, at +- 4 uS, this works out to be a 250khz clock. That is 7 times better than the 32.768khz.

So here is my Arduino lcd clock based on a 16bit timerOne interrupts using microseconds. It is not quite as good as counting aluminum ions! But it is easy and with some calibrations it can be as good as a RTC. I have made 3 versions of this clock. From connect to computer usb. To stand alone with 4 buttons. To outside gps with temperature using a HC12. This instructable will cover the first 2 clocks and I will write another 'in depth' for the HC12.

See my other instructable on HC12 range problems.

What you can expect is an easy lcd clock/date using UNO and a 16x2 lcd. I made some custom numbers for the lcd. The 'BIG numbers' library take up 3 spaces, mine just 1. The 4 button have internal pull up so the build is easy. I have a case for this and a 2 lcd and backs.

The public library here in my small town has a 3d printer anyone can use. So check out a library near you for making the lcd case.

My tests show -+ second every 24-48 hours. That is about one minute off in two months. Three or four adjustments put the clock spot on. Only off by about 12 seconds pre MONTH. Repeated attempts to 'calibrate' seams to just be chasing numbers. The one BAD feature is using ANY 'menu' resets the seconds to 00. This changes the current time. I did leave a 60sec timeout for the button press as to allow for synk with another clock.

THE NUTS AND BOLTS

IMG_20191127_155112-800x600.jpg
IMG_20191127_155223-800x600.jpg
IMG_20191127_154511-800x600.jpg
IMG_20191127_155213-800x600.jpg

This project is a STAND ALONE clock without RTC just a uno and lcd. The 4 buttons allow time/date set and adjust time zone and calibrate.

The 3d printer files have a one and two lcd case for other projects.

The lcd has BIG NUMBERS that take up only ONE space wide. This took me quite some time to do

The case has 8 holes for buttons for other projects.

Just connect a 5v wall wart for power.

Check your local LIBRARY for use of a 3d printer !!

ABOUT THE BUILD

IMG_20191127_153558-800x600.jpg
IMG_20191127_153515-800x600.jpg
IMG_20191127_153151-600x800.jpg

Any Arduino boards with MEGA 328 micros should work. It needs a 16mhz crystal and must be running at that speed. A 3.3 volt at 8mhz may not work with the interrupt timing. For the enclosure case a pro-mini fits best but you may squeeze a nano in but the usb cable may be a problem. This is a Hitachi 16x2 lcd, very popular. Some cheep ones are DULL and just faint. An edge connector is needed to fit a popular I2c converter module. Only 4 wires are needed to hook up to the uno. There are many tutorials to show how to hook up the lcd without a converter module if you do not want one. For the no button clock that is all you do.

The lcd has a BIG NUMBER custom char. The big numbers take up only ONE width.

4 BUTTONS and CASE

IMG_20191127_153838-800x600.jpg
IMG_20191127_153900-800x600.jpg
IMG_20191127_153917-800x600.jpg
IMG_20191127_154117-800x600.jpg
IMG_20191127_154137-800x600.jpg
IMG_20191127_154329-800x600.jpg
IMG_20191127_154402-800x600.jpg
IMG_20191127_154408-800x600.jpg
IMG_20191127_152653-600x800.jpg

The same as above but add the 4 switches. A standard pc board 2inch x 2.5 inch is used to fit the case. Just cut in half and install the switches so the legs go left to right. If you put the switches with legs up the holes will not line up in the case. Test that they line up to the case holes BEFORE soldering. Ground the bottom legs (all) and run each top leg to a pin on the uno. See enclosed schematic. If you 3d print the case, the button part needs to be GLUED to the lcd case. It does NOT snap in like the back does. Any small self taping screws will hold the lcd in place. TOO big and you will crack the case. Hot glue stick may be the best. Before mounting the lcd...blacken the led area with black tape. Otherwise it will shine through the case. I use 2 side foam tape in 2 layers for mounting the pro mini. This tape is a bargain at 'dollar tree stores'. I use solid coated magnet wire about 26 gauge. I have a great instructable on 'a poor mans solder pot' for using this wire in hookups.

THE LCD

IMG_20191127_153339-800x600.jpg
IMG_20191127_152901-800x600.jpg
IMG_20191127_153249-800x600.jpg
IMG_20191127_153351-800x600.jpg
IMG_20191127_153240-800x600.jpg

lcd problems

Once finished with the build, download and install the sketch. The lcd may not light up the display. Here are some tips. The lcd 'led' should be lit and make the screen bluish. If no led check the jumper pins opposite the resistor pot. This needs the jumper or 150 ohm resistor. The blue pot is always the problem. So turn the pot till the display shows 2 rows of squares. Then back off just until the squares barely fade out. If still no display, Check the SDA and SCL connections. Too easy to get them backwards. That is A4 to SDA and A5 to SCL. These are A pins not D pins and some pro minis have these pins on the inside of the pc not on the edges. The last option is to check the address. Some lcd converter modules have different addresses. Or in using more than one device the all need different addresses. Most modules have 3 solder pins to set up 3 different addresses. Remember the I2c only runs 2 wires to any and ALL devices. So each device MUST have a unique address. Included is an I2c address scanner. Download the scanner install and read the serial monitor. The display shows the address for ANY I2c device. Check The clock sketch for the line at the top of the sketch. 'LiquidCrystal_I2C lcd(0x3F,16,2); ' 0x3F is the correct address for my converter. If your address differs, change to the correct one from the scanner. Caution: copy and paste the new address sometimes includes end of line or carriage returns. Just TYPE in the other address. The first letters are always zero and small case x 0x. This tells C++ that it is a hex. After 0x any letter is upper case.

HOOKUPS

IMG_20191127_162110-600x800.jpg
IMG_20191127_152743-800x600.jpg
IMG_20191127_154426-800x600.jpg
IMG_20191127_154437-800x600.jpg
IMG_20191127_155151-800x600.jpg

follow the schematic and wire the unit.

OTHER PHOTOS

IMG_20191127_155123-800x600.jpg
IMG_20191127_152614-800x600.jpg
IMG_20191127_152610-800x600.jpg
IMG_20191127_152605-800x600.jpg
IMG_20191127_163025-800x600.jpg
IMG_20191127_163037-800x600.jpg

good luck PLEASE see my other instructables

THE SKETCH

instructables won't let me download a Arduino file !!!! so I used text. You will have to copy and paste the text into a NEW arduino open file at the IDE.......SORRY

and the text files wont load either !!! and tried to paste here but jumbled it up !!

finally !!! got my sketch to download here. 3-26-2020 Fixed some minor things too.

The people who get paid to write code are rolling on the floor when they see my code. My sketches usually start out simple. Then I add more things to do. So the sketch gets twisted into a mess. I hope you learn from my two biggest mistakes. There should be a defined outline and goal at the start. Not add tons of stuff throughout the sketch. My worst mistake is to misuse a FUNCTION. It should be brief and return a sum, and used only when it replaces repeated lines of code throughout the sketch. delay(100) is a good example.

My use of a FUNCTION is to separate sections of the sketch. This leaves the main body easy for me to follow as well as allowing to debug separate sections just by calling the function. I think that GOTO used to do this but it has fallen from favor and NEVER gets used. Nuff said. I checked the dates and times as best as I can. The same parts of the sketch runs my 'TIME SQUARED' clocks for years. If I missed something or there is a bug please let me know. To calibrate the 'no buttons sketch' the line with 'unsigned long tSec = 1000122; ' (line 34) is what you change. The constant of 277 per second per hour is correct. But in practice I make only 2 to 8 amount changes to 'tSec' value. At 1000122 many of my clocks ran as good as a RTC. Be patient a small change of only 2-8 can become a perfect clock. The down side of any changes for either clock means that the current time WILL be altered. You will need to change to the correct current time/date.

//
// easy_one_lcd_clock_no_buttons // // arduino and lcd clock // use timerOne 16 bit timer // to calibrate this clock: // use a good seconds clock like a GPS. // use hours as baseline. Count seconds // THIS is off. If THIS is behind a GPS // GPS=00..THIS=58 SUBTRACT 277 for each // second/hours. So if slower by 2 sec in // 3 hours... (277 * 2)/3 = 184 // SUBTRACT from tSec. // if THIS is ahead GPS=00...THIS=03 // same math just ADD to tSec. // cauction, most clocks correct at 00. // 20 sec is a better timer check.

CASE STL Files

Here are the 3d printer case files. The keypad needs to be glued to the lcd case. The back snaps unto both the one and two lcd case front. Snap the top in first then work your way down to get a nice fit.

CHECH OUT your local LIBRARY for the use of a 3d printer.