Coder Social home page Coder Social logo

tg9541 / w1209 Goto Github PK

View Code? Open in Web Editor NEW
31.0 5.0 12.0 118 KB

W1209 data logging thermostat with an STM8 eForth interactive console

Home Page: https://github.com/TG9541/W1209/wiki

License: MIT License

Makefile 9.87% Forth 61.44% Assembly 28.68%
w1209 stm8 thermostat firmware stm8-eforth forth logging

w1209's Introduction

W1209 Data-Logging Thermostat

Travis-CI

This project uses STM8 eForth to turn the off-the-shelf board W1209 into a data logging thermostat with a console interface and an embedded programming environment. It provides source code, a ready-to-use firmware, and documentation.

w1209

Features are:

  • a heating thermostat, e.g. for a chicken egg incubator
  • no special tool installation necessary
    • ready-made binaries, and source code, are provided
    • new binaries can be built with the help of Travis-CI (or locally on your Linux machine)
    • interactive programming in Forth, even while the thermostat task is running!
    • any serial terminal program can be used, e.g. picocom, cutecom, or e4thcom
  • data logger with a 144 entry ring-buffer, a 0.1h to 10h intervall, and log access through the serial console
    • L.dump command prints the log through the serial console - the last line is the latest entry
    • L.wipe command erases the log memory
    • records lowest and highest temperature
    • records the number of relay cycles and the heating duty cycle
  • detection of "sensor disconnected failure"
  • easy to use parameters menu for set-point, hysteresis, and trip-delay

This is work in progress although it's feature-complete. Please consider the software "beta" (please write an issue if you need support or want to give feedback :-) ).

Possible future features:

  • a simple "field-bus" for building a network of thermostat units
  • more fail-safe features (e.g. parameter integrity, limits monitoring)

Please note that implementing new features may require using a more compact STM8 eForth build, or removing existing features. The STM8 eForth modular-build feature makes that easy.

With minor modifications the code can be used for other generic thermostat boards for which STM8s eForth support exists. Other boards can be added with the help of modular-build. The code can also be used for non-interactive thermostats, e.g. using a C0135 Relay Board.

Getting Started

Note: STM8 eForth only works on supported STM8 chips - W1209 boards with a Nuvoton chip will have to be modified before they can be used with the code in this repository!

512 of the 576 bytes logging buffer rely on an undocumented STM8S003F3P6 feature which might not work in some chips. Although there are no known cases of where the extended EEPROM didn't work, using an STM8S103F3P6 chip or reducing the logging buffer to 64 bytes will always work.

After programming the firmware binary to the W1209 board, it should work as normal thermostat. Parameters can be set using the board keys (set, +, -).

The following items are recommended for programming:

W1209 ST-Link programmer TTL-Serial-Interface
W1209 Programmer TTL-Serial

Please refer to the STM8 eForth Wiki for instructions on programming the W1209 using an ST-Link compatible programmer.

After programming, the display should show the temperature value (in °C), or .dEF. (default) if no sensor is connected).

Before using the thermostat, please reset the parameter values by holding the keys + and - until the text rES. appears on the LED display (about 4s). Pressing the set key leads to the parameter menu. The menu returns to the temperature display when no key is pressed for more than 10s.

The software currently supports the following parameters:

Display Range Default Unit Description
SEt. 10.0 - 80.0 37.5 °C Heating thermostat set point (switch off above)
LoG. 0.0 - 10.0 10.0 h Logger interval in hours
dEL. 0.0 - 60.0 0.0 s thermostat heating trip delay
Cor. -2.0 - 2.0 0.0 °C thermometer offset (for corrections around desired set-point)
hYS. 0.1 - 2.0 0.5 °C thermostat hysteresis (difference between the lower and the upper trip points)

Note that in most cases hanging the trip delay parameter dEL. should not be required.

Using the Data Log

