# carlsans/t4max6675emu architecture

> Architecture diagram of the GitHub repository carlsans/t4max6675emu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/carlsans/t4max6675emu
- Repository: https://github.com/carlsans/t4max6675emu

## Overview

##### Project Type and Purpose
- This is an embedded‐firmware project: an Arduino sketch that polls two MAX6675 thermocouple‐to‐digital converter modules, reads temperature data, and streams it out over the serial port.
- The goal is to “emulate” or drive two MAX6675 sensors on a shared SPI bus, each with its own chip‐select line.

##### Main Components
A. Arduino Board (ATmega328P)
– Runs the doublemax6675.ino sketch
– Hosts digital I/O: SPI clock, data in, two CS lines, plus USB‐serial
B. MAX6675 Modules ×2
– Each module connects a K‐type thermocouple and converts to 12‐bit SPI data
C. K‐Type Thermocouples ×2
– Physical sensors feeding the MAX6675 modules
D. Shared SPI Bus
– SCK (clock), SO/MISO (data output), VCC (+5 V), GND
E. Separate Chip‐Select Lines
– CS1 (e.g. D2), CS2 (e.g. D3) on Arduino
F. USB‐Serial Interface
– Arduino’s built‐in converter streams readings to a host PC

##### Relationships & Data Flow
- At runtime, the Arduino toggles CS1 low → reads 16 bits from MAX6675 #1 over SO → raises CS1 → toggles CS2 low → reads from MAX6675 #2 → raises CS2.
- Parsed temperature values are sent via Serial.write/println over USB to a PC or terminal.
- Power (5 V) and Ground are common rails feeding the Arduino and both modules.

##### Architectural Patterns & Design Principles
- Bus multiplexing: a single SPI bus shared by multiple peripherals, each demarcated by its own CS.
- Polling loop: simple “read‐delay‐read‐delay” in loop() for real‐time sampling.
- Layer separation: hardware interface layer (pin toggling, SPI bit‐banging or hardware SPI), data processing layer (convert raw bits to °C), communication layer (serial output).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Power Rails"
        VCC["+5V"]:::power
        GND["GND"]:::ground
    end

    subgraph "Sensors Side"
        subgraph "MAX6675 Module #1"
            TC1["K-Type Thermocouple"] 
            MOD1["MAX6675 Module #1"] 
        end
        subgraph "MAX6675 Module #2"
            TC2["K-Type Thermocouple"] 
            MOD2["MAX6675 Module #2"] 
        end
    end

    Arduino["Arduino (ATmega328P)\nD2: CS1, D3: CS2\nD4: SCK, D5: SO\nD0/D1: USB-Serial\nloop(): read CS1 → read CS2 → Serial.print()"]:::mcu

    PC["Host PC / Serial Monitor"]:::pc
    README["README.md"]:::doc

    VCC --> MOD1
    VCC --> MOD2
    VCC --> Arduino
    GND --> MOD1
    GND --> MOD2
    GND --> Arduino

    MOD1 -->|"SCK"| Arduino:::spi
    MOD2 -->|"SCK"| Arduino:::spi
    MOD1 -->|"SO/MISO"| Arduino:::spi
    MOD2 -->|"SO/MISO"| Arduino:::spi

    Arduino -->|"CS1 (D2)"| MOD1:::cs
    Arduino -->|"CS2 (D3)"| MOD2:::cs

    Arduino -->|"TX/RX\n(USB-Serial)"| PC:::serial

    PC --> README

    click Arduino "https://github.com/carlsans/t4max6675emu/blob/main/doublemax6675.ino"
    click README "https://github.com/carlsans/t4max6675emu/blob/main/README.md"

    classDef power stroke:#ff0000,stroke-width:2px
    classDef ground stroke:#000000,stroke-width:2px
    classDef spi stroke:#0000ff,stroke-width:2px
    classDef cs stroke:#00aa00,stroke-width:2px
    classDef serial stroke:#ffa500,stroke-width:2px
    classDef mcu fill:#e0f7fa,stroke:#006064
    classDef pc fill:#f1f8e9,stroke:#33691e
    classDef doc fill:#f3e5f5,stroke:#6a1b9a
```
