esp8266 – Cam's Electronics Projects http://localhost Sun, 08 Apr 2018 19:34:46 +0000 en-CA hourly 1 https://wordpress.org/?v=4.7.10 Internet Alarm Clock Front Panel http://localhost/2018/04/07/internet-alarm-clock-front-panel/ Sun, 08 Apr 2018 00:49:32 +0000 http://localhost/?p=90 After completing my clinical engineering internship hours while simultaneously working on my research, followed by a three-month research sprint and thesis draft, it’s time for a catch-up post.

An early sketch of the front panel design (Jan 7, 2017).

I started the ball rolling on the Internet Alarm Clock in early 2017 by designing a front panel PCB that implements the alarm clock’s physical user interface (UI).

The front panel is intended to connect to another PCB (to be designed) via a single 6 pin, 0.1″ pitch IDC connector for the I2C (data) bus, power, and button interrupt signal.

Here’s a rundown of the UI elements:

  • Classic red seven-segment display for displaying the time.
  • Character LCD screen for displaying additional information. Transflective with RGB backlight.
  • Four directional buttons (up, down, left, right) for setting the time.
  • Three buttons at the top, each colour-coded for association with a specific functionality:
    • Red, associated with the clock (to match the red seven segment display)
    • Green, associated with the weather reporting functionality (to match the colour of… grass I guess!)
    • Blue, associated with the next arriving bus (inspired by the blue lights on TTC buses)
Alarm clock front panel PCB schematics (Jan 24, 2017)

The front panel electronic design is fairly straightforward. An as1115 does the heavy lifting by doing three things:

  1. Driving the four-digit, seven-segment clock display
  2. Controlling the Newhaven character LCD (NHD-C0220BIZ-FS(RGB)-FBW-3VM
    ) backlight via three switching BJTs (to accommodate the different rated voltages of each of the red, green, and blue backlight LEDs).
  3. Reading the button input from the seven buttons.
Finalized front panel layout (Jan 24, 2017)

For the final layout I decided to move the up/down/left/right buttons alongside the seven-segment display, hoping to make setting the alarm (or, in the absence of Wi-Fi, setting the time) more intuitive.

Unpopulated front panel PCBs (Feb 9, 2017)

I decided to use an Adafruit ESP8266 Wi-Fi module breakout board (2471) as the Wi-Fi module, due to its wide use among hobbyists for their projects, which I can refer to for help. Adafruit’s version comes with the NodeMCU firmware, which implements a Lua-based scripting engine. As I wrote routines in Lua to exercise the displays and read the buttons on the front panel PCB via the I2C bus, I gradually built up a prototype firmware throughout 2017.

Front panel PCB under control of the Adafruit Huzzah ESP8266 breakout board (assembled Mar 2017, photo taken Apr 2018)

I was able to implement the following features using Lua scripting and appropriate selection of modules for a custom NodeMCU build (built using nodemcu-build.com):

  • Automatic syncronization of time over Wi-Fi using NodeMCU’s Network Time Protocol (NTP) module
  • Wi-Fi connection and alarm status icons
  • Automatic dimming of seven segment display at night
  • Setting the alarm time
  • Setting date and time if no Wi-Fi found (could not fully implement due to memory constraints)
  • Visual portion of the alarm, signified by colour-cycling the LCD backlight

The last feature is pretty cool:

Rise and shine!

But, after a certain point, my scripts ran out of memory. Despite there being 4 MB of flash (less 0.5 MB for the firmware) on the underlying module in which to store the scripts, it seems that the Lua interpreter has to load these text files to RAM to execute, and then the variables (of which many are strings) take additional memory, on top of the interpreter’s RAM footprint. Though I’m not entirely sure how NodeMCU partitions and manages the ESP8266 memory space, it appears that RAM is limited to the order of tens of kilobytes. So I may have to use an external microcontroller and program the user interface in C, where it can execute directly from the micro’s flash memory, and reserve the Lua scripting for the high-level network interfacing (e.g. parsing XML or JSON to get the weather and next bus).

Bill of materials, KiCad design files, and Lua scripts are available in this post’s commit.

]]>