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:
Tue May 23 23:28:27 2017 +0000
Revision:
8:e7fce7d9ebdd
Parent:
7:5269fbadd5d7
Child:
9:c10fb4ac8aa7
Non working( it worked 20 mins ago :'(

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