Goal of this work
The standard Tasmota software does not allow setting the GPIO pins for controlling the TM1637 display module. This because it simply does not contain this feature by default. We have to build our own firmware.
Folder structure
I have my own private gitlab running at https://gitlab.vanderwulp.be, in which I created a project “/domotica/co2-sensor-tm1637”.
And I do my development in this folder ~/development/, where everything is sorted by repository location;
in this case: ~/development/gitlab.vanderwulp.be/.
Hence, we go to this folder and clone this project - see below. This creates the following folder:
~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/
Getting the project set up: repo and Platformio
First, we clone the gitlab project, and go into the project folder. The we activate Platformio with the “get_pio” alias, as explained in my blog.
michiel@Delphinus:~/development/gitlab.vanderwulp.be> git clone http://gitlab.vanderwulp.be/domotica/co2-sensor-tm1637.git
Cloning into 'co2-sensor-tm1637'...
warning: redirecting to https://gitlab.vanderwulp.be/domotica/co2-sensor-tm1637.git/
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 33 (delta 0), reused 0 (delta 0), pack-reused 30 (from 1)
Receiving objects: 100% (33/33), 726.72 KiB | 16.15 MiB/s, done.
Resolving deltas: 100% (8/8), done.
michiel@Delphinus:~/development/gitlab.vanderwulp.be> cd co2-sensor-tm1637/
michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637> get_pio
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637>
The “(penv)” in the CLI prompt indicates that we are in the Platformio virtual environment, i.e. Platformio is available.
Get the Tasmota source as git submodule
We need the Tasmota source, to be able to compile it. Since the project folder is already managed by git, I did not know how to obtain the source without adding it to my repo. So, I tried to make it a submodule. See short explanation here and in the git-scm book.
The submodule system worked well, except that the Tasmota configuration files are ignored by the git of Tasmota, and also not part of the git of my repo. So, I had to copy these two files. Maybe there is a better way…
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637> git clone https://github.com/arendst/Tasmota.git
Cloning into 'Tasmota'...
remote: Enumerating objects: 140529, done.
remote: Counting objects: 100% (220/220), done.
remote: Compressing objects: 100% (94/94), done.
remote: Total 140529 (delta 181), reused 126 (delta 126), pack-reused 140309 (from 2)
Receiving objects: 100% (140529/140529), 241.77 MiB | 12.10 MiB/s, done.
Resolving deltas: 100% (98544/98544), done.
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637> git submodule add https://github.com/arendst/Tasmota.git Tasmota
Adding existing repo at 'Tasmota' to the index
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637> git commit -m "Add child submodule."
[main 341373c] Add child submodule.
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 Tasmota
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637> git push
...
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637> git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637>
Select the Platformio build environment
The default environment configuration can be used to easily generate Tasmota firmware variants (named “tasmota”, “sensors”, “display”, “tasmota32c3”, etc.). If you’re not sure which binary is the right one for you, consult the builds table or just start with “tasmota.bin”. To build and/or flash exactly one of these, use the Platformio -e command line argument (e.g., -e “tasmota32c3”) - or set it as the default environment.
Adapt the configuration: platformio_override.ini
I copied the platformio_override_sample.ini file to platformio_override.ini
michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota> cp platformio_override_sample.ini platformio_override.ini
michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota> vi platformio_override.ini
… and made these changes:
Select the ESP32-C3 as the default environment:
default_envs =
; tasmota
tasmota32c3
Remove an unused module:
; *** Audio needs a lot of time to compile. Mostly not used functions. Recommended to disable
; lib/lib_audio
The result is platformio_override.ini.
Adapt the configuration: my_user_config.h
I copied the tasmota/user_config_override_sample.h file to tasmota/user_config_override.h and made these changes
at the bottom of this file right before the last #endif:
#define USE_DISPLAY // Add I2C/TM1637/MAX7219 Display Support (+2k code)
#define USE_DISPLAY_TM1637 // [DisplayModel 15] Enable TM1637 Seven Segment Display Module (4-6 digits)
The above changes enable the code for the TM1637 display.
The result is user_config_override.h.
Compile
Once all the prerequisites are in place, compiling and uploading is one simple command. Execute this from within the Tasmota source code directory:
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota> pio run
Or, if you want to retain the build log:
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota> pio run 2>&1 | tee build.log
Upload with esptool via USB cable
Once all the prerequisites are in place, uploading is one simple command. Execute this from within the Tasmota source code directory:
pio run -t upload
This fails, due to python 3.6 not supported by esptool.
We need to go to python 3.11 - that is not so easy on OpenSuse Leap 15.6.
Update Python from 3.6 to 3.11 on openSUSE Leap 15.6
Let us try this tip on stackexchange.
Before attempting this, please read the excellent documentation.
So, I installed pyenv as root with
zypper install pyenv
This installed both pyenv and pyenv-bash-completion.
Then, as normal user, I needed to add some lines to the ~/.bashrc file - this can be done by pasting the following at the command line:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
Next I installed Python 3.11 and set it as the global default:
pyenv install 3.11
pyenv global 3.11
Finally, I had to reinstall platformio according https://michiel.vanderwulp.be/platformio-core-cli-installation-linux.html
This now finally worked:
michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota> get_pio
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota> python --version
Python 3.11.11
(penv) michiel@Delphinus:~/development/gitlab.vanderwulp.be/co2-sensor-tm1637/Tasmota>
2nd attempt: Upload with esptool via USB cable
Again, let’s upload the Tasmota firmware:
pio run -t upload
This works
Now we can set the TM1637 GPIO pins:
