Hello everyone,
I am currently trying to get a Nixie clock running with ESP-Home.
I have to admit to my shame the whole code is a combination of chatgpt and internet.
I have a bit of knowledge of coding, but really not much.
every time i change something i get another error.
would someone help me and look over the code?
many thanks
display_driver.h
#ifndef DISPLAY_DRIVER_H
#define DISPLAY_DRIVER_H
#include "esphome/core/component.h"
#include "esphome/components/output/output.h"
class DisplayDriver : public esphome::Component {
public:
DisplayDriver(esphome::output::OutputPin *data_pin, esphome::output::OutputPin *clock_pin, esphome::output::OutputPin *latch_pin);
void setup();
void loop();
void update_time(int hours, int minutes);
private:
void shift_out(uint8_t value);
esphome::output::OutputPin *data_pin_;
esphome::output::OutputPin *clock_pin_;
esphome::output::OutputPin *latch_pin_;
};
#endif
display_driver.cpp
#include "display_driver.h"
// Lookup-Tabelle: Adressen für jede Zahl (0-9) auf jeder Röhre (1-4)
const uint8_t NIXIE_ADDRESSES[4][10] = {
{0b00000001, 0b00000010, 0b00000011, 0b00000100, 0b00000101, 0b00000110, 0b00000111, 0b00001000, 0b00001001, 0b00001010}, // Röhre 1
{0b00010001, 0b00010010, 0b00010011, 0b00010100, 0b00010101, 0b00010110, 0b00010111, 0b00011000, 0b00011001, 0b00011010}, // Röhre 2
{0b00100001, 0b00100010, 0b00100011, 0b00100100, 0b00100101, 0b00100110, 0b00100111, 0b00101000, 0b00101001, 0b00101010}, // Röhre 3
{0b00110001, 0b00110010, 0b00110011, 0b00110100, 0b00110101, 0b00110110, 0b00110111, 0b00111000, 0b00111001, 0b00111010} // Röhre 4
};
DisplayDriver::DisplayDriver(esphome::output::OutputPin *data_pin, esphome::output::OutputPin *clock_pin, esphome::output::OutputPin *latch_pin) {
this->data_pin_ = data_pin;
this->clock_pin_ = clock_pin;
this->latch_pin_ = latch_pin;
}
void DisplayDriver::setup() {
ESP_LOGD("DisplayDriver", "Setup completed");
}
void DisplayDriver::loop() {
// Optional: Regelmäßiger Code
}
void DisplayDriver::update_time(int hours, int minutes) {
ESP_LOGD("DisplayDriver", "Updating time: %02d:%02d", hours, minutes);
// Stunden und Minuten aufsplitten
int hour_tens = hours / 10;
int hour_units = hours % 10;
int minute_tens = minutes / 10;
int minute_units = minutes % 10;
// Zahlen in Adressen umwandeln
uint8_t address_hour_tens = NIXIE_ADDRESSES[0][hour_tens]; // Zehnerstelle der Stunde, Röhre 1
uint8_t address_hour_units = NIXIE_ADDRESSES[1][hour_units]; // Einerstelle der Stunde, Röhre 2
uint8_t address_minute_tens = NIXIE_ADDRESSES[2][minute_tens]; // Zehnerstelle der Minute, Röhre 3
uint8_t address_minute_units = NIXIE_ADDRESSES[3][minute_units]; // Einerstelle der Minute, Röhre 4
// Adressen an Schieberegister senden
shift_out(address_hour_tens);
shift_out(address_hour_units);
shift_out(address_minute_tens);
shift_out(address_minute_units);
// Latch-Pin aktivieren
this->latch_pin_->digital_write(true);
delayMicroseconds(1);
this->latch_pin_->digital_write(false);
}
void DisplayDriver::shift_out(uint8_t value) {
for (int i = 0; i < 8; i++) {
this->clock_pin_->digital_write(false);
this->data_pin_->digital_write((value >> (7 - i)) & 0x01); // Bit für Bit senden
this->clock_pin_->digital_write(true);
}
}
esphome:
name: nixie_clock
platform: ESP32
board: esp32dev
includes:
- "display_driver.cpp"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Wenn kein WLAN verfügbar ist, starte einen Access Point
ap:
ssid: "NixieClockSetup"
password: "setup1234"
# WLAN-Zugangsdaten über Weboberfläche einstellbar
captive_portal:
web_server:
port: 80
# OTA-Updates
ota:
platform: esphome
# Logging für Debugging
logger:
# GPIOs für das Schieberegister
output:
- platform: gpio
pin: GPIO23
id: data_pin
- platform: gpio
pin: GPIO18
id: latch_pin
- platform: gpio
pin: GPIO5
id: clock_pin
# WS2812-LED-Steuerung
light:
- platform: fastled_clockless
chipset: WS2812
pin: GPIO19
num_leds: 4
rgb_order: GRB
name: "Nixie LEDs"
# Internetzeit abrufen
time:
- platform: sntp
id: sntp_time
on_time:
- seconds: 0
minutes: /1
then:
- lambda: |-
auto now = id(sntp_time).now();
id(display_driver)->update_time(now.hour, now.minute);
custom_component:
- id: display_driver
lambda: |-
auto *driver = new DisplayDriver(id(data_pin), id(clock_pin), id(latch_pin));
App.register_component(driver);
return driver;
binary_sensor:
- platform: status
name: "Nixie Clock Status"
sensor:
- platform: uptime
name: "Betriebsstunden"
unit_of_measurement: "h"
filters:
- multiply: 0.00027778
text_sensor:
- platform: wifi_info
ip_address:
name: "IP-Adresse"
ssid:
name: "WLAN-SSID"