Skip to content

Board W1401

Thomas edited this page Jan 21, 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 3 2-digit 7S-LED displays without decimal point, however, retrofitting the DP is possible.

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 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" (0x41) 0x01
"START ⇩" "B" (0x42) 0x02
"⇧ STOP" "D" (0x44) 0x04
"STOP ⇩" "H" (0x48) 0x08

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

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

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 demonstrates the group output feature:

: show 1 . 2 . 3 . CR ;
' show BG !

Running show from the command line results in 1 2 3<new line>. Running it in the background displays 1 in the leftmost 2-digit group, 2 in the middle, and 3 on the right group (all right aligned).

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, and using GPIO PD1/SWIM for 4 tasks (SWIM for flashing, half-duplex RX and TX) is a bit complicated. To make the serial interface work together with the LED display the shift register clock pulses are very short compared to the serial interface bit time. The board support code implements a 64ns clock pulse, which most serial interface devices filter out. It's also possible to use a simple RC filter (e.g. 47R/10nF) to hide the pulses from UARTs with different noise filter characteristics (e.g. the interrupt driven implementation in this project).

The capacitor connected to NRST (C7) is over-sized and ICP (in circuit programming) may fail. However, programming through SWIM is possible if NRST isn't connected (SWIM only).

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

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