Monday, November 25, 2019

WiFi Enabled Alarm Clock - Part 1

Alarm Clocks are simple devices - they beep occasionally at a specific time. So it's probably not hard to make one. But what if we had a WiFi connected Alarm Clock? Something that would make "Internet of Things" an actual buzz word. Get it? Alarm clocks buzz... ha... okay, I guess not. Let's just get on with the build.

The display we'll be using in this project is the PCB that I got from the case for the game console I made a long time go. I still have it hooked up to the Arduino and the same great message is programmed into it.



The brains of this operation will be the ESP8266 on an Arduino Board. I'll also be using a RTC clock module to keep accurate time.


The first big issue I ran into was that the board required a 5V power supply and 5V signaling. The ESP8266 board was only capable of delivering 3.3V and 3.3V signalling. I tried to see if I could use 5V and 3.3V signalling, but the board didn't do... anything, really. So I had to get a logic level shifter. I realize I could have made my own, but I decided to get something that would match the aesthetic of the finished product (which at this point I haven't really settled on yet).

<picture of logic level shifter>

I soldered some pins on and put it in the breadboard. I supplied 3.3V to the low voltage side and 5V to the high voltage side. I then uploaded the "Send Nudes" code to the ESP8266 and... well... it flickered. Sometimes it didn't even show up at all. The "send nudes" message was not solid and the animated cycling at the bottom was off as well. So I hooked up my logic analyzer to look at the signals coming from the ESP8266, coming out of the level shifter, and coming out of the original Arduino implementation.


I was glad that the level shifter was working correctly, but the true issue was very clear from the start: the ESP8266 was far too fast. About 13.8 times as fast (357.14kHz to 25.77kHz). It took a whole day to perfect the rewrite using Arduino Timer Interrupts. This was no easy feat, and I'm rather proud of it. Once I did that, I added the ZS-043 RTC module which features the DS3231 RTC chip and communicates over an I2C bus and supports 3.3V signalling (yay), so I wrote the code to display the time, and worked really well using this library.


Next, we need to get the time from the internet, so we need to connect to a network. This proved troublesome - I kept getting stack traces in the serial console - probably because I was using a timer I shouldn't have been.

Everything above this was written on or before 11/17/17. I let the project sit for a very long time. When I came back to it, it just... worked. The time displayed and it connected to my network just fine. Two years of updates to the SDK? I don't know. But let's continue with what for me back then would have been a much harder project.

The next step is to get the time from an NTP server. I'm using an NTP library to get the seconds since the epoch and then calculating the seconds since 2000 to set to the RTC chip. However, since we're using NTP and the board will keep in sync with an NTP source, we don't really need the RTC clock. It adds unneeded complexity to the code and it's unlikely that we'll ever need to use the board outside of WiFi range. So that's a sacrifice I'm willing to make for simplicity.

So now it's time to actually build the clock to make it look nice (and give it some more features). I got a wood frame and put screws through the back of it to mount the display PCB on. The microcontroller will sit on the other side of it driving the LEDs. I'm also going to add some RGB LEDs, an alarm buzzer, and a few buttons to really bring the clock together.


The next step was installing the LEDs. Unfortunately, this is were things got a little... broken.


Here I'm using two custom made boards I made for the Hard Drive DJ Turn Table project. They're made so that you can drive three LEDs with PWM through transistors. We're leaving the other parts blank as we won't be needing them for this project. Basically, we just need three PWM signals to drive these LEDs which are fed the voltage right from our external power source (and not through the PWM pin).

Somewhere along the line, I think I fried my ESP8266. I'm not sure how and I'm not sure when, but it seems like a short developed somewhere while I was debugging it. It's intermittent (according to my multimeter) which is really odd. I'm waiting for a couple of ESP8266 chips but they'll take forever to get here. So, in the mean time, we at least have some of the software done and the code ported to the ESP8266's clock speed as well as a plan for going forward.

No comments:

Post a Comment