-
Notifications
You must be signed in to change notification settings - Fork 66
Board W1401
The (XH-)W1401 is a "hackable" thermostat with I/O and UI elements (analog input, relay, display, keys, buzzer). It can be re-programmed for simple automation tasks, e.g. monitoring, timing, or control. It's widely available at a price as low as $2.30, about a dollar more than the W1209.
The board has 3 2-digit 7S-LED displays (without decimal point). If application doesn't require a 3 digit 7S-LED display STM8 eForth code that runs on a W1209 can be ported to the W1401 easily.
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
- 10k NTC temperature sensor header
Starting with release STM8EF 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.
The following board features are currently supported:
- 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 with
5 ADC! ADC@
Some more information is available on the STM8EF Hackaday.io log.
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 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).
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
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).
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.
An example picocom configuration for half-duplex communication is described here.
The following sketch shows how to connect a serial interface adapter using the SWIMCOM method:
XH-W1401 .
. e.g. "CH340 USB serial converter"
. .----o serial TxD "TTL"
. |
ICP header . ---
. / \ 1N4148
VCC ----------[1] ---
. |
PD1/SWIM------<2>-----*----o serial RxD "TTL"
.
NRST----------<3>
.
GND-----------<4>----------o serial GND
.
................
The XH-W1401 thermostat module uses PD1 to clock a 74HC164 shift register, and using the GPIO PD1/SWIM for 4 tasks (SWIM for flashing, half-duplex RX and TX) is a bit complicated. The solution is to make the LED shift register clock pulses very short compared to the serial interface bit time. The code implements a 64ns clock pulse, which a CH340 serial interface chip filters out, and it's also possible to use a simple RC filter (e.g. 47R/10nF) to hide it 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). I recommend either removal, or replacement with 100nF max.
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
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
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 NC
14 VCC
The DP segment isn't connected, but it's possible to hand-wire 74HC164 pin 13 to L5621 pin 2 and to both L3621 pin2.