ESP32 with a small display

I’ve bought this little device ESP32 C3 desktop trinket Mini TV Portable Pendant LVGL 1.44inch LCD ST7735 Brand Spotpear

It has a 128x128 screen and 4 buttons (reset+3). It can be used as a multi-button command that displays status messages.

I did not find reliable instructions to setup the device using Arduino IDE so I’ve decided to go the tasmota route. So here is what I’ve done:

  1. Flash the device with tasmota using `ESP-Flasher`and a suitable firmware.This repositorycontains several unnofficial fw’s, I’ve used `tasmota32c3-lvgl.bin`

  2. When tasmota boots for the first time it asks the wi-fi credentials. Tasmota will then reboot and the device will display a blank screen

  3. It’s now necessary to define the GPIO pins. For this device I had to compare the diagram posted by the vendor with tasmota requirements, resulting in.

imagem

  1. Now MQTT needs to be parametrized so that openHAB (or other app) can use the device. I also used the `SO73 1` command so that buttons can be identified. Tasmota will now reboot. The console should display a successfull login to your mosquitto broker. You need to define a topic for the device (in my case display-secador)

  2. Using Tools → Manage File System you have to upload the following 3 files to the device

display.ini (this is not app dependent, you can use it as is)

:H,ST7735,128,128,16,SPI,1,*,*,*,*,*,*,*,40
:S,2,1,1,0,40,20
:I
EF,3,03,80,02
CF,3,00,C1,30
ED,4,64,03,12,81
E8,3,85,00,78
CB,5,39,2C,00,34,02
F7,1,20
EA,2,00,00
C0,1,23
C1,1,10
C5,2,3e,28
C7,1,86
36,1,48
37,1,00
3A,1,55
B1,2,00,18
B4,1,04
B6,3,08,82,27
F2,1,00
26,1,01
E0,0F,0F,31,2B,0C,0E,08,4E,F1,37,07,10,03,0E,09,00
E1,0F,00,0E,14,03,11,07,31,C1,48,08,0F,0C,31,36,0F
11,80
29,80
:o,28
:O,29
:A,2A,2B,2C,16
:R,36
:0,C0,00,00,00
:1,A0,00,00,01
:2,00,00,00,02
:3,60,00,00,03
:i,20,21

autoexec.be (this defines how the device will interpret commands sent via mqtt)

import haspmota
import string
haspmota.start()

tasmota.add_cmd('msgs',
  def (cmd, idx, payload, raw)
    global.p1b20.text = string.format("%s",raw["msg1"])
    tasmota.resp_cmnd_done()
  end)

Basically this says that when the device receives a cmnd/display-secador/msgs with payload {“msg1”:”any text”} the variable p1b20 (id20 on page 1, see file below) gets its value modified by “any text”. It’s possible to define more fields, but in this case pls use a smaller font, the device has a small screen and there is no much space available for characters.

pages.jsonl (this file defines the screen layout for my application)

{"page":0,"comment":"---------- Upper stat line ----------"}

{"id":11,"obj":"label","x":0,"y":0,"w":100,"pad_right":5,"h":22,"bg_color":"#D00000","bg_opa":255,"text_color":"#ffffff","radius":0,"border_side":0,"text":"","text_font":"montserrat-20"}
{"id":12,"obj":"label","x":101,"y":0,"w":27,"pad_right":5,"h":22,"bg_color":"#00ff00","bg_opa":255,"text_color":"#ffffff","radius":0,"border_side":0,"text":"","text_font":"montserrat-20"}
{"id":13,"obj":"label","x":101,"y":105,"w":27,"pad_right":5,"h":22,"bg_color":"#0000ff","bg_opa":255,"text_color":"#ffffff","radius":0,"border_side":0,"text":"","text_font":"montserrat-20"}

{"id":15,"obj":"lv_wifi_arcs","x":2,"y":0,"w":29,"h":22,"radius":0,"border_side":0,"bg_color":"#000000","line_color":"#FFFFFF"}
{"id":16,"obj":"lv_clock","x":30,"y":3,"w":55,"h":16,"radius":0,"border_side":0,"text_color":"#ffffff"}

{"page":1,"comment":"---------- Page 1 ----------"}

{"id":0,"bg_color":"#0000A0","bg_grad_color":"#000000","bg_grad_dir":1,"text_color":"#FFFFFF"}
{"id":20,"obj":"label","x":10,"y":55,"w":100,"text":"OFF","align":1,"text_font":"montserrat-28"}

Reboot the device and it will display:

imagem

I’ve used green and red colors to mark the buttons that I want to use in my app.

Finally you have to create a thing in openHAB. My definitions are:

UID: mqtt:topic:aveiro:0d8e4cd82c
label: Comando Secador de Roupa
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: Offline
  availabilityTopic: tele/display-secador/LWT
  payloadAvailable: Online
bridgeUID: mqtt:broker:aveiro
channels:
  - id: switch
    channelTypeUID: mqtt:switch
    label: Switch
    configuration:
      commandTopic: cmnd/display-secador/POWER
      stateTopic: stat/display-secador/POWER
  - id: WebServer
    channelTypeUID: mqtt:switch
    label: WebServer
    configuration:
      commandTopic: cmnd/display-secador/WebServer
      off: "0"
      on: "2"
  - id: fw
    channelTypeUID: mqtt:string
    label: Firmware
    configuration:
      stateTopic: stat/display-secador/STATUS2
      transformationPattern:
        - REGEX:(.*StatusFWR.*)∩JSONPATH:$.StatusFWR.Version
  - id: rssi
    channelTypeUID: mqtt:number
    label: RSSI
    configuration:
      stateTopic: tele/display-secador/STATE
      transformationPattern:
        - REGEX:(.*RSSI.*)∩JSONPATH:$.Wifi.RSSI
  - id: status
    channelTypeUID: mqtt:string
    label: Status
    configuration:
      formatBeforePublish: '{"msg1":"%s"}'
      commandTopic: cmnd/display-secador/msgs
  - id: button1
    channelTypeUID: mqtt:string
    label: Button 1
    configuration:
      stateTopic: stat/display-secador/RESULT
      transformationPattern:
        - REGEX:(.*Button1.*)∩JSONPATH:$.Button2.Action
  - id: button2
    channelTypeUID: mqtt:string
    label: Button 2
    configuration:
      stateTopic: stat/display-secador/RESULT
      transformationPattern:
        - REGEX:(.*Button2.*)∩JSONPATH:$.Button2.Action
  - id: button3
    channelTypeUID: mqtt:string
    label: Button 3
    configuration:
      stateTopic: stat/display-secador/RESULT
      transformationPattern:
        - REGEX:(.*Button3.*)∩JSONPATH:$.Button3.Action

You can link items to the channels, these are the device specific ones:

  • button1/2/3 - when such buttons are pressed in the device you will receive SINGLE DOUBLE TRIPLE QUAD PENTA HOLD or CLEAR. This requires that `SO73 1` has been used in device’s console. In my case I’ve only used buttons 2 and 3
  • status - a short message (up to +/-10 characters with the font used in this example)
  • switch - to turn the screen ON/OFF

Enjoy

Awesome build! This definitely belongs here:

:wink: super cool!