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 12:01:06 2017 +0000
Revision:
22:68869504b1ee
Parent:
21:fe1769d5a01c
something (not Nothing)

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 21:fe1769d5a01c 36 void playAlarmSound()
amilner1 15:452425c099ef 37 {
amilner1 15:452425c099ef 38 PwmOut speaker(ALARM_PIN); // alarm sound of regular beeps
sfaghihi 21:fe1769d5a01c 39 while (programState->duringAlarm) {
amilner1 15:452425c099ef 40 speaker.period(1.0/150.0); // 150hz period
amilner1 15:452425c099ef 41 speaker =0.0125;
amilner1 15:452425c099ef 42 wait(0.5);
amilner1 15:452425c099ef 43 speaker=0.0; // turn off audio
amilner1 15:452425c099ef 44 wait(0.5);
amilner1 15:452425c099ef 45 }
sfaghihi 17:7ba6c8e4945b 46 }
sfaghihi 17:7ba6c8e4945b 47
sfaghihi 19:450dbcda696e 48 AnalogIn ain(RANGE_AN);
sfaghihi 19:450dbcda696e 49 DigitalOut cs(RANGE_CS, 0);
sfaghihi 18:2afeed90c051 50
sfaghihi 17:7ba6c8e4945b 51 bool getDistance()
sfaghihi 17:7ba6c8e4945b 52 {
sfaghihi 18:2afeed90c051 53 float adc, volts, inches;
sfaghihi 18:2afeed90c051 54 cs = 1;
sfaghihi 18:2afeed90c051 55 wait_us(30);
sfaghihi 18:2afeed90c051 56 adc = ain.read(); // read analog as a float
sfaghihi 19:450dbcda696e 57 volts = adc * 4.5; // convert to volts
sfaghihi 19:450dbcda696e 58 inches = volts / 0.0095;
sfaghihi 19:450dbcda696e 59 cs = 0;
sfaghihi 18:2afeed90c051 60 return inches <= RANGE_THRESHOLD;
sfaghihi 19:450dbcda696e 61 }
sfaghihi 19:450dbcda696e 62
sfaghihi 21:fe1769d5a01c 63 //I2C master(RTC_SDA, RTC_SCL);
sfaghihi 21:fe1769d5a01c 64 Rtc_Ds1307 rtc(RTC_SDA, RTC_SCL);
sfaghihi 19:450dbcda696e 65 void read_rtc(StateClass *ps)
sfaghihi 19:450dbcda696e 66 {
sfaghihi 21:fe1769d5a01c 67 Rtc_Ds1307::Time_rtc data = {};
sfaghihi 21:fe1769d5a01c 68 int s = 0, m = 0, h = 0, dow = 0, d = 0, mo = 0, y = 0;
sfaghihi 21:fe1769d5a01c 69 //rtc.gettime(&s, &m, &h, &dow, &d, &mo, &y);
sfaghihi 21:fe1769d5a01c 70 rtc.getTime(data);
sfaghihi 21:fe1769d5a01c 71 h = data.hour;
sfaghihi 21:fe1769d5a01c 72 m = data.min;
sfaghihi 21:fe1769d5a01c 73 s = data.sec;
sfaghihi 21:fe1769d5a01c 74 dow = data.wday - 1;
sfaghihi 21:fe1769d5a01c 75 d = data.date;
sfaghihi 21:fe1769d5a01c 76 mo = data.mon;
sfaghihi 21:fe1769d5a01c 77 y = data.year;
sfaghihi 21:fe1769d5a01c 78 LOG("%d:%d:%d", h, m, s);
sfaghihi 21:fe1769d5a01c 79 //if (!rtc.isRunning())
sfaghihi 21:fe1769d5a01c 80 // return;
sfaghihi 21:fe1769d5a01c 81 ps->time->hour = h;
sfaghihi 21:fe1769d5a01c 82 ps->prevTime->hour = h;
sfaghihi 21:fe1769d5a01c 83 ps->time->minute = m;
sfaghihi 21:fe1769d5a01c 84 ps->prevTime->minute = m;
sfaghihi 21:fe1769d5a01c 85 ps->time->second = s;
sfaghihi 21:fe1769d5a01c 86 ps->prevTime->second = s;
sfaghihi 21:fe1769d5a01c 87 ps->date->year = y;
sfaghihi 21:fe1769d5a01c 88 ps->date->day = d;
sfaghihi 21:fe1769d5a01c 89 ps->date->month = mo;
sfaghihi 21:fe1769d5a01c 90 ps->date->dow = dow-1;
sfaghihi 19:450dbcda696e 91 }
sfaghihi 19:450dbcda696e 92
sfaghihi 19:450dbcda696e 93 void update_rtc(StateClass *ps)
sfaghihi 19:450dbcda696e 94 {
sfaghihi 21:fe1769d5a01c 95 //DateTime data(ps->date->year, ps->date->month, ps->date->day, ps->time->hour, ps->time->minute, ps->time->second);
sfaghihi 21:fe1769d5a01c 96 //rtc.adjust(data);
amilner1 15:452425c099ef 97 }