Skip to content

Instantly share code, notes, and snippets.

@Nizzle
Last active October 14, 2024 21:15
Show Gist options
  • Save Nizzle/6971c2cc066e6412740487bcc3b2c62a to your computer and use it in GitHub Desktop.
Save Nizzle/6971c2cc066e6412740487bcc3b2c62a to your computer and use it in GitHub Desktop.
ESPhome config for SHA2017 badge (https://wiki.sha2017.org/w/Projects:Badge)
esphome:
name: shabadge
esp32:
board: esp32-pro
logger:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
ota:
password: !secret ota_pass
api:
id: hassapi
password: !secret api_pass
i2c:
sda: 26
scl: 27
scan: True
mpr121:
id: mpr121_component
address: 0x5A
touch_debounce: 1
release_debounce: 1
touch_threshold: 12
release_threshold: 6
binary_sensor:
- platform: mpr121
id: touch_buttonA
channel: 0
name: "Touch Button A"
- platform: mpr121
id: touch_buttonB
channel: 1
name: "Touch Button B"
- platform: mpr121
id: touch_buttonStart
channel: 2
name: "Touch Button Start"
- platform: mpr121
id: touch_buttonSelect
channel: 3
name: "Touch Button Select"
- platform: mpr121
id: touch_buttonDown
channel: 4
name: "Touch Button Down"
- platform: mpr121
id: touch_buttonRight
channel: 5
name: "Touch Button Right"
- platform: mpr121
id: touch_buttonUp
channel: 6
name: "Touch Button Up"
- platform: mpr121
id: touch_buttonLeft
channel: 7
name: "Touch Button Left"
- platform: mpr121
id: charging_status
channel: 9
name: "Charging Status"
- platform: gpio
name: "Flash Button"
pin: 0
filters:
- invert:
sensor:
- platform: adc
pin: 34
attenuation: 6db
filters:
- multiply: 2.91
name: "USB Voltage"
update_interval: 20s
accuracy_decimals: 1
- platform: adc
pin: 35
attenuation: 6db
#attenuation: 2.5db
filters:
- multiply: 2.91
#- multiply: 1.95
name: "Battery Voltage"
update_interval: 20s
accuracy_decimals: 1
- platform: uptime
name: Uptime Sensor
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 (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
spi:
clk_pin: 18
mosi_pin: 5
text_sensor:
- platform: version
id: ver
hide_timestamp: true
- platform: template
name: Uptime Human Readable
id: uptime_human
icon: mdi:clock-start
display:
- platform: waveshare_epaper
cs_pin: 19
dc_pin: 21
busy_pin: 22
reset_pin: 23
model: 2.90in-dke
#Partial not working yet so full only
full_update_every: 1
update_interval: 5s
lambda: |-
it.printf(0, 0, id(font40), "%s", id(ver).state.c_str());
it.printf(0, 40, id(font40), "%s", id(uptime_human).state.c_str());
rotation: 270
external_components:
- source:
type: git
url: https://github.com/Nizzle/esphome
ref: dke2.9-epaper
components: [ waveshare_epaper ]
font:
- file: "Fonts/Comfortaa-Regular.ttf"
id: font40
size: 40
@waza-ari
Copy link

waza-ari commented May 13, 2024

Hey, thanks for the writeup! With the latest ESPHome Beta release the following code kinda works:

spi:
  clk_pin: 18
  mosi_pin: 5

display:
  - platform: waveshare_epaper
    model: 2.90in-dke
    cs_pin: GPIO19
    dc_pin: GPIO21
    busy_pin: GPIO22
    reset_pin: GPIO23
    full_update_every: 1  # Partial not working yet so full updates only.
    update_interval: 20s
    lambda: |-
      it.printf(0, 34, id(font32), "My Fancy Text");
    rotation: 270

font:
  - file: "fonts/comfortaa.ttf"
    id: font32
    size: 32

It does print the text, however the refresh doesn't work:

[00:02:41][I][waveshare_epaper:1218]: Performing e-paper update.
[00:02:42][E][waveshare_epaper:159]: Timeout while displaying image!
[00:02:42][W][component:237]: Component display took a long time for an operation (1030 ms).
[00:02:42][W][component:238]: Components should block for at most 30 ms.

Any idea what could be causing this?

@polyfloyd
Copy link

Is anything actually changing the contents of the display? Maybe it only refreshes when some displayed value has changed

@waza-ari
Copy link

@polyfloyd sorry I should have mentioned that. Interestingly the display flashes black briefly (which is probably normal for the full update), and the content itself is shown. So the update does work as expected, still the messages are irritating me.

@SqyD
Copy link

SqyD commented Sep 6, 2024

Hey @Nizzle !
I've started to gather esphome configurations for various badgeteam badges here I've made some minor tweaks to your configuration so it works with more recent esphome versions that made some modifications of the display component. Naturally I've given full credits to you as the original author.

Thanks!
Paul / "SqyD"

@morris2009
Copy link

Did you ever found a configuration from someone, or a way to turn on the LED's on this 2017Sha-badge?
I did play around, and I can turn them on, on boot by powering that chip, but couldn't find a way of switching them on or off or setting the brightness.

I do use my old badge as a keypad panel in my office and a display of the temperature and humidity i read from other sensors and retrieve from Home Assistant. Really happy with that :)

@polyfloyd
Copy link

@morris2009 LED power is switched by the MPR touch sensor which also acts as GPIO extender.

I do not use the LED's myself, but the 5V power coming out of the breakout connector on the back is switched via the same circuit.

I have the block below block in my config. With this, you should be able to drive the LEDs via something like the neopixel driver.

mpr121:
  id: mpr121_component
  address: 0x5A
  touch_debounce: 1
  release_debounce: 1
  touch_threshold: 10
  release_threshold: 7

output:
  - id: led_and_ext_power
    platform: gpio
    pin:
      mpr121: mpr121_component
      number: 10
      mode: OUTPUT
      inverted: true

@morris2009
Copy link

morris2009 commented Oct 14, 2024

@polyfloyd
** Edit: have no been able to get the LED's working (config below)

Haven't been able to get the LEDs working yet, unfortunately.

But for reference to add to @Nizzle his git repository, you can use the buzzer if you ever need to. You'd have to give up the is_charging sensor though (channel 9 on the mpr121), because in esphome the mpr121 touch sensors can only be enabled as a range. And the power to the buzzer is channel 8 which i used as GPIO output, similar as channel 10 (apparantly for enabling the power to the LEDstrip).
You might be able to directly access the GPIO in a switch section, or a button section, but I am not that good in writing yaml. In this way you can use automations in home assistant to trigger the buzzer, or even to trigger it when a sensor is too high, via lambda's independent of home assistant.

the following is the code i used for the buzzer

output:
  - id: buzzer_power
    platform: gpio
    pin:
      mpr121: mpr121_component
      number: 8
      mode: OUTPUT

button:
  - platform: output
    name: buzzer
    output: buzzer_power
    duration: 4000ms
    icon: mdi:vibrate

And this is the correct config for the 6 LED's. i guess there is still something to gain by setting up each led as a separate partition to gain full advantage.

  - platform: neopixelbus
    type: GRBW
    variant: sk6812
    pin: 32
    num_leds: 6
    name: badge_leds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment