Our clock project

Dependencies:   SPI_TFT_ILI9341 TFT_fonts Adafruit_RTCLib RTC-DS1307 TSI

IoT Clock

We have been given a task to design a clock with internet features, the 'Internet Clock'. First of all, we identified what features we want:

Display: Split into 4 parts:

  • Analogue clock - the good ol' fashioned circle display, complete with minute, hour and second hands.
  • Digital clock - equipped with date for the modern human.
  • Weather display - for those who cannot be bothered to look out of the window.
  • Alarm - just what you need when you have to get up or be somewhere.

Wifi module:

  • For collecting data for weather, alarm times and so it can be an 'Internet Clock'.

Speaker:

  • To make the annoying sound to let you know your alarm is going off.

Range finder:

  • To wave your hand in front of to turn the alarm off, because pressing a button is too last centurary.

The roles:

  • Soroush's first task was to get the LCD screen to work. Meanwhile Adam sorted out the speaker system.
  • When these were done, Adam worked on the screen to display a clock face and date/year. Soroush then connected the wifi module to extract data for weather, location and date. /media/uploads/amilner1/img_0285.jpg Connecting the wifi module.
  • The next part was to get the range-finder hooked up and responding to a hand passing, and switch the alarm off.
  • Finally, it was time for assembly.

Difficulties: There were many issues faced throughout the project. First of all, Adam's coding knowledge was a lot less than Soroush's which slowed down some completion of tasks. Although, this did help us sort out the roles. Next was the wifi connectivity which caused several problems during the project, and we couldn't get the connection or fetch data, which further slowed the process. Another difficulty was finding the range-finder's set-up page for mbed. However, when we got past these set backs we managed to put everything together quickly, /media/uploads/amilner1/img_0294.jpg All the hardware wired in.

Outcome:

  • Our LCD screen has 2 displays:
  1. 1 An analogue clock filling the screen.

/media/uploads/amilner1/img_0304.jpg

  1. 2 An analogue clock, date and year, weather and location, and alarm time.

/media/uploads/amilner1/img_0305.jpg

This is changed by holding (not passing quickly) your hand in front of the range-finder.

  • An RTC to keep track of the time rather than collecting the information from then internet. However, we have had a lot of problems setting this up, and it doesn't seem to respond.
  • Wifi is also not connected, so we have the default date, time, weather and location.
  • You are able to change the alarm time by swiping the touch pad on the back.

Perhaps given more time we'd be able to fix these problems. But a key point is that we have got all the other features working, except the correct time. /media/uploads/amilner1/img_0303.jpg

