Skip to content

Commit f470f34

Browse files
committed
First push
0 parents  commit f470f34

19 files changed

+827
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.vscode/
2+
build/
3+
dependencies.lock
4+
sdkconfig*

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# For more information about build system see
2+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3+
# The following five lines of boilerplate have to be in your project's
4+
# CMakeLists in this exact order for cmake to work correctly
5+
cmake_minimum_required(VERSION 3.16)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(esp_idf_tm1637_cpp_demo)
9+
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Demo Project: ESP-32 tm1637 driven LED library for the ESP-IDF
2+
3+
## Introduction
4+
5+
This is a demo project for a library to control TM1637 LED 7-segment display using the ESP-32 IDF toolchain [ESP-IDF](https://github.com/espressif/esp-idf).
6+
7+
Please note that this is actually a demo project. The actual library is in the components folder.
8+
9+
![Image](images/20240911_025121-crop.jpg "icon")
10+
11+
## Features
12+
13+
* Display numbers
14+
* Display raw segment data
15+
* Scrolling text
16+
* Simplified interface
17+
* C++ Implementation
18+
19+
20+
## Software required
21+
22+
esp-idf v5.1.2 or later.
23+
24+
# Installation
25+
26+
27+
```Shell
28+
git clone https://github.com/cfrankb/esp32-tm1637plus-cpp
29+
cd esp32-tm1637plus-cpp/
30+
idf.py set-target {esp32/esp32s2/esp32s3/esp32c3}
31+
idf.py menuconfig
32+
idf.py flash
33+
```
34+
35+
## Suggested wiring for the TM1637 LED display
36+
37+
| TM1637 | wirecolor | GPIO Pin |
38+
| -------- | --------- | ---------- |
39+
| CLK | white | 18 |
40+
| DIO | yellow | 19 |
41+
| GRN | black | GRN |
42+
| VCC | red | 3.3v or 5v |
43+
44+
45+
## Tested hardware
46+
47+
| Part # | Size | Pins |
48+
| -------- | --------- | ---------- |
49+
| 5643BS-1 | 0.56" | 12 |
50+
| 8041BS-1 | 0.80" | 12 |
51+
| 8401BS-1F| 0.80" | 14 |
52+
53+
54+
## Source Code
55+
56+
The source is available from [GitHub cfrankb/esp32-tm1637plus-cpp](https://github.com/cfrankb/esp32-tm1637plus-cpp).
57+
58+
## License / acknowledgement
59+
60+
The code in this project is licensed under the MIT license - see LICENSE for details.
61+
62+
Inital idea based on the Micropython implementation library, written by Mike Causer Copyright (c) 2016
63+
64+
The project is also based in part on this ESP-32 ESP-IDF library: https://github.com/petrows/esp-32-tm1637
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
sdkconfig.old
3+
sdkconfig
4+
*.swp
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
sudo: false
2+
language: bash
3+
4+
# when you suspects issues in cache, use the following line to disable cache.
5+
# cache: false
6+
cache:
7+
directories:
8+
- ${HOME}/distfiles
9+
- ${HOME}/.ccache
10+
- ${HOME}/.cache/pip
11+
os:
12+
- linux
13+
14+
matrix:
15+
include:
16+
- env:
17+
- PROJECT_TARGET="esp32"
18+
- PROJECT_SDK_BRANCH="master"
19+
- env:
20+
- PROJECT_TARGET="esp8266"
21+
- PROJECT_SDK_BRANCH="master"
22+
23+
addons:
24+
apt:
25+
packages:
26+
- gcc
27+
- wget
28+
- make
29+
- libncurses-dev
30+
- flex
31+
- bison
32+
- python
33+
- python-pip
34+
- gperf
35+
- ccache
36+
37+
before_install:
38+
# Save path to the git respository
39+
- PROJECT_PATH=$(pwd)
40+
41+
install:
42+
- export TOOLCHAIN_DIR="${HOME}/${PROJECT_TARGET}"
43+
- |
44+
if [ ${PROJECT_TARGET} == "esp8266" ]; then
45+
export PROJECT_GCC_PREFIX="xtensa-lx106-elf"
46+
export PROJECT_TOOLCHAIN_FILE=xtensa-lx106-elf-linux64-1.22.0-92-g8facf4c-5.2.0.tar.gz
47+
export PROJECT_SDK_NAME="ESP8266_RTOS_SDK"
48+
else
49+
export PROJECT_GCC_PREFIX="xtensa-esp32-elf"
50+
export PROJECT_TOOLCHAIN_FILE=xtensa-esp32-elf-gcc8_2_0-esp32-2019r1-linux-amd64.tar.gz
51+
export PROJECT_SDK_NAME="esp-idf"
52+
fi
53+
- export PROJECT_GCC_FILE="${PROJECT_GCC_PREFIX}-gcc"
54+
- export PROJECT_DISTFILE_DIR="${HOME}/distfiles"
55+
- export IDF_PATH=${TOOLCHAIN_DIR}/${PROJECT_SDK_NAME}
56+
- export PROJECT_LOG="${HOME}/build.log"
57+
- export PROJECT_EXAMPLE_DIR="${PROJECT_PATH}/examples"
58+
# Install ESP32 toochain following steps as desribed
59+
# in http://esp-idf.readthedocs.io/en/latest/linux-setup.html
60+
61+
# Prepare directory for the toolchain
62+
- mkdir -p ${TOOLCHAIN_DIR} ${PROJECT_DISTFILE_DIR}
63+
# Get SDK from github
64+
- git clone --branch ${PROJECT_SDK_BRANCH} --recursive https://github.com/espressif/${PROJECT_SDK_NAME}.git ${IDF_PATH}
65+
66+
# Setup ccache to build faster
67+
# XXX when the entire build process exceeds 50 min, th job will be killed
68+
# https://docs.travis-ci.com/user/customizing-the-build/#build-timeouts
69+
- ccache --version
70+
- mkdir ${HOME}/ccache_bin
71+
- (cd ${HOME}/ccache_bin && ln -s /usr/bin/ccache ${PROJECT_GCC_FILE})
72+
- export CCACHE_BASEDIR=$PROJECT_PATH
73+
- export CCACHE_CPP2=true
74+
75+
# Get Python requirements
76+
- python -m pip install --user --upgrade pyOpenSSL
77+
- python -m pip install --user -r ${IDF_PATH}/requirements.txt
78+
79+
# Download binary toolchain if it does not exist
80+
- |
81+
if [ ! -f ${PROJECT_DISTFILE_DIR}/${PROJECT_TOOLCHAIN_FILE} ]; then
82+
wget -O ${PROJECT_DISTFILE_DIR}/${PROJECT_TOOLCHAIN_FILE} https://dl.espressif.com/dl/${PROJECT_TOOLCHAIN_FILE}
83+
fi
84+
- tar -xz -C ${TOOLCHAIN_DIR} -f ${PROJECT_DISTFILE_DIR}/${PROJECT_TOOLCHAIN_FILE}
85+
86+
# Make toolchains available for all terminal sessions
87+
- export PATH=$HOME/ccache_bin:$PATH:$HOME/${PROJECT_TARGET}/${PROJECT_GCC_PREFIX}/bin
88+
89+
script:
90+
- rm -f ${PROJECT_LOG}
91+
# XXX surpress log output where possible. when the size exceeds 4 MB, the
92+
# job will be killed.
93+
- |
94+
IGNORE_FILE="travis-ignore"
95+
96+
case ${PROJECT_TARGET} in
97+
esp32)
98+
;;
99+
esp8266)
100+
IGNORE_FILE="travis-ignore-esp8266"
101+
# these drivers do not compile for ESP8266 yet
102+
export EXCLUDE_COMPONENTS="encoder max7219 mcp23x17"
103+
;;
104+
esac
105+
106+
cd ${PROJECT_EXAMPLE_DIR}
107+
for i in $(ls -d */); do
108+
if [ ! -e ${PROJECT_EXAMPLE_DIR}/${i}/${IGNORE_FILE} ]; then
109+
echo "Building ${i}..."
110+
cd ${PROJECT_EXAMPLE_DIR}/${i}
111+
make defconfig
112+
make -j2 >> ${PROJECT_LOG}
113+
if [ $? -ne 0 ]; then
114+
# when failed, show last 100 lines for debugging, and exit with
115+
# non-zero exit code
116+
tail -n 100 ${PROJECT_LOG}
117+
exit 1
118+
fi
119+
make clean >/dev/null
120+
# make sure the directory is clean
121+
rm -rf ${i}/sdkconfig ${i}/build
122+
fi
123+
done
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "tm1637plus.cpp"
2+
INCLUDE_DIRS "include"
3+
REQUIRES driver)

components/esp-32-tm1637plus/Kconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
menu "ESP TM1637"
2+
3+
config DELAY_BLOCKING_TIME
4+
int "Blocking time between clock pin changes"
5+
range 1 100
6+
default 10
7+
help
8+
This option allows you to configure the blocking time between changes
9+
of the clock pin in the ESP TM1637 module. The value represents the
10+
delay in microseconds (us) to be inserted between clock pin changes.
11+
Increasing the blocking time can help ensure reliable communication
12+
with the TM1637 module, especially in scenarios where the module may
13+
have difficulty keeping up with rapid clock changes. Adjust this value
14+
based on your specific requirements and the characteristics of your
15+
TM1637 module hardware. The range for this option is from 1 to 100 microseconds,
16+
with a default value of 50 microseconds.
17+
18+
config TM1637_BRIGHTNESS
19+
int "TM1637 LED brightness"
20+
range 0 7
21+
default 7
22+
help
23+
This option sets the init brightness level of the TM1637 LED module.
24+
The value should be between 0 (lowest brightness) and 7 (highest brightness).
25+
The default brightness value is 7 (highest brightness).
26+
27+
endmenu

components/esp-32-tm1637plus/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Mike Causer
4+
Copyright (c) 2018 Peto <[email protected]>
5+
Copyright (c) 2024 Francois Blanchette
6+
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ESP-32 tm1637 driven LED library for the ESP-IDF
2+
3+
## Introduction
4+
5+
This is an library of control TM1637 LED 7-segment display using ESP-32 IDF toolchain [ESP-IDF](https://github.com/espressif/esp-idf).
6+
7+
![Image](images/20240911_025121-crop.jpg "icon")
8+
9+
## Features
10+
11+
* Display numbers
12+
* Display raw segment data
13+
* Scrolling text
14+
* Simplified interface
15+
* C++ Implementation
16+
17+
18+
# Software required
19+
20+
esp-idf v5.1.2 or later.
21+
22+
# Installation
23+
24+
25+
```Shell
26+
git clone https://github.com/cfrankb/esp32-tm1637plus-cpp
27+
cd esp32-tm1637plus-cpp/
28+
idf.py set-target {esp32/esp32s2/esp32s3/esp32c3}
29+
idf.py menuconfig
30+
idf.py flash
31+
```
32+
33+
34+
35+
## Important notes
36+
37+
This library uses `ets_delay_us()` function to generate i2c-like control sequences. Please note - while using within FreeRTOS task will be blocked while data is transmitted.
38+
39+
40+
## Source Code
41+
42+
The source is available from [GitHub cfrankb/esp32-tm1637plus-cpp](https://github.com/cfrankb/esp32-tm1637plus-cpp).
43+
44+
## License
45+
46+
The code in this project is licensed under the MIT license - see LICENSE for details.
47+
48+
Inital idea based on the Micropython implementation library, written by Mike Causer Copyright (c) 2016
49+
50+
This project is also based in part on: https://github.com/petrows/esp-32-tm1637
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Use defaults
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-version: "1.0.0"
2+
description: ESP IDF implementation of the TM1637 LED 7-Segment display library
3+
url: https://github.com/cfrankb/esp32-tm1637plus-cpp
4+
dependencies:
5+
## Required IDF version
6+
idf:
7+
version: ">=5.0"
8+
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef __TM1637___H
2+
#define __TM1637___H
3+
#include <inttypes.h>
4+
#include <stdbool.h>
5+
#include <driver/gpio.h>
6+
#include <vector>
7+
8+
class TM1637
9+
{
10+
public:
11+
explicit TM1637(gpio_num_t pin_clk, gpio_num_t pin_dta);
12+
~TM1637();
13+
14+
static uint8_t encode_digit(const int digit);
15+
static uint8_t encode_char(const char o);
16+
static const std::vector<uint8_t> &encode_string(const char *s);
17+
static const std::vector<uint8_t> &hex(uint16_t val);
18+
static const std::vector<uint8_t> &number(uint16_t val);
19+
void brightness(const uint8_t val);
20+
uint8_t brightness();
21+
void write(std::vector<uint8_t> segments, int pos = 0);
22+
void show(const char *s, bool colon = false);
23+
void set_raw(const uint8_t pos, const uint8_t data);
24+
void set_char(const uint8_t pos, const char ch, const bool dot);
25+
void scroll(const char *s, int delay = 250);
26+
27+
private:
28+
gpio_num_t m_pin_dta;
29+
gpio_num_t m_pin_clk;
30+
uint8_t m_brightness;
31+
32+
void _delay();
33+
void _write_byte(uint8_t b);
34+
void _start();
35+
void _stop();
36+
void _write_data_cmd();
37+
void _write_dsp_ctrl();
38+
};
39+
40+
#endif

0 commit comments

Comments
 (0)