# Sinara 8451 Thermostat

* [Wiki](https://github.com/sinara-hw/Thermostat/wiki)
* [Firmware](https://git.m-labs.hk/M-Labs/thermostat)

## Setup

Attach Ethernet and Micro-USB cables and run:

```shell
git clone gitea@git.m-labs.hk:M-Labs/thermostat.git
cd thermostat
nix develop
nix-shell -p gcc-arm-embedded-10 rlwrap
cargo build --release
arm-none-eabi-objcopy -O binary target/thumbv7em-none-eabihf/release/thermostat thermostat.bin
# turn on Thermostat
rlwrap nc -vv 192.168.1.26 23
# enter `dfu` command end exit rlwrap
dfu-util -a 0 -s 0x08000000:leave -D thermostat.bin
```

Then check that fans are working properly.
You may also check fan controls via `fan` commands (see the firmware documentation).

## Test PID

1. For Zotino: connect 10-pins IDC 2.54mm FC cable from internal Thermostat connector to the Zotino TEC
2. General TEC: connect external connector to the TEC
3. Connect Ethernet and PSU
4. Run:
   ```shell
   git clone gitea@git.m-labs.hk:esavkin/thermostat.git
   cd thermostat
   git checkout zotino-tec
   nix develop
   python pytec/tec_qt.py
   ```
5. In `Output Config`, set limits: 
   * `Max Cooling Current` - 400 mA
   * `Max Heating Current` - 400 mA
   * `Max Voltage Difference` - 1 V
6. `PID Config` -> `PID Auto Tune` set desired target temperature, which should be slightly above your room temperature (+10C)
7. Set `Thermistor Config` -> `B` and other values, according to the datasheet of the TEC module, for example for Zotino `B` is `3455 K`
8. Run `PID Config` -> `PID Auto Tune` -> `Run` and check graphs that the measured temperature goes to the target temperature, 
   and eventually stabilizes at +- 0.01 of the target

## Common problems

### Thermostat doesn't connect or doesn't enter DFU mode

Carefully take out Thermostat from its protective box, unscrewed all screws before. Apply jumper and power on the Thermostat.
Now it should be in DFU mode.