Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Checks

on:
pull_request:
push:
branches: [work, main]

jobs:
python:
name: Python syntax and parser smoke
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Compile GUI module
run: python -m py_compile gui/portable_avr_control_studio.py
- name: Parser smoke tests
run: |
python - <<'PY'
from gui.portable_avr_control_studio import parse_serial_line
assert parse_serial_line('OK,PING\n').kind == 'OK'
assert parse_serial_line('ERR,BAD,message\n').kind == 'ERR'
assert parse_serial_line('CONFIG,DEVICE_NAME=Unit,SENSOR_VREF_MV=5000\n').fields['SENSOR_VREF_MV'] == '5000'
assert parse_serial_line('STATUS,SENSOR_RAW=512,SENSOR_MV=2502\n').fields['SENSOR_MV'] == '2502'
assert parse_serial_line('DATA,INFO,protocol=2\n').fields['PROTOCOL'] == '2'
assert parse_serial_line('garbage\n').malformed
PY

avr-compile:
name: Arduino AVR Uno compile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Arduino CLI
uses: arduino/setup-arduino-cli@v2
- name: Install AVR core
run: |
arduino-cli core update-index
arduino-cli core install arduino:avr
- name: Compile Uno firmware
run: arduino-cli compile --fqbn arduino:avr:uno firmware/PortableAVRControlStudio
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__/
*.py[cod]
.pytest_cache/
build/
dist/
*.spec
9 changes: 9 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Repository Agent Instructions

This repository is a draft Portable AVR Control Studio project. Follow these rules for all files in this tree:

- Keep claims conservative: do not state or imply physical hardware testing unless a human has provided test evidence.
- Treat Arduino Uno / ATmega328P AVR as the primary firmware target unless a documented hardware profile says otherwise; Nano may be referenced only as a compatible secondary option.
- Keep customer-facing runtime settings aligned across firmware, GUI, README, and protocol docs.
- Unknown hardware must be handled through documented profiles, not automatic detection claims.
- Keep the GitHub PR as Draft until Python smoke checks and AVR compile checks are documented, and until AVR compile checks are reproducible in CI or local maintainer notes.
113 changes: 112 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,112 @@
# Arduino
# Portable AVR Control Studio

Portable AVR Control Studio is a portable, Windows-centered control and configuration studio for Arduino Uno / ATmega328P AVR deployments. The Arduino Uno already uses an AVR-compatible target; this project compiles firmware for that Uno AVR target and controls/configures it from a portable Tkinter desktop application.

## Architecture

```text
Windows GUI (Tkinter + optional pyserial)
|
| newline-delimited 115200 baud ASCII protocol
v
Arduino Uno / ATmega328P AVR firmware
|
| validated Config struct + EEPROM persistence
v
Sensor input + relay / buzzer outputs documented by hardware profile
```

### Firmware

The sketch in `firmware/PortableAVRControlStudio/PortableAVRControlStudio.ino` provides:

- EEPROM-backed `Config` storage with magic/version validation.
- Factory defaults for the Arduino Uno / ATmega328P AVR primary target.
- Safe fixed-buffer serial command parsing without Arduino `String`.
- Customer-facing runtime settings for device name, sensor VREF, thresholds, relay mode, buzzer enable, eco mode, telemetry interval, and UI language placeholder.
- Separate hardware/profile settings for sensor pin, relay pin, buzzer pin, and output polarity.
- `RELAY_MODE=AUTO` threshold hysteresis based on sensor millivolt readings.
- Clear `OK`, `ERR`, `CONFIG`, `STATUS`, and `DATA` responses.

Supported commands are documented in [`docs/PROTOCOL.md`](docs/PROTOCOL.md), including `PING`, `INFO`, `GET_CONFIG`, `GET_STATUS`, `SET,<KEY>,<VALUE>`, `SAVE_CONFIG`, `LOAD_CONFIG`, `FACTORY_RESET`, `RELAY,ON|OFF|TOGGLE`, and `BUZZER,ON|OFF|TOGGLE`. `INFO` intentionally returns `DATA,INFO,...` metadata; command acknowledgements use `OK,<COMMAND>`.

