Introduction: Alarm Clock With Evive (Arduino Powered Embedded Platform)

We want to make a combined analog and digital alarm clock. Real Time Clock is essential for clock to keep the time even if it is turned off. But commonly available micro-controller boards like Arduino or Raspberry Pi do not have a real time clock. However in evive, there is an inbuilt RTC (Real Time Clock). evive also has 1.8" TFT screen and few switches and potentiometers, so that we do not require any additional electronic components. evive uses IC PCF8563 for real time clock feature.

http://www.nxp.com/documents/data_sheet/PCF8563.pd...

The IC needs a battery source for fluent running of time. As per datasheet, the clock operating voltage of RTC is 1.0 V to 5.5 V. There is inbuilt Li-ion 3.7V battery in evive so you need not worry for this. Using this we have made an analog clock which has an alarm. For this Piezo buzzer is used which is also inbuilt in evive.

There are lots of features for such DIY projects. You can explore them at:
evive.cc/files/evive_specifications.pdf

Component used is only evive!

Step 1: Setting Time and Printing It to Serial Monitor Using PCF8563 IC in Evive

The PCF8563 communicates using 400 kHz two-wire I2C-bus interface. You can read about I2C (or IIC) at

https://learn.sparkfun.com/tutorials/i2c

All I2C based devices have a device ID. PCF8563 IC has device ID: 0x51. For more information on registor, read section 8 in datasheet. You can use arduino library for this RTC, which can be downloaded from:
http://playground.arduino.cc/Main/RTC-PCF8563
But we do not use this library as just a function can be made to implement this. Now we will explain the code to set and read time.

  • Once during start of your project, you have to set the right time in RTC. It will store time till it is connected to the battery. For this you have to change the time and date using the function setPCF8563(). You have to change the second, minute, hour, dayOfWeek, dayOfMonth, month, year (only last two digits) in setup(). Just upload the edited code on evive and open the Serial Monitor. The correct time and date will be displayed and updated every second.
  • Remember to comment out the function setPCF8563() to avoid resetting the clock next time you upload.
  • The function readPCF8563() reads the time via I2C bus. This function updates the values of global variables: second, minute, hour, dayOfWeek, dayOfMonth, month, year. The day of week is set as 0 for sunday, 1 for monday and so on. The clock format is 24 hours. The loop() reads and prints data on serial every second.

Step 2: Making the Analog Clock on TFT

Now we have access to time and we just want to show it in a better way on TFT screen.

evive uses ST7735 SPI 1.8" colored TFT screen and the library for this screen is available on adafruit. This is a hardware level library. You can download the library from github https://github.com/adafruit/Adafruit-ST7735-Librar...

Also we need a graphics library, which can draw basic shapes like circles, lines etc and characters using the ST7735 library. It can be downloaded from https://github.com/adafruit/Adafruit-GFX-Library .

Now we will draw the clock and update it at every second:

  • For the dial, first make a circle having center as the center of screen and then the 12 hour markers in setup because you don't want to change these in the whole program.
  • At every second, calculate the angle that each hand moves in one second. Draw hands with background color so as to erase previous clock readings and then draw the three hands: hour, minute and second according to current angles.
  • If you want to print the date and day of week, print it by setting the cursor using the function object.setCursor(x-coordinate ,y-coordinate) and write text using the function tft.print(text).
  • You can view other TFT functions and read more about the library in the pdf: https://cdn-learn.adafruit.com/downloads/pdf/adafr...
  • Now if you want to print the digital clock at the same time then you can do it similarly.

Here is the complete documented code

Step 3: Adding the Alarm

Now we have made the clock which shows us time in both analog and digital form along with date and day. For alarm clock, you need to first add the alarm hand. Draw the alarm hand with say yellow color same as done previously and control it using the potentiometer already inbuilt in evive. The potentiometers are connected to the analog pins A9 and A10. In this project we have used A9 pin. Set the alarm time using this potentiometer. The analog values from 0 to 1023 are mapped to -2*PI to 0 radians which corresponds to 6 o'clock to 5:59 in clockwise sense (see lines 223-228). Now you need to set the alarm, which can be controlled by any of the slide switches in evive which are connected to 40, 41, 42 and 43. We have used the switch which sets the alarm 'on' when digital pin 40 is high. The alarm tone is preloaded and can be played using the inbuilt Piezo buzzer.
The alarm is triggered if the hour hand and alarm hand are too close (say 0.05 radians) and the tone will be played for a pre-set time till the user switches 'off' the alarm switch.

Step 4: Extra Feature: Alarm Icon on the Display

Now we want to put an alarm symbol to show whether alarm is on or off. For this you have to convert a 'bmp' file into hexadecimal format which can be stored in flash memory of arduino. For this, we have used the Bitmap to HEX converter, which can be download from https://sourceforge.net/projects/lcd-image-convert... . See the settings for Monochrome image with inverted image option so that 'bell' shape can be colored as per your choice. Sample bitmap image is attached and the hex code for bell icon is:

// Bell icon size: 16W*16H
const unsigned char bell [] PROGMEM = { 0x01, 0x80, 0x03, 0xc0, 0x0f, 0xf0, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x7f, 0xfe, 0x7f, 0xfe, 0xc3, 0xc3, 0xc3, 0xc3, 0x3f, 0xfc, };

Note that the array has data type const unsigned char bell [ ] PROGMEM. Here PROGMEM means that the image data is stored in arduino flash (program) memory.

If you want to change the sign of alarm you can change this using the converter but ensure that the size of code should not exceed the limits of arduino mega and image size is edited in drawBitmap(posX, posY, varName, imageSizeX, imageSizeY, color). The icon will only be shown when the alarm switch is 'on'.

A very detailed instructable for this stuff can be explored here.

Step 5: Conclusion

Using evive, the clock was very easily made as we do not require any additional hardware and hence can focus on programming. You can switch 'off' evive, but still the RTC will run using the internal battery and hence when you switch it 'on' at a later time, it will display the right time!

Some segment of codes are used from: http://tronixstuff.com/2013/08/13/tutorial-arduino-and-pcf8563-real-time-clock-ic/

More fun: To wake you up, you can set the alarm and add additional codes to control a motor directly using evive's hardware plug and play interface, which can be used to open curtains!

Explore more about evive projects here.

evive product video can be found here.

Comments

author
tomatoskins made it! (author)2016-05-31

I've never heard of Evive, but it looks awesome!

author
evivetoolkit made it! (author)evivetoolkit2016-08-04

Hi
Now evive is launched, @tamatoskins have a look at http://igg.me/at/evive.
Surely it will be very interesting to you :)

cover.jpg
author
evivetoolkit made it! (author)evivetoolkit2016-06-09

evive is a one stop learning, building and debugging solution for makers. It'll be launched on Indiegogo very soon. You can visit http://evive.cc for details and subscribe to get notified of the launch.

About This Instructable

581views

5favorites

License:

Bio: evive is an open-source embedded platform for all age groups and profession to help them learn, build, debug their robotics, embedded and other projects. With ... More »
More by evivetoolkit:Tweet using Arduino, ESP and KeypadSmartphone controlled Electric Skateboard with eviveLine follower robot using a smart phone
Add instructable to: