Friday, May 15, 2015

Arduino Analog clock with DS1307

arduino_my_name_analogclock.png

Another experiment with Arduino based on experiment with TFT 240×320 display using driver chip ILI9341 and DS1307 real time clock module.

Turn out this can be a nice analog-clock on my desk to replace the widget analog-clock of windows 7.

Update 13/Oct/2016

Analog Clock v2.4

ds1307analogclock2.4.jpg

Changes:
- Use DS3231 - extreme precise does not effect by temperature like DS1307
- Clockface with date/time inside

Version 2.3

ds1307analogclockfinish.jpg
ds1307analogclockfinish2.jpg
ds1307analogclockfinishinside.jpg

Behind the scene

ds1307clockface.jpg
ds1307clockface-backpack.jpg

The circuit

ds1307schema.png

This Analog clock uses precision RTC DS1307 for time keeping and uses arduino-pro-mini clone to read the time from DS1307 and displays it on the TFT screen as Analog clock.

When using arduino Uno, you can power DS1307 RTC module directly with IO pins using A2 sink to GND, and A3 pull up to Vcc and connect the TFT display through a 5v to 3v3 level shifter module.

ds1307ontherun.jpg

Time update on PC code:

ds1307timeupdateconsole.png

If you use ArduinoPro mini (clone) like mine, you have to use a USB / Serial adaptor like this. [S]You should not connect DTR pin because PL2303 acts weird sometime, and send DTR signal before everytime data is sent from PC. And thus it makes ArduinoPro mini restart when PC app scan the com port[/S]. Actually I got mix up between output pin and input pin of AMS1117, but somehow LCD works even it was almost 4v. After fixing, arduinoPro mini no longer restart when scanning com port.

The code consists of two part:
- Code for Arduino: Read time and draw a clock, receive time from serial connection (Com port)
- Code from PC: Auto scan from COM1 to COM16 and send time to Arduino if Analog Clock is found

[INDENT][attach=download/Arduino-AnalogClock2.5.zip]AnalogClock version 2.5[/attach]
[attach=download/Arduino-AnalogClock2.4.zip]AnalogClock version 2.4[/attach]
[attach=download/Arduino-AnalogClock2.31.zip]AnalogClock version 2.3.1[/attach]
[attach=download/Arduino-AnalogClock1.0.zip]AnalogClock version 1.0[/attach]
[/INDENT]

Libraries and tool:

[INDENT]- Adafruit_ILI9341 and Adafruit_GFX
[attach=download/java-Image2Code.rar]java-Image2Code.rar[/attach] or here
[attach=download/arduino-lib-DS1307RTC.rar]arduino-lib-DS1307RTC.rar[/attach]
[attach=download/arduino-lib-Time.rar]arduino-lib-Time.rar[/attach][/INDENT]
[tag]DS1307, Arduino[/tag]

  1. Kenjutsu

    Monday, August 3, 2015 at 20:00:13

    Awesome! Which version of the Adafruit_GFX library are you using?

  2. ceez

    at 20:15:57

    The old version, which doesn’t support class Adafruit_GFX_Button.

    But the newest update of Adafruit_GFX library should work without problem since they just add new class Adafruit_GFX_Button to the library without making changes to the existing code.

  3. Kenjutsu

    at 21:47:49

    Thank you for the reply. One more question, are you using a custom version of Adafruit_ILI9341?

  4. ceez

    at 21:56:10

    Nope :)

  5. Kenjutsu

    at 22:18:43

    Thank you for the reply. The reason I asked was because of this line:

    Adafruit_ILI9341 tft = Adafruit_ILI9341();

    There does not seem to be a default/empty constructor in Adafruit_ILI9341, but by passing the correct pins to one of the overloaded constructors, it does compile :-)

  6. ceez

    at 22:44:19

    I don’t know, maybe my version is very old which I still use since Arduino IDE 1.0

    Yes, it should work.

    [code]#define SCLK 13 // Don’t change
    #define MOSI 11 // Don’t change
    #define MISO 12 // Don’t change
    #define CS 10
    #define DC 9
    #define RST -1 // connect to Reset of arduino or 3v3

    Adafruit_ILI9341(CS, DC, MOSI, SCLK, RST, MISO);[/code]

    I am too lazy to update these libraries when it still works :D

  7. Donald Fischer

    Friday, May 20, 2016 at 01:54:48

    I am really impressed with this and trying to use in a larger project… I am just learning the programming (thru trial and error) and wonder if you could point me in the write direction..

    exit status 1
    no matching function for call to ‘Adafruit_ILI9341::Adafruit_ILI9341()

  8. ceez

    at 19:21:39

    Same thing was asked by Kenjutsu.

    I updated the sketch to use with official adafruit library.

    Or you can modify the source code:

    From line 135, add these line:
    [CODE]#define SCLK 13 // Don’t change
    #define MOSI 11 // Don’t change
    #define MISO 12 // Don’t change
    #define CS 10
    #define DC 9
    #define RST -1 // connect to Reset of arduino or 3v3

    Adafruit_ILI9341 tft = Adafruit_ILI9341(CS, DC, MOSI, SCLK, RST, MISO); // Invoke standard library from adafruit
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(); // Invoke custom library[/CODE]

  9. Donald Fischer

    Sunday, May 22, 2016 at 07:36:34

    I hope you can help… I am getting this error… The file is there

    SDKDDKVer.h: No such file or directory

    #include <SDKDDKVer.h>

  10. ceez

    at 08:03:09

    Remove that line. It serves no purpose since this is not a driver but a simple console app. The WinSDK on my PC automatically put that line there.

  11. Fish

    at 09:26:49

    I saved as and it worked.. Thx

  12. faruk

    Sunday, June 5, 2016 at 13:32:52

    fatal error: struct.h: No such file or directory
    i get this error :(

  13. ceez

    at 18:26:36

    Extract the whole thing to a folder. Don’t run it inside a zip file.

  14. Daniel Fernandes

    Saturday, July 9, 2016 at 04:11:38

    Greetings Ceez!

    The sketc that is giving the error is “AnalogClock version 1.0” (not AnalogClock2.31)
    Error: no matching function for call to ‘Adafruit_ILI9341 :: Adafruit_ILI9341 ()’

    What should be corrected? Thank you

  15. ceez

    at 15:27:48

    Solution in comment #8

  16. Daniel Fernandes

    Saturday, August 27, 2016 at 09:05:49

    Hi friend! The code is loading normally but appears multiple clock faces on display, overlapping each other; What can it be? Thank you

  17. ceez

    at 15:39:47

    It happens because of the mechanism use to update clock face.

    In short, after about 0.9 second, it draws black hands overlap on old time (second changes or minute changes) in order to erase old clock hands, this way much faster than fill a circle or rectangle with black. After *erase* old hands, draw new color hands that reflect of new time. Since timing of the MCU (microcontroller) doesn’t match with RTC or else we don’t need RTC module, you will experience it ticks 2 seconds sometime. It happens because update interval of MCU is larger than 1 second. You can change it shorter than 1s and see the result.

    By small chance, old time is not the same as old time which has been drawn on clock face. Thus black hands were drawn on different position and so old hands are not erased.

    The way I store old time in code, in order to redraw black hands overlap, is not optimised. It just quick and dirty way to make the code works. So, bugs expected. I think it is a little bit better in version 2.3, but I still experience that bug once a day if I leave it powered on 24/7.

    Since I connect it to my PC and let it on and off with PC, that bug doesn’t show up in time frame 5-6 hours.

    So, to eliminate that bug. You should use square wave out put from DS1307 module to trigger time update instead of using sleep(900). Use code like button, check if button is high or low. Otherwise, you can use interrupt like pin change as trigger as well. Oh, and fix the code I use to store old time for erase old hands.

    Cheer!

Add comment

Fill out the form below to add your own comments