### Windows GUI

The desktop app in `gui/portable_avr_control_studio.py` is branded as **Portable AVR Control Studio** and includes these areas:

- Connection
- Firmware
- Settings
- Live Monitor
- Hardware Profiles
- Diagnostics
- Logs
- About / Handoff

Runtime settings are configurable from the GUI. The Settings tab validates values before sending them to firmware, including device-name length/characters, numeric ranges, threshold ordering, telemetry and VREF ranges, editable pin ranges, and enum values such as `MANUAL`/`AUTO` and `ON`/`OFF`.

The GUI can read settings from the board, edit settings, send runtime settings, save settings to EEPROM, factory reset the board, test the relay, and test the buzzer. It parses `OK`, `ERR`, `CONFIG`, `STATUS`, and `DATA` lines defensively so malformed serial data is logged instead of crashing the application.

Demo mode remains available for presentations, but it is explicitly labelled as **simulation only** and does not communicate with physical hardware.

## Runtime settings and hardware profiles

Customer-facing runtime settings are listed in [`docs/product_spec.md`](docs/product_spec.md) and [`docs/PROTOCOL.md`](docs/PROTOCOL.md). Use **Save to EEPROM** after a successful configuration update if the settings should persist after reset or power loss.

Hardware profiles in `docs/profiles/` document expected wiring, output polarity, sensor assumptions, and limitations. Hardware profiles do **not** auto-detect unknown hardware. Driver boards, inverted outputs, sensor circuits, or additional peripherals may require both a matching profile and matching firmware changes.

## Firmware upload status

The Firmware tab supports selecting prepared `.hex` firmware artifacts as a placeholder handoff workflow. It must not be presented as a fully validated production uploader until the uploader, target MCU flags, COM-port behavior, hardware profile, and firmware artifact have been packaged and tested together.

## Firmware compile checks

Install Arduino CLI and run the compile checks documented in [`docs/ARDUINO_CLI.md`](docs/ARDUINO_CLI.md):

```bash
arduino-cli core update-index
arduino-cli core install arduino:avr
arduino-cli compile --fqbn arduino:avr:uno firmware/PortableAVRControlStudio
```

Optional compatible Nano check (secondary only, not required for merge):

```bash
arduino-cli compile --fqbn arduino:avr:nano firmware/PortableAVRControlStudio
```

These are compile checks only for the Arduino Uno AVR target. This repository does **not** claim physical hardware testing.

## Python smoke checks

From the repository root:

```bash
python -m py_compile gui/portable_avr_control_studio.py
python - <<'PY'
from gui.portable_avr_control_studio import parse_serial_line
assert parse_serial_line('OK,PING\n').kind == 'OK'
assert parse_serial_line('CONFIG,RELAY_MODE=AUTO,SENSOR_VREF_MV=5000\n').fields['RELAY_MODE'] == 'AUTO'
assert parse_serial_line('STATUS,SENSOR_RAW=123,SENSOR_MV=601\n').fields['SENSOR_RAW'] == '123'
assert parse_serial_line('garbage\n').malformed
PY
```

Install `pyserial` when using real COM ports:

```bash
python -m pip install pyserial
```

## Portable Windows EXE packaging

See [`docs/PACKAGING.md`](docs/PACKAGING.md). A typical PyInstaller build is:

```powershell
py -m pip install pyinstaller pyserial
py -m PyInstaller --noconfirm --onefile --windowed --name PortableAVRControlStudio gui\portable_avr_control_studio.py
```

## Draft status and hardware-test limitation

Keep the PR as a real GitHub Draft until documented checks are passing and any required AVR compile evidence is captured. No physical hardware test has been claimed in this repository; real boards, sensors, relays, buzzers, power, and enclosure hardware must be validated before customer deployment.
19 changes: 19 additions & 0 deletions docs/ARDUINO_CLI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Arduino CLI Compile Checks

Use Arduino CLI to compile the Arduino Uno / ATmega328P AVR primary target before firmware handoff:

```bash
arduino-cli core update-index
arduino-cli core install arduino:avr
arduino-cli compile --fqbn arduino:avr:uno firmware/PortableAVRControlStudio
```

Optional compatible Nano compile check (secondary only, not required for merge):

```bash
arduino-cli compile --fqbn arduino:avr:nano firmware/PortableAVRControlStudio
```

The GitHub Actions workflow in `.github/workflows/checks.yml` runs the required Uno compile using `arduino/setup-arduino-cli`. The Nano command is optional documentation only and is not required for merge.

These checks verify that the sketch compiles for the Arduino Uno AVR target. They do not prove relay/buzzer wiring, driver polarity, sensor calibration, EEPROM behavior on a specific board, or physical safety. Do not claim physical hardware testing until it has been performed on the target hardware profile.
38 changes: 38 additions & 0 deletions docs/PACKAGING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Portable Windows Packaging

The GUI is a standard-library Tkinter application with optional `pyserial` support for real COM ports.

## Development smoke checks

```powershell
py -m py_compile gui\portable_avr_control_studio.py
py gui\portable_avr_control_studio.py
```

Install serial support when using physical hardware:

```powershell
py -m pip install pyserial
```

## Portable EXE build

A common Windows handoff package can be built with PyInstaller:

```powershell
py -m pip install pyinstaller pyserial
py -m PyInstaller --noconfirm --onefile --windowed --name PortableAVRControlStudio gui\portable_avr_control_studio.py
```

Copy these items into the customer handoff folder:

1. `dist\PortableAVRControlStudio.exe`
2. `README.md`
3. `docs\PROTOCOL.md`
4. `docs\product_spec.md`
5. `docs\testing.md`
6. `docs\customer_handoff.md`
7. `docs\profiles\*.json`
8. Prepared `.hex` firmware artifacts, if firmware upload is part of the handoff

The firmware upload tab is a placeholder workflow for prepared `.hex` artifacts. A production package should bundle and test the selected uploader, target MCU flags, COM-port behavior, and profile-specific firmware before presenting upload as a one-click customer feature.
56 changes: 56 additions & 0 deletions docs/PROTOCOL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Portable AVR Control Studio Serial Protocol

The firmware exposes a newline-delimited ASCII protocol at `115200` baud for the Arduino Uno / ATmega328P AVR primary target. Commands are intentionally small so they can be parsed without Arduino `String` allocations.

## Response format

The protocol consistently uses these prefixes:

- `OK,<COMMAND>` acknowledges commands that only need acknowledgement.
- `ERR,<CODE>,<MESSAGE>` reports rejected commands or validation failures.
- `CONFIG,KEY=VALUE,...` reports the complete active configuration.
- `STATUS,KEY=VALUE,...` reports live state and telemetry.
- `DATA,<TOPIC>,KEY=VALUE,...` reports informational payloads. `INFO` returns `DATA,INFO,...` because it is metadata rather than a state-changing acknowledgement.

The GUI parser accepts these prefixes and logs malformed/unknown data instead of crashing.

## Commands

| Command | Purpose |
| --- | --- |
| `PING` | Check that firmware is responsive; returns `OK,PING`. |
| `INFO` | Return `DATA,INFO` metadata for app, firmware, board, protocol, and baud. |
| `GET_CONFIG` | Return all runtime and hardware/profile settings. |
| `GET_STATUS` | Return relay, buzzer, sensor raw/mV, threshold, uptime, and active pins. |
| `SET,<KEY>,<VALUE>` | Validate and apply one runtime or hardware/profile setting in RAM. |
| `SAVE_CONFIG` | Persist the active configuration to EEPROM. |
| `LOAD_CONFIG` | Load a valid EEPROM configuration. |
| `FACTORY_RESET` | Restore factory defaults and save them to EEPROM. |
| `RELAY,ON` / `RELAY,OFF` / `RELAY,TOGGLE` | Drive the configured relay output when `RELAY_MODE=MANUAL`. |
| `BUZZER,ON` / `BUZZER,OFF` / `BUZZER,TOGGLE` | Drive the configured buzzer output when `BUZZER_ENABLED=ON`. |

## Customer-facing runtime settings

| Key | Valid values | Notes |
| --- | --- | --- |
| `DEVICE_NAME` | 1-16 printable ASCII characters, no commas | Customer-facing board label. |
| `SENSOR_VREF_MV` | `1000`-`5500` | ADC reference used to convert raw sensor readings to millivolts. |
| `THRESHOLD_LOW` | `0`-`5500`, less than `THRESHOLD_HIGH` | AUTO relay turns on at or below this sensor mV. |
| `THRESHOLD_HIGH` | `0`-`5500`, greater than `THRESHOLD_LOW`, not above `SENSOR_VREF_MV` | AUTO relay turns off at or above this sensor mV. |
| `RELAY_MODE` | `MANUAL` or `AUTO` | AUTO uses threshold hysteresis; manual relay commands are rejected in AUTO. |
| `BUZZER_ENABLED` | `ON` or `OFF` | OFF forces buzzer output off and rejects buzzer test commands. |
| `ECO_MODE` | `ON` or `OFF` | ON enforces an effective telemetry interval of at least 5000 ms. |
| `TELEMETRY_MS` | `250`-`60000` | Periodic `STATUS` interval. |
| `UI_LANGUAGE` | `EN` | Placeholder for future localization. |

## Hardware/profile settings

| Key | Valid values | Notes |
| --- | --- | --- |
| `SENSOR_PIN` | `A0`-`A5` or `14`-`19` | Bundled profile default is A0/14. |
| `RELAY_PIN` | Digital pin `2`-`13` | D0/D1 remain reserved for serial. |
| `BUZZER_PIN` | Digital pin `2`-`13` | Must differ from `RELAY_PIN`. |
| `RELAY_ACTIVE_HIGH` | `0`, `1`, `ON`, `OFF`, `TRUE`, `FALSE`, `HIGH`, `LOW` | Controls output polarity. |
| `BUZZER_ACTIVE_HIGH` | Same boolean values | Controls output polarity. |

Hardware/profile settings should match documented wiring and firmware expectations. They are not automatic hardware detection.
25 changes: 25 additions & 0 deletions docs/customer_handoff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Customer Handoff Notes

## What is included

- AVR firmware for the Arduino Uno / ATmega328P primary target.
- Windows-centered Tkinter GUI for runtime configuration and monitoring.
- Demo mode for simulation-only presentations.
- Hardware profile documentation for expected wiring and polarity.
- Placeholder prepared `.hex` firmware artifact workflow.

## What must be confirmed before delivery

1. Compile firmware for the Arduino Uno / ATmega328P AVR target.
2. Validate the selected hardware profile against real wiring.
3. Test relay and buzzer polarity with the final driver modules.
4. Confirm sensor scaling and thresholds with the actual sensor circuit.
5. Package the GUI as a Windows EXE and include profile/docs files.
6. Validate any firmware upload workflow with the bundled uploader and target hardware.

## Important limitations to communicate

- Demo mode is simulation only and does not prove hardware behavior.
- Hardware profiles document assumptions; they do not auto-detect unknown boards or wiring.
- Firmware upload is currently a prepared-artifact placeholder unless an uploader is bundled/configured/tested.
- No physical hardware testing has been claimed in this PR.
48 changes: 48 additions & 0 deletions docs/product_spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Portable AVR Control Studio Product Spec

