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:
Thu May 25 03:30:05 2017 +0000
Revision:
18:2afeed90c051
Parent:
17:7ba6c8e4945b
Child:
19:450dbcda696e
Maximum features without wifi (or the lack of memory)

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 17:7ba6c8e4945b 3 #include "Wifi.h"
sfaghihi 0:07e2cda84b51 4
sfaghihi 7:5269fbadd5d7 5 // Hardware abstractions
sfaghihi 10:e5bcd9088d5d 6 //RawSerial pc_io(USBTX, USBRX);
sfaghihi 8:e7fce7d9ebdd 7 Display screen;
sfaghihi 17:7ba6c8e4945b 8 Wifi wifi(WIFI_SSID, WIFI_PASS);
sfaghihi 17:7ba6c8e4945b 9 bool wifi_con = false;
sfaghihi 17:7ba6c8e4945b 10 bool alarm_dup = false;
sfaghihi 7:5269fbadd5d7 11
sfaghihi 7:5269fbadd5d7 12 // The main program global states
sfaghihi 7:5269fbadd5d7 13 StateClass *programState = NULL;
sfaghihi 7:5269fbadd5d7 14 TimeClass *programTime = NULL;
sfaghihi 11:80a6facfd9f1 15 TimeClass *programPrevTime = NULL;
sfaghihi 7:5269fbadd5d7 16 TimeClass *programAlarm = NULL;
sfaghihi 7:5269fbadd5d7 17 DateClass *programDate = NULL;
sfaghihi 7:5269fbadd5d7 18 WeatherClass *programWeather = NULL;
sfaghihi 7:5269fbadd5d7 19
sfaghihi 7:5269fbadd5d7 20 // Timer Interrupt objects
sfaghihi 7:5269fbadd5d7 21 Ticker clockTimer;
sfaghihi 7:5269fbadd5d7 22 Ticker fetchTimer;
amilner1 15:452425c099ef 23 Ticker alarmTimer;
sfaghihi 7:5269fbadd5d7 24
sfaghihi 7:5269fbadd5d7 25 // Initialize the states and the hardware
sfaghihi 7:5269fbadd5d7 26 void init_state_hw()
sfaghihi 7:5269fbadd5d7 27 {
sfaghihi 9:c10fb4ac8aa7 28 //pc_io.baud(115200);
sfaghihi 18:2afeed90c051 29 /*if (wifi.connect())
sfaghihi 17:7ba6c8e4945b 30 wifi_con = true;
sfaghihi 17:7ba6c8e4945b 31 else
sfaghihi 18:2afeed90c051 32 LOG("NO");*/
sfaghihi 7:5269fbadd5d7 33 programTime = new TimeClass(11, 0, 0);
sfaghihi 11:80a6facfd9f1 34 programPrevTime = new TimeClass(11, 0, 0);
sfaghihi 7:5269fbadd5d7 35 programDate = new DateClass(11, 11, 1918, 1);
sfaghihi 17:7ba6c8e4945b 36 programAlarm = new TimeClass(9, 0, 0);
sfaghihi 16:a639477091ad 37 programWeather = new WeatherClass(sunny, 18, true, (char *)WEATHER_PLACE);
sfaghihi 8:e7fce7d9ebdd 38 //LOG("MOK");
sfaghihi 11:80a6facfd9f1 39 programState = new StateClass(programTime, programPrevTime, programWeather, programDate, programAlarm);
sfaghihi 11:80a6facfd9f1 40 programState->screenState = 0;
sfaghihi 18:2afeed90c051 41 programState->duringAlarm = true;
sfaghihi 7:5269fbadd5d7 42 }
sfaghihi 7:5269fbadd5d7 43
sfaghihi 8:e7fce7d9ebdd 44 void refresh_and_inc()
sfaghihi 8:e7fce7d9ebdd 45 {
sfaghihi 10:e5bcd9088d5d 46 //led1 = !led1;
sfaghihi 10:e5bcd9088d5d 47 //LOG("In Inc: %f\r\n", programTime->second);
sfaghihi 8:e7fce7d9ebdd 48 // Increment Time
sfaghihi 11:80a6facfd9f1 49 programTime->inc(programPrevTime, REFRESH_PERIOD);
sfaghihi 10:e5bcd9088d5d 50 if (programState->screenState == 0)
sfaghihi 11:80a6facfd9f1 51 screen.drawClock(programTime, false, programPrevTime);
sfaghihi 10:e5bcd9088d5d 52 else if (programState->screenState == 1)
sfaghihi 11:80a6facfd9f1 53 screen.drawClockBig(programTime, false, programPrevTime);
sfaghihi 17:7ba6c8e4945b 54
sfaghihi 17:7ba6c8e4945b 55 if (programTime->hour == programAlarm->hour && programTime->minute == programAlarm->minute) {
sfaghihi 17:7ba6c8e4945b 56 if (!alarm_dup) {
sfaghihi 17:7ba6c8e4945b 57 alarm_dup = true;
sfaghihi 17:7ba6c8e4945b 58 programState->duringAlarm = true;
sfaghihi 17:7ba6c8e4945b 59 playAlarmSound(programState);
sfaghihi 17:7ba6c8e4945b 60 }
sfaghihi 17:7ba6c8e4945b 61 } else
sfaghihi 17:7ba6c8e4945b 62 alarm_dup = false;
sfaghihi 18:2afeed90c051 63
sfaghihi 18:2afeed90c051 64 if (getDistance()) {
sfaghihi 18:2afeed90c051 65 if (programState->duringAlarm)
sfaghihi 17:7ba6c8e4945b 66 programState->duringAlarm = false;
sfaghihi 18:2afeed90c051 67 else {
sfaghihi 18:2afeed90c051 68 programState->screenState = 1 - programState->screenState;
sfaghihi 18:2afeed90c051 69 screen.drawAll(programState, true);
sfaghihi 18:2afeed90c051 70 }
sfaghihi 18:2afeed90c051 71 }
sfaghihi 18:2afeed90c051 72
sfaghihi 8:e7fce7d9ebdd 73 //printf("HAH");
sfaghihi 8:e7fce7d9ebdd 74 //pc_io.printf("After Inc: %d\r\n", programTime->second);
sfaghihi 8:e7fce7d9ebdd 75
sfaghihi 8:e7fce7d9ebdd 76 // Refresh Display
sfaghihi 11:80a6facfd9f1 77 /*if (programState->screenState == 0)
sfaghihi 10:e5bcd9088d5d 78 screen.drawClock(programTime, false);
sfaghihi 10:e5bcd9088d5d 79 else if (programState->screenState == 1)
sfaghihi 11:80a6facfd9f1 80 screen.drawClockBig(programTime, false);*/
sfaghihi 8:e7fce7d9ebdd 81 //screen.drawAll(programState);
sfaghihi 8:e7fce7d9ebdd 82 //LOG ("OUT YEAH!\r\n");
sfaghihi 8:e7fce7d9ebdd 83 }
sfaghihi 8:e7fce7d9ebdd 84
sfaghihi 7:5269fbadd5d7 85 void fetch_data()
sfaghihi 7:5269fbadd5d7 86 {
sfaghihi 8:e7fce7d9ebdd 87 //LOG("Fetch happening\r\n");
sfaghihi 7:5269fbadd5d7 88 // NB Use the wifi module at some point
sfaghihi 17:7ba6c8e4945b 89 if (!wifi_con)
sfaghihi 17:7ba6c8e4945b 90 return;
sfaghihi 18:2afeed90c051 91 char *data = NULL;//wifi.getTimeDate();
sfaghihi 17:7ba6c8e4945b 92 int s, m, h, d, mo, y, dow, t;
sfaghihi 17:7ba6c8e4945b 93 sscanf(data, "%d,%d,%d,%d,%d,%d,%d,%d", &s, &m, &h, &d, &mo, &y, &dow, &t);
sfaghihi 17:7ba6c8e4945b 94 free(data);
sfaghihi 17:7ba6c8e4945b 95 //led1 = 1;
sfaghihi 17:7ba6c8e4945b 96 /*
sfaghihi 13:334c591a982b 97 programWeather->type = cloudy;
sfaghihi 13:334c591a982b 98 programWeather->temp = 10;
sfaghihi 14:85c51b4eff4b 99 programWeather->isCelsius = false;
sfaghihi 16:a639477091ad 100 //programWeather->place = "London";
sfaghihi 13:334c591a982b 101 if (programState->screenState == 0)
sfaghihi 13:334c591a982b 102 screen.drawWeather(programWeather, false);
sfaghihi 17:7ba6c8e4945b 103 */
sfaghihi 17:7ba6c8e4945b 104 if (programWeather->temp != t) {
sfaghihi 17:7ba6c8e4945b 105 programWeather->temp = t;
sfaghihi 17:7ba6c8e4945b 106 screen.drawWeather(programWeather, false);
sfaghihi 17:7ba6c8e4945b 107 }
sfaghihi 17:7ba6c8e4945b 108 //led1 = 0;
sfaghihi 17:7ba6c8e4945b 109
sfaghihi 17:7ba6c8e4945b 110 if (programDate->dow != dow || programDate->day != d || programDate->month != mo || programDate->year != y) {
sfaghihi 17:7ba6c8e4945b 111 programDate->dow = dow;
sfaghihi 17:7ba6c8e4945b 112 programDate->day = d;
sfaghihi 17:7ba6c8e4945b 113 programDate->month = mo;
sfaghihi 17:7ba6c8e4945b 114 programDate->year = y;
sfaghihi 17:7ba6c8e4945b 115 if (programState->screenState == 0)
sfaghihi 17:7ba6c8e4945b 116 screen.drawDate(programDate);
sfaghihi 17:7ba6c8e4945b 117 } else {
sfaghihi 17:7ba6c8e4945b 118 programDate->dow = dow;
sfaghihi 17:7ba6c8e4945b 119 programDate->day = d;
sfaghihi 17:7ba6c8e4945b 120 programDate->month = mo;
sfaghihi 17:7ba6c8e4945b 121 programDate->year = y;
sfaghihi 17:7ba6c8e4945b 122 }
sfaghihi 7:5269fbadd5d7 123 if (abs((programTime->hour)*3600+(programTime->minute)*60+(programTime->second)-h*3600-m*60-s) > 180) {
sfaghihi 12:dd5d8eea2e47 124 programPrevTime->hour = programTime->hour;
sfaghihi 12:dd5d8eea2e47 125 programPrevTime->minute = programTime->minute;
sfaghihi 12:dd5d8eea2e47 126 programPrevTime->second = programTime->second;
sfaghihi 7:5269fbadd5d7 127 programTime->hour = h;
sfaghihi 7:5269fbadd5d7 128 programTime->minute = m;
sfaghihi 7:5269fbadd5d7 129 programTime->second = s;
sfaghihi 11:80a6facfd9f1 130 clockTimer.detach();
sfaghihi 11:80a6facfd9f1 131 clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);
sfaghihi 12:dd5d8eea2e47 132 if (programState->screenState == 0)
sfaghihi 12:dd5d8eea2e47 133 screen.drawClock(programTime, true, programPrevTime);
sfaghihi 12:dd5d8eea2e47 134 else if (programState->screenState == 1)
sfaghihi 12:dd5d8eea2e47 135 screen.drawClockBig(programTime, true, programPrevTime);
sfaghihi 7:5269fbadd5d7 136 }
sfaghihi 13:334c591a982b 137
sfaghihi 12:dd5d8eea2e47 138 //screen.drawAll(programState, false);
sfaghihi 8:e7fce7d9ebdd 139 //LOG("Fetch happened\r\n");
sfaghihi 7:5269fbadd5d7 140 }
sfaghihi 0:07e2cda84b51 141
amilner1 15:452425c099ef 142 void stopAlarm()
amilner1 15:452425c099ef 143 {
amilner1 15:452425c099ef 144 programState->duringAlarm = false;
sfaghihi 17:7ba6c8e4945b 145 alarmTimer.detach();
amilner1 15:452425c099ef 146 }
amilner1 15:452425c099ef 147
sfaghihi 0:07e2cda84b51 148 // main() runs in its own thread in the OS
sfaghihi 7:5269fbadd5d7 149 int main()
sfaghihi 7:5269fbadd5d7 150 {
sfaghihi 8:e7fce7d9ebdd 151 init_state_hw();
sfaghihi 8:e7fce7d9ebdd 152 //LOG("AFTER\r\n");
sfaghihi 8:e7fce7d9ebdd 153 //printf("OI OI");
sfaghihi 17:7ba6c8e4945b 154
sfaghihi 11:80a6facfd9f1 155 screen.drawAll(programState, true);
sfaghihi 17:7ba6c8e4945b 156
sfaghihi 10:e5bcd9088d5d 157 //screen.drawDate(programDate);
sfaghihi 7:5269fbadd5d7 158 // Timer initializations
sfaghihi 17:7ba6c8e4945b 159
sfaghihi 8:e7fce7d9ebdd 160 clockTimer.attach(&refresh_and_inc, REFRESH_PERIOD);
sfaghihi 17:7ba6c8e4945b 161 fetchTimer.attach(&fetch_data, FETCH_PERIOD);
amilner1 15:452425c099ef 162 alarmTimer.attach(&stopAlarm, 40);
sfaghihi 17:7ba6c8e4945b 163
sfaghihi 18:2afeed90c051 164 playAlarmSound(programState);
sfaghihi 8:e7fce7d9ebdd 165 //LOG("YAY\r\n");
sfaghihi 7:5269fbadd5d7 166 // Infinite loop
sfaghihi 0:07e2cda84b51 167 while (true) {
sfaghihi 0:07e2cda84b51 168 }
sfaghihi 0:07e2cda84b51 169 }
sfaghihi 0:07e2cda84b51 170