Coder Social home page Coder Social logo

esphome-component-ds1302's Introduction

esphome-component-ds1302

A ds1302 component for esphome. This is a drop-in replacement of ds1307. The driver was ported from esp-idf-lib.

Usage

See Time component.

# import the component from GitHub
external_components:
  - source:
      type: git
      url: https://github.com/trombik/esphome-component-ds1302
    components:
      - ds1302

esphome:
  name: example-esp8266
  on_boot:
    then:
      ds1302.read_time:

time:
  - platform: ds1302
    id: ds1302_time
    # on some modules, CS is labeled as RST
    cs_pin: D8
    dio_pin: D7
    clk_pin: D5
    update_interval: never

  # a time source is required
  - platform: sntp
    id: sntp_time
    on_time_sync:
      then:
        ds1302.write_time:

Status

  • Works on esp8266 and esp32

Examples

See examples under config.

Logs

esp8266

[I][logger:243]: Log initialized
[17:59:11][C][ota:465]: There have been 0 suspected unsuccessful boot attempts.
[17:59:11][I][app:029]: Running through setup()...
[17:59:11][C][ds1302:055]: Setting up DS1302...
[17:59:11][D][ds1302:131]: Read  10:58:54 2022-10-11  CH:OFF RS:0 DS:OFF TCS:0
[17:59:11][D][time:041]: Synchronized time: 2022-10-11 17:58:54
[17:59:11][C][display.tm1637:128]: Setting up TM1637...
[17:59:11][C][wifi:037]: Setting up WiFi...

... snipped WiFi logs ...

[17:59:20][C][ota:089]: Over-The-Air Updates:
[17:59:20][C][ota:090]:   Address: example-esp8266.local:8266
[17:59:20][C][ota:093]:   Using Password.
[17:59:20][C][api:025]: Setting up Home Assistant API server...
[17:59:20][C][sntp:025]: Setting up SNTP...
[17:59:20][I][app:062]: setup() finished successfully!
[17:59:20][D][sntp:074]: Synchronized time: 2022-10-11 17:59:02
[17:59:20][D][ds1302:145]: Write 10:59:02 2022-10-11  CH:OFF RS:0 DS:OFF TCS:0
[17:59:20][I][app:102]: ESPHome version 2022.9.1 compiled on Oct 11 2022, 17:50:36
[17:59:20][C][wifi:502]: WiFi:

... snipped WiFi logs ...

[17:59:20][C][logger:275]: Logger:
[17:59:20][C][logger:276]:   Level: DEBUG
[17:59:20][C][logger:277]:   Log Baud Rate: 115200
[17:59:20][C][logger:278]:   Hardware UART: UART0
[17:59:20][C][ds1302:074]: DS1302:
[17:59:20][C][ds1302:075]:   Pin CS: GPIO15
[17:59:20][C][ds1302:076]:   Pin CLK: GPIO14
[17:59:20][C][ds1302:077]:   Pin DIO: GPIO13
[17:59:20][C][ds1302:078]:   Timezone: '<+07>-7'
[17:59:20][C][display.tm1637:138]: TM1637:
[17:59:20][C][display.tm1637:139]:   Intensity: 5
[17:59:20][C][display.tm1637:140]:   Inverted: 0
[17:59:20][C][display.tm1637:141]:   Length: 4
[17:59:20][C][display.tm1637:142]:   CLK Pin: GPIO5
[17:59:20][C][display.tm1637:143]:   DIO Pin: GPIO4
[17:59:20][C][display.tm1637:144]:   Update Interval: 0.5s
[17:59:20][C][mdns:094]: mDNS:
[17:59:20][C][mdns:095]:   Hostname: example-esp8266
[17:59:20][C][ota:089]: Over-The-Air Updates:
[17:59:20][C][ota:090]:   Address: example-esp8266.local:8266
[17:59:20][C][ota:093]:   Using Password.
[17:59:20][C][api:138]: API Server:
[17:59:20][C][api:139]:   Address: example-esp8266.local:6053
[17:59:20][C][api:143]:   Using noise encryption: NO
[17:59:20][C][sntp:050]: SNTP Time:
[17:59:20][C][sntp:051]:   Server 1: '0.pool.ntp.org'
[17:59:20][C][sntp:052]:   Server 2: '1.pool.ntp.org'
[17:59:20][C][sntp:053]:   Server 3: '2.pool.ntp.org'
[17:59:20][C][sntp:054]:   Timezone: '<+07>-7'
[17:59:20][C][debug:049]: Debug component:
[17:59:20][D][debug:061]: ESPHome version 2022.9.1
[17:59:20][D][debug:065]: Free Heap Size: 40008 bytes
[17:59:20][D][debug:093]: Flash Chip: Size=4096kB Speed=40MHz Mode=DOUT
[17:59:20][D][debug:250]: Chip ID: 0x000CB68D
[17:59:20][D][debug:251]: SDK Version: 2.2.2-dev(38a443e)
[17:59:20][D][debug:252]: Core Version: 3.0.2
[17:59:20][D][debug:253]: Boot Version=6 Mode=1
[17:59:20][D][debug:254]: CPU Frequency: 80
[17:59:20][D][debug:255]: Flash Chip ID=0x0016405E
[17:59:20][D][debug:256]: Reset Reason: External System
[17:59:20][D][debug:257]: Reset Info: External System

