Giter Site home page Giter Site logo

bolaerts / esp32-2432s028 Goto Github PK

View Code? Open in Web Editor NEW
103.0 7.0 13.0 3.44 MB

Home Assistant integration using ESPHome on an esp32-2432s028 board, featuring I²C expansion and touchscreen functionalities

License: MIT License

esp32-2432s028 esphome ili9341 xpt2046 i2c spi

esp32-2432s028's Introduction

ESP32-2432s028

Introduction

This repository contains some experimental setup for using the esp32-2432s028 develoment board with tft display within Home Assistant. Only a few gpio pins are exposed and usable, but by using I²C you could use a MCP23017 module to add additional ports.

Hardware

Wiring esp32-2432s028 + BME280 sensor

All credits for extended pinout explanation go to macsbug, see more on: https://macsbug.wordpress.com/2022/08/17/esp32-2432s028/

Schematic

Flashing instructions: keep the boot button pressed when you plug in the USB cable/flasher, this will allow to flash the firmware.

Software

SPI

Two separate SPI busses are being used for the display and the touchscreen.

spi:
  - id: lcd
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12
  - id: touch
    clk_pin: GPIO25
    mosi_pin: GPIO32
    miso_pin: GPIO39

Display

The esp32-2432s028 has an ili9341 display that can be used via the lcd SPI bus:

display:
  - platform: ili9xxx
    model: ILI9341
    spi_id: lcd
    cs_pin: 15
    dc_pin: 2
    lambda: |-
      ...

# Former led pin in the display config
output:
  - platform: ledc
    pin: 21
    id: former_led_pin

# Define a monochromatic, dimmable light for the backlight
light:
  - platform: monochromatic
    output: former_led_pin
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON

Touchscreen

To add touch functionalities, a touchscreen component should be added via the touch SPI bus:

touchscreen:
  platform: xpt2046
  spi_id: touch
  cs_pin: 33
  interrupt_pin: 36
  update_interval: 50ms
  threshold: 400
  calibration_x_min: 3860
  calibration_x_max: 280
  calibration_y_min: 340
  calibration_y_max: 3860

I2C

The default gpio pins for I2C on an ESP32 are GPIO21 and GPIO22. Both of them are exposed in the extended IO connector (P3), but apparently GPIO21 is also used as a led pin in the lcd SPI bus, so it looks as if this gpio pin is somehow useless on the extended IO connector. GPIO35 which is also exposed in the extended IO connector can only be used for input, so also useless for I2C. Luckily there is another connector with GPIO27, which makes it possible to setup an I2C bus.

i2c:
  sda: GPIO27
  scl: GPIO22
  scan: true
  id: bus_a

Force LED on back of module to stay off

# Define pins for backlight display and back LED1
output:
  - platform: ledc
    pin: GPIO21
    id: former_led_pin
  - platform: ledc
    id: output_red
    pin: GPIO4
    inverted: true
  - platform: ledc
    id: output_green
    pin: GPIO16
    inverted: true
  - platform: ledc
    id: output_blue
    pin: GPIO17
    inverted: true

# Define a monochromatic, dimmable light for the backlight
light:
  - platform: monochromatic
    output: former_led_pin
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON
  - platform: rgb
    name: LED
    red: output_red
    id: led
    green: output_green
    blue: output_blue
    restore_mode: ALWAYS_OFF

Demo

YAML

substitutions:
  devicename: "esp32-2432s028"
  ssid: Esp32-2432S028 Fallback Hotspot
  static_ip: 192.168.0.44
  gateway: 192.168.0.1
  subnet: 255.255.255.0

packages:
  wifi: !include common/wifi.yaml
  
esphome:
  name: $devicename
  build_path: ./build/$devicename

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:

api:

ota:

captive_portal:

spi:
  - id: lcd
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12
  - id: touch
    clk_pin: GPIO25
    mosi_pin: GPIO32
    miso_pin: GPIO39

i2c:
  sda: GPIO27
  scl: GPIO22
  scan: true
  id: bus_a

color:
  - id: my_red
    red: 100%
    green: 0%
    blue: 0%
  - id: my_orange
    red: 100%
    green: 50%
    blue: 0%
  - id: my_yellow
    red: 100%
    green: 100%
    blue: 0%
  - id: my_green
    red: 0%
    green: 100%
    blue: 0%
  - id: my_blue
    red: 0%
    green: 0%
    blue: 100%
  - id: my_teal
    red: 0%
    green: 100%
    blue: 100%
  - id: my_gray
    red: 70%
    green: 70%
    blue: 70%
  - id: my_white
    red: 100%
    green: 100%
    blue: 100%

