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:
Fri May 26 11:14:53 2017 +0000
Revision:
20:e8ff6955c24e
Parent:
19:450dbcda696e
sfsdfd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amilner1 5:fe6910712822 1 #include "utility.h"
amilner1 5:fe6910712822 2
amilner1 5:fe6910712822 3
sfaghihi 8:e7fce7d9ebdd 4 TimeClass::TimeClass (int h, int m, float s)
sfaghihi 7:5269fbadd5d7 5 : hour(h), minute(m), second(s) {}
sfaghihi 7:5269fbadd5d7 6
sfaghihi 11:80a6facfd9f1 7 void TimeClass::inc(TimeClass *prev, float i) {
sfaghihi 11:80a6facfd9f1 8 prev->second = this->second;
sfaghihi 11:80a6facfd9f1 9 prev->minute = this->minute;
sfaghihi 11:80a6facfd9f1 10 prev->hour = this->hour;
sfaghihi 11:80a6facfd9f1 11 this->second += i;
sfaghihi 11:80a6facfd9f1 12 if (this->second >= 60) {
sfaghihi 11:80a6facfd9f1 13 this->second = 0;
sfaghihi 11:80a6facfd9f1 14 this->minute += 1;
sfaghihi 8:e7fce7d9ebdd 15 }
sfaghihi 7:5269fbadd5d7 16
sfaghihi 11:80a6facfd9f1 17 if (this->minute == 60) {
sfaghihi 11:80a6facfd9f1 18 this->minute = 0;
sfaghihi 11:80a6facfd9f1 19 this->hour += 1;
sfaghihi 7:5269fbadd5d7 20 }
sfaghihi 7:5269fbadd5d7 21
sfaghihi 11:80a6facfd9f1 22 if (this->hour == 24)
sfaghihi 11:80a6facfd9f1 23 this->hour = 0;
sfaghihi 7:5269fbadd5d7 24 }
amilner1 5:fe6910712822 25
amilner1 5:fe6910712822 26 DateClass::DateClass(int d, int m, int y, int dow)
sfaghihi 7:5269fbadd5d7 27 : day(d), month(m), year(y), dow(dow) {}
amilner1 5:fe6910712822 28
amilner1 15:452425c099ef 29 WeatherClass::WeatherClass(weatherType t, int tmp, bool cel, char *p)
sfaghihi 13:334c591a982b 30 : type(t), temp(tmp), isCelsius(cel), place(p) {}
sfaghihi 7:5269fbadd5d7 31
sfaghihi 11:80a6facfd9f1 32 StateClass::StateClass(TimeClass *t, TimeClass *p, WeatherClass *w, DateClass *d, TimeClass *a)
amilner1 15:452425c099ef 33 : time(t), prevTime(p), weather(w), date(d), alarm(a), screenState(0), screenActive(true), duringAlarm(false) {}
amilner1 15:452425c099ef 34
amilner1 15:452425c099ef 35
sfaghihi 20:e8ff6955c24e 36 extern StateClass *programState;
sfaghihi 20:e8ff6955c24e 37
sfaghihi 20:e8ff6955c24e 38 void playAlarmSound()
amilner1 15:452425c099ef 39 {
amilner1 15:452425c099ef 40 PwmOut speaker(ALARM_PIN); // alarm sound of regular beeps
sfaghihi 20:e8ff6955c24e 41 while (programState->duringAlarm) {
amilner1 15:452425c099ef 42 speaker.period(1.0/150.0); // 150hz period
amilner1 15:452425c099ef 43 speaker =0.0125;
amilner1 15:452425c099ef 44 wait(0.5);
amilner1 15:452425c099ef 45 speaker=0.0; // turn off audio
amilner1 15:452425c099ef 46 wait(0.5);
amilner1 15:452425c099ef 47 }
sfaghihi 17:7ba6c8e4945b 48 }
sfaghihi 17:7ba6c8e4945b 49
sfaghihi 19:450dbcda696e 50 AnalogIn ain(RANGE_AN);
sfaghihi 19:450dbcda696e 51 DigitalOut cs(RANGE_CS, 0);
sfaghihi 18:2afeed90c051 52
sfaghihi 17:7ba6c8e4945b 53 bool getDistance()
sfaghihi 17:7ba6c8e4945b 54 {
sfaghihi 18:2afeed90c051 55 float adc, volts, inches;
sfaghihi 18:2afeed90c051 56 cs = 1;
sfaghihi 18:2afeed90c051 57 wait_us(30);
sfaghihi 18:2afeed90c051 58 adc = ain.read(); // read analog as a float
sfaghihi 20:e8ff6955c24e 59 volts = adc * 3.3; // convert to volts
sfaghihi 20:e8ff6955c24e 60 inches = volts / 0.0064;
sfaghihi 19:450dbcda696e 61 cs = 0;
sfaghihi 18:2afeed90c051 62 return inches <= RANGE_THRESHOLD;
sfaghihi 19:450dbcda696e 63 }
sfaghihi 19:450dbcda696e 64
sfaghihi 20:e8ff6955c24e 65 //I2C master(RTC_SDA, RTC_SCL);
sfaghihi 20:e8ff6955c24e 66 Rtc_Ds1307 rtc(RTC_SDA, RTC_SCL);
sfaghihi 19:450dbcda696e 67 void read_rtc(StateClass *ps)
sfaghihi 19:450dbcda696e 68 {
sfaghihi 20:e8ff6955c24e 69 Rtc_Ds1307::Time_rtc data;
sfaghihi 20:e8ff6955c24e 70 //rtc.twentyfour_hour();
sfaghihi 19:450dbcda696e 71 LOG("IN RTC\r\n");
sfaghihi 20:e8ff6955c24e 72 int s = 0, m = 0, h = 0, dow = 0, d = 0, mo = 0, y = 0;
sfaghihi 20:e8ff6955c24e 73 //rtc.gettime(&s, &m, &h, &dow, &d, &mo, &y);
sfaghihi 20:e8ff6955c24e 74 rtc.getTime(data);
sfaghihi 20:e8ff6955c24e 75 h = data.hour;
sfaghihi 20:e8ff6955c24e 76 m = data.min;
sfaghihi 20:e8ff6955c24e 77 s = data.sec;
sfaghihi 20:e8ff6955c24e 78 dow = data.wday - 1;
sfaghihi 20:e8ff6955c24e 79 d = data.date;
sfaghihi 20:e8ff6955c24e 80 mo = data.mon;
sfaghihi 20:e8ff6955c24e 81 y = data.year;
sfaghihi 20:e8ff6955c24e 82 LOG("%d:%d:%d", h, m, s);
sfaghihi 20:e8ff6955c24e 83 //if (!rtc.isRunning())
sfaghihi 20:e8ff6955c24e 84 // return;
sfaghihi 20:e8ff6955c24e 85 ps->time->hour = h;
sfaghihi 20:e8ff6955c24e 86 ps->prevTime->hour = h;
sfaghihi 20:e8ff6955c24e 87 ps->time->minute = m;
sfaghihi 20:e8ff6955c24e 88 ps->prevTime->minute = m;
sfaghihi 20:e8ff6955c24e 89 ps->time->second = s;
sfaghihi 20:e8ff6955c24e 90 ps->prevTime->second = s;
sfaghihi 20:e8ff6955c24e 91 ps->date->year = y;
sfaghihi 20:e8ff6955c24e 92 ps->date->day = d;
sfaghihi 20:e8ff6955c24e 93 ps->date->month = mo;
sfaghihi 20:e8ff6955c24e 94 ps->date->dow = dow-1;
sfaghihi 19:450dbcda696e 95 }
sfaghihi 19:450dbcda696e 96
sfaghihi 19:450dbcda696e 97 void update_rtc(StateClass *ps)
sfaghihi 19:450dbcda696e 98 {
sfaghihi 20:e8ff6955c24e 99 /*
sfaghihi 19:450dbcda696e 100 DateTime data(ps->date->year, ps->date->month, ps->date->day, ps->time->hour, ps->time->minute, ps->time->second);
sfaghihi 20:e8ff6955c24e 101 rtc.adjust(data);*/
sfaghihi 20:e8ff6955c24e 102 //rtc.settime(ps->time->second, ps->time->minute, ps->time->hour, ps->date->dow, ps->date->day, ps->date->month, ps->date->year);
amilner1 15:452425c099ef 103 }