Wednesday 22 June 2022

LilyGo T-Display Keypad


Rationale

Some years ago I setup a home music server based on Linux Music Player Daemon (MPD) with a web front-end to select and control music playing on my HiFi separates system.  Typically I would choose music to play using  my iPad or phone browser.
As an add-on I developed an ESP8266 attached keypad which also allowed me to control the music.  I call it my "Button" although it has a number of buttons/functions.  It is particularly useful for pause / resume, next type functions and to start my favourite playlists and radio channels.  Effectively it is a clever remote control tailored to suit my needs.
The original "Button" version 1 has a USB cable to power the ESP8266 so it isn't very portable; typically this doesn't matter but I did develop version 2 which has a rechargeable battery.  I found this cumbersome and I haven't used it much.  Both Buttons have a tiny LCD screen to display status info but this isn't very visible as I have had difficulty creating suitable enclosures to accomodate ESP8266/keypad/displays.


Recently I have implemented my Home Assistant (HA) Server, including MPD for music server control and Arduino based MQTT communication.  This allows me to control my HiFi from an ESP device and I added it to my "Button" software for testing purposes and it works fine. It works in parallel to my original application and has the potential for more functionality / flexibility.

In advance of doing more work on the button I looked out for a case for an ESP device and keypad which would be more compact than my home-made devices.  I was excited to stumble on the LilyGo T-Display Keypad on Aliexpress.
It is based on the ESP32, has a mechanical keyboard, a small TFT display and a rechargeable battery all in a neat case.  This is an absolutely perfect replacement for my old buttons and I ordered one immediately.

First look

Connecting the USB-C cable causes the ESP32 to start up.  A simple display appears allowing you to display wifi networks, input voltage or put the processor into a deep sleep.  There are two buttons adjacent to the TFT screen for these controls.  There is also a reset button on the top or right of the case.
Like a remote control there is no on / off switch which feels very strange to me.





The LilyGO github repository provides you with instructions to load the TFT library and example sketches into your PC Arduino development environment.
From there it is easy to compile and load the Factory_Test sketch which is the same one as installed on delivery.  This is awesome, nothing makes life easier than a working example containing many of the features of the device.  In particular it provides information on:
    All the pins needed for keypad, TFT, buttons, SD Card
    Arduino libraries for all hardware
    Example code to use the TFT display
    Example code to find the input reference voltage (useful for low battery check)
    Example to display a bitmap on the TFT
    How to put the ESP into deep sleep

In addition there are sketches for
    Example code to use the keypad
    Test SD functions to create, view, delete file and directory list.
    A rather good animated eyes sketch which makes really brings the screen to life.

This makes my life so much easier and saves me many, many hours looking at schematics, finding libraries, writing code to set up everything.

Application One

My first application requirement is clearly to setup similar functionality to the "Button".
Firstly I amended example code to read input from the keypad and display messages on the screen.  I then added wifi and websockets based on "Button 1" code.  Using a case statement I could then easily process key presses and send websocket messages to PI40 (which processes websocket input) for processing.  Within a few hours I have a working example for the "Button 3" based on the web page which I usually use.

I added and tested MQTT, using Home Assistant (HA) as my MQTT Broker.  This allows me to communicate with HA and use a HA script or automation to control any function HA function.  This is an extremely powerful extra.  On my webpage I cannot control amplifier volume since the amp is old and uses an IR remote control.  However my Broadlink IR remote is controlled by HA and I can add volume up/down buttons to LilyGo.

The LilyGo battery runs out after about 24 hours if not recharged, so I set up a button to show battery percentage / time remaining and another button to clear the screen.  This completes a basic setup which is a great improvement over my previous buttons and which I use in preference to my phone.

I cannot stress enough what a good product this is for me, both in terms of the hardware purchased and the software provided to help get started.  I shall look out for other products they can inspire me with.


     

 


No comments:

Post a Comment