font:
  - file: "Helvetica.ttf"
    id: helvetica_48
    size: 48
  - file: "Helvetica.ttf"
    id: helvetica_36
    size: 36
  - file: "Helvetica.ttf"
    id: helvetica_24
    size: 24
  - file: "Helvetica.ttf"
    id: helvetica_12
    size: 12

image:
  - file: "power-off-button.png"
    id: on_off_button
  - file: "radio-station.png"
    id: radio

binary_sensor:
  - platform: status
    name: "Node Status"
    id: system_status

  - platform: touchscreen
    name: Power
    x_min: 30
    x_max: 90
    y_min: 20
    y_max: 80

  - platform: touchscreen
    name: Music
    x_min: 150
    x_max: 210
    y_min: 20
    y_max: 80

time:
  - platform: homeassistant
    id: esptime

text_sensor:
  - platform: template
    # name: Uptime Human Readable
    id: uptime_human
    icon: mdi:clock-start
    internal: True

  - platform: wifi_info
    ip_address:
      # name: ESP IP Address
      id: ip_address

sensor:
  - platform: uptime
    # name: Uptime Sensor
    internal: True
    id: uptime_sensor
    update_interval: 1s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                ("Uptime ") +
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

  - platform: wifi_signal
    # name: "WiFi Signal Sensor"
    internal: True
    id: wifi_signal_sensor
    update_interval: 5s

  - platform: bmp280
    temperature:
      name: "Temperatuur"
      unit_of_measurement: °C
      accuracy_decimals: 1
      id: "bme_temperature"
    pressure:
      name: "Luchtdruk"
      unit_of_measurement: hPa
      accuracy_decimals: 0
      id: "bme_humidity"
    address: 0x76
    update_interval: 30s        

display:
  - platform: ili9xxx
    model: ILI9341
    spi_id: lcd
    cs_pin: 15
    dc_pin: 2
    lambda: |-
      int hs = it.get_width() / 2; // Horizontal Spacing = text data horizontal center point
      int hq = it.get_width() / 4; // text data horizontal center for two vertical lines
      int vs = it.get_height() / 8; // Vertical Center = text data vertical center point = how many lines
      int line_gap = 21; // distance of line from center of data text
      it.rectangle(0,  0, it.get_width(), it.get_height(), id(my_blue));
      it.rectangle(0, 20, it.get_width(), it.get_height(), id(my_blue));
      
      it.strftime(5, 5, id(helvetica_12), id(my_white), TextAlign::TOP_LEFT, "%H:%M:%S", id(esptime).now());
      it.print(hs, 5, id(helvetica_12), id(my_blue), TextAlign::TOP_CENTER, "${devicename}"); //print title  
      
      if (id(system_status).state) {
        it.print(it.get_width()-5, 5, id(helvetica_12), id(my_green), TextAlign::TOP_RIGHT, "Online");
      }
      else {
        it.print(it.get_width()-5, 5, id(helvetica_12), id(my_red), TextAlign::TOP_RIGHT, "Offline");
      }
      it.line(0, it.get_height()-20, it.get_width(), it.get_height()-20, id(my_blue)); // line across bottom above footer text
      it.printf(5, it.get_height()-3, id(helvetica_12), id(my_gray), TextAlign::BOTTOM_LEFT, "%s", id(uptime_human).state.c_str());
      it.printf(hs, it.get_height()-3, id(helvetica_12), id(my_gray), TextAlign::BOTTOM_CENTER, "%.0fdBm", id(wifi_signal_sensor).state);
      it.printf(it.get_width()-5, it.get_height()-3, id(helvetica_12), id(my_gray), TextAlign::BOTTOM_RIGHT, "%s", id(ip_address).state.c_str());
      it.image(hq - 25, 50, id(on_off_button));
      it.image(3*hq - 25, 50, id(radio));

      it.line(0, vs * 3, it.get_width(), vs * 3, id(my_blue));
      it.print(hs, vs * 3 + line_gap, id(helvetica_24), id(my_white), TextAlign::CENTER, "BME280 sensor");
      it.line(0, vs * 4, it.get_width(), vs * 4, id(my_blue));
      it.print(hq, vs * 5, id(helvetica_12), id(my_white), TextAlign::CENTER, "Temperature:");
      it.printf(3*hq, vs * 5, id(helvetica_12), id(my_white), TextAlign::CENTER, "%.1f°C", id(bme_temperature).state);
      it.print(hq, vs * 6, id(helvetica_12), id(my_white), TextAlign::CENTER, "Pressure:");
      it.printf(3*hq, vs * 6, id(helvetica_12), id(my_white), TextAlign::CENTER, "%.0fhPa", id(bme_humidity).state);

# Define pins for backlight display and back LED1
output:
  - platform: ledc
    pin: GPIO21
    id: former_led_pin
  - platform: ledc
    id: output_red
    pin: GPIO4
    inverted: true
  - platform: ledc
    id: output_green
    pin: GPIO16
    inverted: true
  - platform: ledc
    id: output_blue
    pin: GPIO17
    inverted: true

# Define a monochromatic, dimmable light for the backlight
light:
  - platform: monochromatic
    output: former_led_pin
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON
  - platform: rgb
    name: LED
    red: output_red
    id: led
    green: output_green
    blue: output_blue
    restore_mode: ALWAYS_OFF

touchscreen:
  platform: xpt2046
  spi_id: touch
  cs_pin: 33
  interrupt_pin: 36
  update_interval: 50ms
  report_interval: 1s
  threshold: 400
  calibration_x_min: 3860
  calibration_x_max: 280
  calibration_y_min: 340
  calibration_y_max: 3860
  swap_x_y: false

# Exposed switches.
switch:
  - platform: restart
    name: ESP32-2432S028 Restart

Screenshot

Schematic

Home Assistant integration

Schematic

Enclosure options

Update 19.07.2023: attempt to make a Home Assistant remote control

Using one of the above enclosure options, a 600 MAh 3.7V battery and a MT3608 step-up convertor, I tried to make a Home Assistant remote control. Conclusion: it works, but unfortunately I didn't manage to keep it working for an acceptable period of time, even with deep sleep implemented.

Remote control

Remote control under the hood

esp32-2432s028's People

Contributors

bolaerts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-2432s028's Issues

FWIW DHT 11, or 22 sensors

You can just use the provided 4 pin connector with a DHT sensor and still have a GPIO left over

sensor:
  # - platform: dallas
  #   address: xxxxxxxxxxx
  #   name: "CYD Temp" 
  - platform: dht
    pin: GPIO22
    model: AUTO_DETECT
    temperature:
      name: "CYD Temperature"    
    humidity:
      name: "CYD Humidity"
    update_interval: 60s  

ILI9341 Display Issue with X and Y Axis Inversion ?

I'm experiencing an issue with my ILI9341 TFT LCD display when interfacing with an ESP32 using ESPHome. The display's orientation seems to be incorrect, and the rotation configuration parameter appears to have no effect on correcting the issue. It seems as if the X and Y axes are swapped.
(with factory settings there was no problem)

(Used the code example from here)
WhatsApp Image 2023-11-12 at 09 15 32_d906f38f

I have attached an image showing the problem. As you can see, the display renders with a section of static at the bottom, while the rest of the content appears to be laid out for a wider aspect ratio than what's being displayed.

Adjusting the rotation property from 0 to 90, 180, or 270 doesn't resolve the problem, leading me to suspect that there might be a deeper configuration issue at play, possibly with the axis settings.

Has anyone encountered this before and found a solution? Any help would be greatly appreciated.

Thank you!

missing wifi.yaml

Hi,
great to see one of these displays for ESPhome, but I get errors about the missing file wifi.yaml. What should be in it?
regards
Dave

ERROR Could not load truetype file /config/Helvetica.ttf: unknown file format

Hi, I tried your to install your code on my device, but ran into the following error:

ERROR Could not load truetype file /config/Helvetica.ttf: unknown file format

Could be I'm missing something in my ESPHome version (freshly installed docker container), but couldn't find any similar issues, except for https://community.home-assistant.io/t/oled-1306-128x64-error-validating/489043
But that one got no solution. The font is available. I downloaded it from your Github

Best Regards ,
Ronald

display seems to draw in the wrong direction

Hi i just tried the code example but it seems to draw the image in the wrong orientation, leaving a band of noise on the right hand of the display ( assuming the usb-c port is left ). i assume that it might be an easy fix some where however i'm not wel versed with display drawing code and lcd libs
20231022_113336

Compile error

Hi,

I see the following compile error with ESPHome 2023.9.1

Compiling .pioenvs/display1/src/main.cpp.o
Compiling .pioenvs/display1/lib64d/WiFi/WiFiSTA.cpp.o
Compiling .pioenvs/display1/lib64d/WiFi/WiFiScan.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:333:24: error: expected primary-expression before 'return'
   touch->set_interface(return new SPIClass(HSPI));
                        ^~~~~~
Compiling .pioenvs/display1/lib64d/WiFi/WiFiServer.cpp.o
*** [.pioenvs/display1/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.54 seconds ==========================

Flashing instructions

Hi,

it would be nice if the readme would provide at least basic flashing instructions. I have flashed tons of Shellys with ESPHome before but how to get this device into download boot mode I have no idea...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.