Notes

With esphome version 2022.9.1 as of this writing, esphome compile fails when the MCU is esp8266. See a workaround at Issue #3348. As such, esphome/components/time/automation.cpp must be patched. See how in the tox.ini.

esphome-component-ds1302's People

Contributors

fatbeard avatar trip5 avatar trombik avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

fatbeard trip5

esphome-component-ds1302's Issues

Error compiling package with ds1302 component

Getting this error compiling a package..

INFO ESPHome 2023.10.6
INFO Reading configuration /config/esphome-web-266e3c.yaml...
INFO Detected timezone 'Etc/UTC'
INFO Generating C++ source...
INFO Compiling app...
Processing esphome-clock (board: nodemcuv2; framework: arduino; platform: platformio/[email protected])

HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- ESPAsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.4
|-- Wire @ 1.0
Compiling .pioenvs/esphome-clock/src/esphome/components/ds1302/ds1302.cpp.o
Compiling .pioenvs/esphome-clock/src/esphome/components/font/font.cpp.o
Compiling .pioenvs/esphome-clock/src/esphome/components/i2c/i2c.cpp.o
Compiling .pioenvs/esphome-clock/src/esphome/components/i2c/i2c_bus_arduino.cpp.o
src/esphome/components/ds1302/ds1302.cpp: In member function 'void esphome::ds1302::DS1302Component::read_time()':
src/esphome/components/ds1302/ds1302.cpp:103:9: error: 'ESPTime' is not a member of 'esphome::time'; did you mean 'esphome::ESPTime'?
103 | time::ESPTime rtc_time{.second = uint8_t(ds1302_.reg.second + 10 * ds1302_.reg.second_10),
| ^~~~~~~
In file included from src/esphome/components/time/real_time_clock.h:8,
from src/esphome/components/ds1302/ds1302.h:32,
from src/esphome/components/ds1302/ds1302.cpp:34:
src/esphome/core/time.h:12:8: note: 'esphome::ESPTime' declared here
12 | struct ESPTime {
| ^~~~~~~
src/esphome/components/ds1302/ds1302.cpp:112:3: error: 'rtc_time' was not declared in this scope; did you mean 'read_time'?
112 | rtc_time.recalc_timestamp_utc(false);
| ^~~~~~~~
| read_time
*** [.pioenvs/esphome-clock/src/esphome/components/ds1302/ds1302.cpp.o] Error 1
========================== [FAILED] Took 9.27 seconds ==========================

YAML is:

esphome:
name: esphome-clock
friendly_name: ESPHome-clock
on_boot:
then:
ds1302.read_time:

esp8266:
board: esp01_1m

logger:

api:
encryption:
key: "xxxx="

ota:

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

ap:
ssid: "esphome-clock"
password: !secret ap_password

captive_portal:

time:

  • platform: ds1302
    id: ds1302_time

    cs is rst

    cs_pin: GPIO0
    dio_pin: GPIO2
    clk_pin: GPIO14
    update_interval: never

time source

  • platform: sntp
    timezone: America/Toronto
    id: sntp_time
    on_time_sync:
    then:
    ds1302.write_time:

i2c:
sda: 4
scl: 5
frequency: 400kHz

font:

  • file:
    type: gfonts
    family: JetBrains+Mono
    weight: 100
    id: font1
    size: 26

external_components:

display:

  • platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    contrast: 100%
    lambda: |-
    auto time = id(ds1302_time).now();
    if (time.is_valid()) {
    it.strftime(it.get_width() / 2 - 2, it.get_height() / 2 - 2, id(font1), TextAlign::CENTER, "%I:%M %p", id(ds1302_time).now());
    }

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.