## Product goal

Portable AVR Control Studio is a Windows-centered control and configuration studio for Arduino Uno / ATmega328P AVR installations. It combines:

- EEPROM-backed AVR firmware.
- A Tkinter desktop GUI suitable for portable Windows packaging.
- A documented serial protocol.
- Hardware profiles that describe assumptions without pretending to auto-detect unknown hardware. Arduino Nano may be documented only as a compatible secondary option.

## Customer-facing runtime settings

These settings are editable from the GUI and persisted by firmware after `SAVE_CONFIG`:

| Setting | Purpose |
| --- | --- |
| `DEVICE_NAME` | Human-readable board label, 1-16 printable characters, no commas. |
| `SENSOR_VREF_MV` | ADC reference in millivolts. |
| `THRESHOLD_LOW` | Lower sensor threshold in millivolts. |
| `THRESHOLD_HIGH` | Upper sensor threshold in millivolts. |
| `RELAY_MODE` | `MANUAL` for direct relay commands or `AUTO` for threshold control. |
| `BUZZER_ENABLED` | `ON` enables buzzer commands; `OFF` forces buzzer output off. |
| `ECO_MODE` | `ON` reduces telemetry cadence by enforcing at least 5000 ms. |
| `TELEMETRY_MS` | Periodic status interval, 250-60000 ms. |
| `UI_LANGUAGE` | Placeholder; currently only `EN` is supported. |

## Hardware/profile settings

Hardware settings remain editable for controlled handoff scenarios but are separated from customer runtime settings in the GUI:

- `SENSOR_PIN`
- `RELAY_PIN`
- `BUZZER_PIN`
- `RELAY_ACTIVE_HIGH`
- `BUZZER_ACTIVE_HIGH`

Changing hardware settings may require matching firmware, wiring, driver polarity, and profile documentation.

## Relay AUTO behavior

When `RELAY_MODE=AUTO`, firmware samples the configured analog sensor, converts raw ADC readings to millivolts using `SENSOR_VREF_MV`, and applies simple hysteresis:

- Relay turns `ON` at or below `THRESHOLD_LOW`.
- Relay turns `OFF` at or above `THRESHOLD_HIGH`.
- Relay keeps its previous state between the thresholds.

Manual `RELAY,ON|OFF|TOGGLE` commands are rejected while `RELAY_MODE=AUTO` so the GUI cannot fight the threshold controller.
32 changes: 32 additions & 0 deletions docs/profiles/arduino_uno_avr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "Arduino Uno AVR",
"target": "Arduino Uno / ATmega328P AVR (primary supported profile)",
"serial": {
"baud": 115200,
"notes": "D0/D1 are reserved for USB serial and are not accepted for relay/buzzer outputs."
},
"runtime_settings": {
"DEVICE_NAME": "Uno AVR Studio",
"SENSOR_VREF_MV": 5000,
"THRESHOLD_LOW": 1200,
"THRESHOLD_HIGH": 2800,
"RELAY_MODE": "MANUAL",
"BUZZER_ENABLED": "ON",
"ECO_MODE": "OFF",
"TELEMETRY_MS": 1000,
"UI_LANGUAGE": "EN"
},
"hardware_settings": {
"SENSOR_PIN": "A0 / 14",
"RELAY_PIN": 8,
"BUZZER_PIN": 9,
"RELAY_ACTIVE_HIGH": 1,
"BUZZER_ACTIVE_HIGH": 1
},
"limitations": [
"This Arduino Uno profile documents expected wiring; it is not automatic hardware detection.",
"Driver boards with inverted polarity must use matching settings and may require firmware review.",
"AUTO relay mode uses firmware threshold hysteresis and must be validated with the actual sensor circuit.",
"Physical hardware validation has not been claimed by the repository checks."
]
}
Loading
Loading