The data logger feature uses the upper 576 bytes of the internal EEPROM as a 144 entry ring-buffe. The logger interval (time between samples) can be defined in the range from 6 minutes (0.1h) to 10h by the menu item LoG..

The following items are recorded:

  • Lowest temperature
  • Highest temperature
  • Heating duty cycle DC = 100% * t.on/(t.on + t.off)
  • Number of relay cycles

The data log can be accessed through the Forth console with the command L.dump. The log can be wiped with the command L.wipe. To use the Forth console, connect a serial interface adapter to the + and - key pins.

The following chart demonstrates the influence of insulation improvements, a hysteresis parameter change, and the effect of heating temperature setback overnight in my living room:

w1209-log2

Such a chart can be created with the following steps:

  • set the log interval according to the required observation time
    • 0.1h for control optimization
    • e.g. 3.5h for the 3 weeks that it takes to hatch a chicken egg
  • let the thermostat run (no intervention required)
  • connect a TTL-RS232 interface to the keys + (RX) and - (TX) (pins next to the LED display)
  • access the console with a serial terminal program with the settings "9600-N-8-1"
    • for Linix e.g. e4thcom, minicom, picoterm, or miniterm.py
    • for Windos e.g. miniterm.py, PuTTY, Hyperterminal
    • press the ENTER key - STM8 eForth should respond with ok
  • type L.dump to extract the data (note: the last line is "now")
  • take a note of the read out time, and the log interval)
  • copy and paste the data to a spread sheet program
  • use the known read-out time, and the log intervall for the time in the x-axis of an x/y chart

The Thermostat Controller

control.fs implements a very simple 2-point controller with hysteresis, and delay. There is no other reason for either of the parameters other than they can be used for mitigating noise, which the sensor measurement already takes care of.

In future versions it may be replaced by a simple PI controller, where the relay duty cycle is the control variable.

Working with the Code in this Repository

Clone this repository, an run make depend for dependency resolution. This will download an STM8 eForth binary, and add required folders, files, and symlinks.

The general workflow for set-up is this:

  • clone the repository
  • install stm8flash
  • connect a ST-LINK-V2 dongle to a W1209
  • run make defaults to wipe the stock firmware
    • warning: there is no known public source for the stock firmware, and after erasing it there is no way back!
  • run make to flash the STM8EF binary
  • for interactive scripting install e4thcom
  • optionally install the development version of ucSim (or use the Docker image) to take advantage of off-line image creation

For programming the W1209 binary please follow the instructions in the STM8EF Wiki page for board W1209 (if stm8flash is installed just run make flash).

Interactive scripting through the serial console is supported by the STM8 eForth base binary. Please refer to the instructions for getting a serial console.

The recommended terminal emulator is e4thcom: it supports line editing, and upload of source files with #include, and using a library with #require. Type #i main.fs to load the complete source code.

For Continuous Integration use cases make simload applies ucSim to create an STM8 binary file that contains the full thermostat script, including the W1209-FD base image. The Docker image tg9541/docker-sdcc contains tool dependencies for Continuous Integration (refer to .travis.yml or use the Travis-CI badge to browse the execution log).

About the STM8 eForth Base System

The code is based on the STM8EF binary release. The Makefile uses the "modular build" method to automatically build a binary for the board support folder W1209-FD.

Please refer to the STM8EF Wiki for more information.

Contributing

This is a community projecy - it's driven by user contributions!

Please write an issue if you have questions, post a comment in the HACKADAY.IO project, or contribute docs, code, new use-cases and requirements.

Also consider writing about it in forums, blogs, on Twitter, or make a YouTube video in your native language, so that others can find it (please use #W1209 and #STM8EF hashtags).

Commercial Use

The code in this repository can be used for commercial applications in compliance with to the license conditions.

w1209's People

Contributors

tg9541 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

w1209's Issues

flashing problem

Hi. I have a W1209 with STM8S003F3P6 on board. After the successful flashing I am stuck with the "4th" display. Long pressing "set" has no effect.

I ran

make clean
make BOARD=W1209 flash -- display shows 4th

with output:

stm8ef-2.2.23$ make BOARD=W1209 flash
mkdir -p out/W1209
sdasstm8 -I. -I./W1209 -I./inc -plosgffw out/W1209/forth.rel forth.asm
sdcc -mstm8 -I./W1209 -I./inc -oout/W1209/W1209.ihx main.c out/W1209/forth.rel
mkdir -p out/W1209/target
rm -f out/W1209/target/*
rm -f target
ln -s out/W1209/target/ target
awk -f tools/genalias.awk -v target="out/W1209/target/" out/W1209/forth.rst
awk -f tools/genconst.awk -v target="out/W1209/target/" out/W1209/forth.rst
stm8flash -c stlinkv2 -p stm8s003f3 -w out/W1209/W1209.ihx
Determine FLASH area
Due to its file extension (or lack thereof), "out/W1209/W1209.ihx" is considered as INTEL HEX format!
5194 bytes at 0x8000... OK
Bytes written: 5194

To me that looks good. I also tried (after make clean) W1209-FD with the same result. W1209-CA puts garbage on the display.

I'm a bit unsure about the voltage to give the board from the stlinkv2: 3.3V or 5V? I have read both somewhere. I tried both anyhow.

Should the setting work when powered only thought the stlinkv2? I do I need to swap to 12V? Tried disconnecting the stlinkv2 and connect 12V but I got no further than "4th"

Flashing W1209-0.2.1 results in the same, I only get the "4th" display. I guess stm8ef-2.2.23 is just the forth environment. W1209-0.2.1 is the temperature logger??

Changing the makefile from stm8s103f3 to stm8s003f3 has no effect. But I can't figure out how to do a full compile (I have a working sdcc)

I have the feeling I am missing something basic here :(

W1209-0.2.1$ make
if [ ! -d "out" ]; then \
        curl -# -L -O https://github.com/TG9541/stm8ef/releases/download/2.2.20/stm8ef-bin.zip; \
        unzip -q -o stm8ef-bin.zip -x out/*; \
        unzip -q -o stm8ef-bin.zip out/W1209-FD/*; \
        rm stm8ef-bin.zip; \
fi
#################################################################################################################################################################### 100,0%#################################################################################################################################################################### 100,0%
stm8flash -c stlinkv2 -p stm8s003f3 -w out/W1209-FD/W1209-FD.ihx
Determine FLASH area
Due to its file extension (or lack thereof), "out/W1209-FD/W1209-FD.ihx" is considered as INTEL HEX format!
5241 bytes at 0x8000... OK
Bytes written: 5241

Thanks for any pointers.
Martin

Need binary .ihx file for W1209 with modified .fs source files

Hello Thomas,

As suggested I am opening an issue here to start the modifications required to the W1209 source files prior to doing a Travis CI build to get a binary that I can flash to my W1209.

I have a Travis CI account now which runs either from my Safari web browser or from Terminal on my MacBook Pro running macOS Mojave 10.14.2.

Best regards,

Paul

I'm new at this

I am not a programmer but I learn quickly, my question is can the w1209 be used with a 100k thermoistor and in crease the temperature range? I have a few from other projects but can seem to find suitable hardware to do the job I need

Non-issue: Pictures

Issues can store pictures which can be linked in the Wiki. Let's use this issue for that!

Output for "overheat" protection.

The original W1209 firmware has a configurable overheat protection that shuts off the relay when the temp rises above a set value. I'd like to create a similar feature that, rather than shutting off the relay, signals an external MCU when the set temp is reached. The easiest would be to toggle a GPIO low/high, however it doesn't appear there are any GPIO's available. So I was wondering if a command could be sent over serial instead? Any input appreciated, thanks!

Make dig2tem configurable

Some W1209 boards have a value of R2 (the reference resistor for the NTC) of e.g. 5k1 instead of 20k.

By preloading dig2tem to NVM before loading main.fs board specific adjustments can be done.

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.