Skip to content

Board W1401

Thomas edited this page Dec 23, 2018 · 26 revisions

W1401 Thermostat module

The (XH-)W1401 is a "hackable" thermostat with I/O and UI elements (analog input, relay, display, keys, buzzer) which can be re-programmed for simple automation tasks, e.g. monitoring, timing, or control. It's not much more expensive than a W1209, at a retail price starting from about $2.30. The relay is rated 250VAC, and, unlike other thermostats, the PCB design looks good enough to actually consider using it for switching mains voltage.

The board has three 2-digit 7S-LED displays without decimal point, however, retrofitting the DP is possible.

Note: since the beginning of the year 2018, in many [products|STM8S Value Line Gadgets]], STM8S003F3P6 controllers were replaced with a Nuvoton MCS51 chip which is compatible at a pin function level but not on the software level. In that case retrofitting an STM8Sx03F3P6 chip is required for using STM8 eForth. If you buy such a variant of this board please provide feedback through GitHub Issues!

The board has the following features:

  • STM8S003F3P6
  • 3x2 digit 7S-LED display with 74HC164 as a segment driver
  • 4 keys
  • 2 LEDs
  • relay (rated 250VAC)
  • buzzer
  • sensor header with 20k pull-up (for 10k NTC)

XH-W1209-front

W1401 Board Support

Starting from release STM8 eForth v2.2.7 the source code in the master branch is ready for applications, and there is a W1401 HEX binary in the releases section.

STM8 eForth currently supports the following board features:

  • 2-wire serial interface through PD1/SWIM
  • 7S-LED through vectored I/O (auto-off with time delay while the serial interface is active)
  • board keys through vectored I/O
  • relay/red LED, and green LED through OUT!
  • buzzer with programmable pitch (BEEP_CSR HW-register)
  • read sensor input (e.g. 5 ADC! ADC@)

Some more information is available on the STM8 eForth log on Hackaday.io.

Board UI Character Input

The 4 keys are mapped as follows:

Key ?KEYB BKEY
"⇧ START" "A", 65 0x01
"START ⇩" "B", 66 0x02
"⇧ STOP" "D", 68 0x04
"STOP ⇩" "H", 72 0x08