Committer:
sfaghihi
Date:
Wed May 24 10:35:16 2017 +0000
Revision:
12:dd5d8eea2e47
Parent:
11:80a6facfd9f1
Child:
13:334c591a982b
Better non flashing update;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sfaghihi 7:5269fbadd5d7 1 #include "utility.h"
sfaghihi 2:56a27b66d03a 2 #include "Display.h"
sfaghihi 0:07e2cda84b51 3
sfaghihi 7:5269fbadd5d7 4 // Hardware abstractions
sfaghihi 10:e5bcd9088d5d 5 //RawSerial pc_io(USBTX, USBRX);
sfaghihi 8:e7fce7d9ebdd 6 Display screen;
sfaghihi 10:e5bcd9088d5d 7 //DigitalOut led1(LED3);
sfaghihi 7:5269fbadd5d7 8
sfaghihi 7:5269fbadd5d7 9 // The main program global states
sfaghihi 7:5269fbadd5d7 10 StateClass *programState = NULL;
sfaghihi 7:5269fbadd5d7 11 TimeClass *programTime = NULL;
sfaghihi 11:80a6facfd9f1 12 TimeClass *programPrevTime = NULL;
sfaghihi 7:5269fbadd5d7 13 TimeClass *programAlarm = NULL;
sfaghihi 7:5269fbadd5d7 14 DateClass *programDate = NULL;
sfaghihi 7:5269fbadd5d7 15 WeatherClass *programWeather = NULL;
sfaghihi 7:5269fbadd5d7 16
sfaghihi 7:5269fbadd5d7 17 // Timer Interrupt objects
sfaghihi 7:5269fbadd5d7 18 Ticker clockTimer;
sfaghihi 7:5269fbadd5d7 19 Ticker fetchTimer;
sfaghihi 7:5269fbadd5d7 20
sfaghihi 7:5269fbadd5d7 21 // Initialize the states and the hardware
sfaghihi 7:5269fbadd5d7 22 void init_state_hw()
sfaghihi 7:5269fbadd5d7 23 {
sfaghihi 9:c10fb4ac8aa7 24 //pc_io.baud(115200);
sfaghihi 8:e7fce7d9ebdd 25 //LOG("OK");
sfaghihi 7:5269fbadd5d7 26 programTime = new TimeClass(11, 0, 0);
sfaghihi 11:80a6facfd9f1 27 programPrevTime = new TimeClass(11, 0, 0);
sfaghihi 7:5269fbadd5d7 28 programDate = new DateClass(11, 11, 1918, 1);
sfaghihi 7:5269fbadd5d7 29 programWeather = new WeatherClass();
sfaghihi 8:e7fce7d9ebdd 30 //LOG("MOK");
sfaghihi 11:80a6facfd9f1 31 programState = new StateClass(programTime, programPrevTime, programWeather, programDate, programAlarm);
sfaghihi 11:80a6facfd9f1 32 programState->screenState = 0;
sfaghihi 7:5269fbadd5d7 33 }
sfaghihi 7:5269fbadd5d7 34
sfaghihi 8:e7fce7d9ebdd 35 void refresh_and_inc()
sfaghihi 8:e7fce7d9ebdd 36 {
sfaghihi 10:e5bcd9088d5d 37 //led1 = !led1;
sfaghihi 10:e5bcd9088d5d 38 //LOG("In Inc: %f\r\n", programTime->second);
sfaghihi 8:e7fce7d9ebdd 39 // Increment Time
sfaghihi 11:80a6facfd9f1 40 programTime->inc(programPrevTime, REFRESH_PERIOD);
sfaghihi 10:e5bcd9088d5d 41 if (programState->screenState == 0)
sfaghihi 11:80a6facfd9f1 42 screen.drawClock(programTime, false, programPrevTime);
sfaghihi 10:e5bcd9088d5d 43 else if (programState->screenState == 1)
sfaghihi 11:80a6facfd9f1 44 screen.drawClockBig(programTime, false, programPrevTime);
sfaghihi 10:e5bcd9088d5d 45
sfaghihi 11:80a6facfd9f1 46
sfaghihi 8:e7fce7d9ebdd 47 //printf("HAH");
sfaghihi 8:e7fce7d9ebdd 48 //pc_io.printf("After Inc: %d\r\n", programTime->second);
sfaghihi 8:e7fce7d9ebdd 49
sfaghihi 8:e7fce7d9ebdd 50 // Refresh Display
sfaghihi 11:80a6facfd9f1 51 /*if (programState->screenState == 0)
sfaghihi 10:e5bcd9088d5d 52 screen.drawClock(programTime, false);
sfaghihi 10:e5bcd9088d5d 53 else if (programState->screenState == 1)
sfaghihi 11:80a6facfd9f1 54 screen.drawClockBig(programTime, false);*/
sfaghihi 8:e7fce7d9ebdd 55 //screen.drawAll(programState);
sfaghihi 8:e7fce7d9ebdd 56 //LOG ("OUT YEAH!\r\n");
sfaghihi 8:e7fce7d9ebdd 57 }
sfaghihi 8:e7fce7d9ebdd 58
sfaghihi 7:5269fbadd5d7 59 void fetch_data()
sfaghihi 7:5269fbadd5d7 60 {
sfaghihi 8:e7fce7d9ebdd 61 //LOG("Fetch happening\r\n");
sfaghihi 7:5269fbadd5d7 62 // NB Use the wifi module at some point
sfaghihi 10:e5bcd9088d5d 63 programDate->dow = 3;
sfaghihi 10:e5bcd9088d5d 64 programDate->day = 24;
sfaghihi 7:5269fbadd5d7 65 programDate->month = 5;
sfaghihi 7:5269fbadd5d7 66 programDate->year = 2017;
sfaghihi 7:5269fbadd5d7 67 int h = 18, m = 54, s = 0;
sfaghihi 7:5269fbadd5d7 68 if (abs((programTime->hour)*3600+(programTime->minute)*60+(programTime->second)-h*3600-m*60-s) > 180) {
sfaghihi 12:dd5d8eea2e47 69 programPrevTime->hour = programTime->hour;
sfaghihi 12:dd5d8eea2e47 70 programPrevTime->minute = programTime->minute;
sfaghihi 12:dd5d8eea2e47 71 programPrevTime->second = programTime->second;
sfaghihi 7:5269fbadd5d7 72 programTime->hour = h;
sfaghihi 7:5269fbadd5d7 73 programTime->minute = m;
sfaghihi 7:5269fbadd5d7 74 programTime->second = s;
sfaghihi 11:80a6facfd9f1 75 clockTimer.detach();
sfaghihi 11:80a6facfd9f1 76 clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);
sfaghihi 12:dd5d8eea2e47 77 if (programState->screenState == 0)
sfaghihi 12:dd5d8eea2e47 78 screen.drawClock(programTime, true, programPrevTime);
sfaghihi 12:dd5d8eea2e47 79 else if (programState->screenState == 1)
sfaghihi 12:dd5d8eea2e47 80 screen.drawClockBig(programTime, true, programPrevTime);
sfaghihi 7:5269fbadd5d7 81 }
sfaghihi 12:dd5d8eea2e47 82 //screen.drawAll(programState, false);
sfaghihi 8:e7fce7d9ebdd 83 //LOG("Fetch happened\r\n");
sfaghihi 7:5269fbadd5d7 84 }
sfaghihi 0:07e2cda84b51 85
sfaghihi 0:07e2cda84b51 86 // main() runs in its own thread in the OS
sfaghihi 7:5269fbadd5d7 87 int main()
sfaghihi 7:5269fbadd5d7 88 {
sfaghihi 8:e7fce7d9ebdd 89 init_state_hw();
sfaghihi 8:e7fce7d9ebdd 90 //LOG("AFTER\r\n");
sfaghihi 8:e7fce7d9ebdd 91 //printf("OI OI");
sfaghihi 11:80a6facfd9f1 92 screen.drawAll(programState, true);
sfaghihi 10:e5bcd9088d5d 93 //screen.drawDate(programDate);
sfaghihi 7:5269fbadd5d7 94 // Timer initializations
sfaghihi 8:e7fce7d9ebdd 95 clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);
sfaghihi 7:5269fbadd5d7 96 fetchTimer.attach(&fetch_data, 30);
sfaghihi 7:5269fbadd5d7 97
sfaghihi 8:e7fce7d9ebdd 98 //LOG("YAY\r\n");
sfaghihi 7:5269fbadd5d7 99 // Infinite loop
sfaghihi 0:07e2cda84b51 100 while (true) {
sfaghihi 0:07e2cda84b51 101 }
sfaghihi 0:07e2cda84b51 102 }
sfaghihi 0:07e2cda84b51 103