Pressing multiple keys leads to an ASCII code corresponding to the value of the bit-field (e.g. "SET" and "-" result in the numeric code 69 (0x45) or ASCII "E".

Please refer to the W1209 Pulse Generator code for a simple demonstration of the key input features.

Board UI Character Output

The W1401 board provides 4 keys and 3 two digit 7S-LED displays. The usage of keys is very similar to that explained in the W1209 UI section.

The LED display is organized in right-aligned 2-digit groups that each work similar to the display of a pocket calculator. SPACE switching between the groups works, and CR moves to the leftmost group.

The following code displays different data (all scaled to a range of 0..99) on the 3x2 digit 7S-LED groups of the board W1401:

: timer TIM 655 / ;
: ain 5 ADC! ADC@ 100 1023 */ ;
: show timer . ain . BKEY . CR ;
' show bg !

The word show displays the values scaled to 0..99 from the BG timer, the sensor analog input, and the board key bitmap BKEY followed by a CR (new line). When the word show runs in the background, it displays the ticker on the left yellow 7S-LED group, ain on the middle red LEDs, and the board key bitmap on the right yellow group.

The 7S-LED group feature simplifies the usage of 7S-LED display groups (see issue #20 for details).

Board Digital Outputs

The relay/red LED and the green LED are mapped to bits B0 and B1 of the OUT! word and OUT register. The following code shows how to set relay and green LED:

1 OUT! \ relay and red LED on, green LED off
2 OUT! \ relay and red LED off, green LED on
3 OUT! \ relay and and red LED on, green LED on

Beeper

The beeper is connected to the PD4/BEEP GPIO, and hence the frequency can be controlled through the BEEP_CSR register.

The following code gives an example:

: BEEP_CSR $50F3 ;
: beep $A0 OR BEEP_CSR C! ;
: annoy TIM 100 / 10 MOD 20 + beep ;
: silence 0 BG ! 31 beep ;
' annoy BG !

You'll find that the beeper is quite effective (enter silence to stop it).

Serial Console

The board support provides half-duplex console access through PD1/SWIM on the ICP header. Please note that PD1 also is the clock pulse for the 7S-LED column shift register, and that up to 2 seconds after a serial transmissions the LED display is blanked to improve robustness of the communication.

The half-duplex interface is designed to work with e4thcom, or with the example Picocom configuration for half-duplex communication described here.

The following sketch shows how to connect a serial interface adapter using the SWIMCOM method:

................  
  XH-W1401     .
               .      .----o serial TxD "TTL"
       ( )     .      |      e.g. "PL2302 USB serial converter"
               .     ---
               .     / \  1N4148 
VCC ------<4>  .     ---  
               .      |
PD1/SWIM--<3>--.------*----o serial RxD "TTL"
               .
NRST------<2>  .
               .
GND-------[1]--.-----------o serial GND
               .     
ICP header     . 

Note: the W1401 assigns GND to pin 1, which is an unusual feature.

W1401 Hardware Description

The XH-W1401 thermostat module uses PD1 to clock a 74HC164 shift register. Using GPIO PD1/SWIM for 4 tasks (SWIM for flashing, half-duplex RX and TX) in the board support was a bit complicated, but it works reliably: to make the serial interface work together with the LED display the shift register clock pulses had to be very short compared to the serial interface bit time. The board support code implements a 64ns clock pulse, which most serial interface devices will filter out. It's also possible to use a simple RC filter (e.g. 47R/10nF) to hide the pulses from UARTs with insufficient noise filter characteristics. The board support code, however, uses one more work-around: blanking the display during serial communication.

The capacitor connected to NRST (C7) is over-sized and ICP (in circuit programming) might fail. However, programming through SWIM is possible even if NRST isn't connected (SWIM only mode like in the STM8S001J3 which requires two attempts for programming).

XH-W1209-back

STM8S003F3P6:

The µC pins are connected as follows:

Pin	STM	Connected to
1	PD4     R3-Q1 (-> BEEP_CSR)
2	PD5	Ain sensor connector (Vdd - 20k - pin2 pin1 - (C - VSS) - AIN5)
3	PD6	Key "Start v"
4	NRST	ICP header pin 3
5	PA1	Key "Stop ^"
6	PA2	R-Q5 (relay, LED red)
7	VSS	GND
8	Vcap	Cap
9	VDD	5.0V
10	PA3	Key "Stop v"
11	PB5	/LED green
12	PB4	Key "Start ^"
13	PC3	Dig2 L3621.5
14	PC4	Dig3 L5621.8
15	PC5	74HC164 DSA-DSB
16	PC6	Dig6 L3621.5
17	PC7	Dig1 L3621.10
18	PD1	74HC164 CLK, ICP header pin2
19	PD2     Dig5 L3621.10
20	PD3	Dig4 L5621.7

3621Bx and 5621Bx 7S-LED Displays

The 7S-LED displays are of common anode type. The exact type of displays may differ (compatible LED displays with a different color may be used). My samples have 9mm yellow displays marked ZT21036.Y, and a red 14mm center display marked ZT210501R7.3.

Dig1 L3621.10 STM8S.17 PC7
Dig2 L3621.5  STM8S.13 PC3
Dig3 L5621.8  STM8S.14 PC4
Dig4 L5621.7  STM8S.20 PD3
Dig5 L3621.10 STM8S.19 PD2
Dig6 L3621.5  STM8S.16 PC6

74HC164 and LED segments

Only 7 bits of the shift register are used, the decimal point (DP) isn't connected.

1  DSA STM8.15 PC5
2  DSB-DSA
3  Q0 R5 L3621.3, L5621.10 segment A
4  Q1 R6 L3621.9, L5621.9 segment B
5  Q2 R8 L3621.8, L5621.1 segment C
6  Q3 R9 L3621.6, L5621.4 segment D
7  GND
8  CLK STM8.18 PD1/SWIM
9  /MR (+VCC)
10 Q4 R10 L3621.7, L5621.3 segment E
11 Q5 R11 L3621.4, L5621.6 segment F
12 Q6 R12 L3621.1, L5621.5 segment G
13 Q7 (can be wired to DP)
14 VCC

Note: the DP segment isn't connected, but it's possible to hand-wire 74HC164 pin 13 to pin2 of the L5621 and L3621 7S-LED displays.

Clone this wiki locally