KT142C UART Control GUI (v9)

Introduction

The KT142C UART Control GUI (v9) is a comprehensive Python-based interface designed to control the KT142C audio module via UART. This GUI enables both manual operations and automated test sequences, offering a user-friendly yet powerful tool for audio playback, and device configuration.

Built with wxPython for the graphical user interface and pySerial for serial communication, the application accommodates a broad spectrum of baud rates, automated command acknowledgments, and real-time feedback from the device.

System Requirements

  • Python 3.9 or higher
  • wxPython: pip install wxPython
  • pySerial: pip install pyserial
  • OS: Windows, Linux, or macOS (with appropriate serial drivers)

Installation Instructions for Windows 11

  1. Verify Python 3.9+ installation (v3.14.0 at the moment of writing)

(download from https://www.python.org/downloads/ ).

  1. Install dependencies: Open Windows PowerShell and run:

pip install pyserial wxPython

  1. Download kt142c_gui_v9.py to a local folder.
  2. In PowerShell, navigate to the script’s location (e.g., right-click in the folder and select “Open in Terminal”).
  3. Launch the GUI:

python kt142c_gui_v9.py

The GUI window will launch upon execution.

TIP: The easiest way to navigate to the GUI file is to right-click inside the folder with the Python script and click on “Open in Terminal”:

Then type the command and hit the Enter:

The GUI window will appear:

Key Features

  1. Dual Panel Manual Control
    • The layout features two scrollable panels:
      • Control Commands: Handles playback, volume, loop, and sequence operations.
      • Query & Info Commands: Retrieves firmware details, file counts, and volume information.
    • Panels automatically resize with scrollbars for extended lists of controls.
  2. Device Connection & Baud Management
    • Maintains unified port/baud state for consistency between GUI and device.
    • Safe Set Baud Operation:
      • Issues a baud change command at the current rate (0x0B).
      • Closes and reopens the port at the new rate.
      • Verifies communication with a query command (0x3F).
    • Baud Sweep: Tests all supported baud rates (1200–460800 bps) and summarizes responses.
    • Supports non-volatile baud storage; changes persist after power cycle. No baud query supported.
  3. Playback Controls
    • Track Playback: Initiate play by track number, folder, or file selection.
    • Sequence & Combined Playback: Build and transmit sequences of track numbers.
    • Looping & Random: Commands for single-track loop, all-track loop, and random playback.
    • Quick Access Buttons: Previous, Next, Play/Pause, Stop, Reset, Low Power, and Wake for core functions.
  4. Volume Control
    • Slider for real-time volume adjustment (0–30 levels).
    • Memory save option (DH=1) to persist volume state.
    • Updates reflect instantly in the GUI.
  5. Device Query & Info
    • Fetches firmware version, total file count, and current volume.
    • Get All Info button sequentially retrieves comprehensive device data.
    • Files list populates automatically from file count queries.
    • Info box delivers real-time, time-stamped feedback.
  6. Raw HEX Command Support
    • Allows transmission of custom hexadecimal commands for advanced users.
  7. ACK Management
    • Supports automatic or manual acknowledgment.
    • Configurable retries and timeouts for dependable communication.
  8. Logging
    • Captures real-time TX, RX, and info messages.
    • Filters enable category-specific views.
    • Includes save and clear functions for logging and diagnostics.
  9. Configuration Persistence
    • Retains last-used port, baud rate, and auto-query settings.
    • Restores configuration on launch for seamless sessions.

Technical Highlights

  • Protocol: Utilizes START_BYTE 0x7E and END_BYTE 0xEF, with a 3-byte payload header [cmd, lenH, lenL]. All frames follow: 7E [cmd] [00] [02] [code] EF for baud/reset/low power.
  • Serial Worker: Employs a dedicated thread for asynchronous RX processing and frame parsing.
  • Thread Safety: Protects RX queues with locks for reliable multi-threaded performance.
  • Firmware Detection: Normalizes month values to 1–12; accommodates 0x3F responses for unavailable firmware info.

Baud Rate, Reset, and Low Power Mode Commands

The KT142C supports configurable UART baud rates from 1200 bps to 460800 bps, stored in non-volatile memory (persists after power cycle). Baud rate queries are not supported. Use command 0x0B to set rates. After changing, wait ≥1 second before reset (0x0C) or power cycle.

Command Frame Example Description
Set to 1200 bps 7E 0B 00 02 00 00 EF Code: 0x00
Set to 2400 bps 7E 0B 00 02 00 01 EF Code: 0x01
Set to 4800 bps 7E 0B 00 02 00 02 EF Code: 0x02
Set to 9600 bps (default) 7E 0B 00 02 00 03 EF Code: 0x03
Set to 19200 bps 7E 0B 00 02 00 04 EF Code: 0x04
Set to 38400 bps 7E 0B 00 02 00 05 EF Code: 0x05
Set to 57600 bps 7E 0B 00 02 00 06 EF Code: 0x06
Set to 115200 bps 7E 0B 00 02 00 07 EF Code: 0x07
Set to 230400 bps 7E 0B 00 02 00 08 EF Code: 0x08
Set to 460800 bps 7E 0B 00 02 00 09 EF Code: 0x09
Reset 7E 0C 00 02 00 00 EF Resets device; effective in any state. Internal clock error <1%.
Enter Low Power Mode 7E 0A 00 02 00 01 EF Standby ~30μA. Wake with any UART command (wait 30ms before next; initial command ignored). Auto-reenter if no valid frame in 5s.
Factory Reset (Restore 9600 bps) 7E C1 00 00 00 00 EF Erases all configurations.

Notes:

  • Use “Safe Set Baudrate” in GUI for seamless changes.
  • For low power: Send wake dummy command, wait 30ms, then actual command.
  • Default: 9600 bps on power-up.

Interface Overview

  1. Connection Row
    • Port: Select the UART port.
    • Current Baud / New Baud: View and choose baud rates (1200–460800 bps).
    • Open / Close: Establish or terminate serial connection.
    • Set Baudrate (Safe): Safely update device baud rate (0x0B command).
    • Baud Sweep: Scan all baud rates for compatibility.
    • Raw HEX: Input and send custom hex commands.
  2. Control Panel (Left)
    • Playback Controls: Play, pause, stop, next/previous, reset (0x0C), low power (0x0A).
    • Loop / Random: Single-track loop, all-tracks loop, or random mode.
    • Volume Control: Slider with memory save option.
    • Combined Playback: Assemble and dispatch track sequences.
  3. Info Panel (Right)
    • Query Commands: Retrieve firmware, file count, volume, or all info.
    • Files & List: Display files, select, and play.
    • Info / Status: Log for device info.
    • Quick Actions: Send online query (0x3F).
  4. Logging Area
    • Time-stamped TX, RX, and info display.
    • Type-based filters.
    • Save or clear options.

Usage

Connecting to the Device

  1. Choose serial port and baud rate (default: 9600).
  2. Click Open. Enable auto-query for immediate device info.

Playback

  1. Select track number, folder, or file.
  2. Click Play Track or Play Folder/File.
  3. Control with Pause, Stop, Next, Previous.

Volume

  1. Slide to adjust (0–30).
  2. Check Mem (DH=1) to save.

Combined Playback

  1. Input track numbers in the field.
  2. Click Add to Combined.
  3. Click Send Combined (0x21) to execute sequence.

Query Info

  • Use buttons: Get Firmware, Get File Count, Get Volume, or Get All Info.

Files List

  • Click Refresh Files List.
  • Select and click Play Selected.

Sending Raw Commands

  • Enter hex in Raw hex and click Send Raw (hex) (e.g., baud set: 7E0B00020000EF).

Safe Baud Change

  1. Select New Baud (e.g., 115200).
  2. Click Set Baudrate (Safe) (sends 0x0B, reopens port, verifies with 0x3F).
  3. GUI auto-verifies new rate; wait 1s before reset.

Low Power Mode

  1. Click Low Power (sends 0x0A).
  2. To wake: Send any command (e.g., query 0x3F), wait 30ms, send target command.
  3. Device auto-sleeps after 5s inactivity.

Tips

  • Auto-Info: Enable for port-open updates.
  • ACK Auto Mode: Promotes command reliability.
  • Logging Filters: Isolate TX, RX, or info.
  • If sleep mode is active, press Wake (55 55 55) before Set Baudrate (Safe).
  • Factory reset (raw: 7E C1 00 00 00 EF) restores 9600 bps but erases settings.

Troubleshooting

  • Cannot Open Port: Inspect cables and drivers.
  • No Device Response: Confirm baud rate (default 9600); run Baud Sweep to figure out what baudrate the chip is responding to. Try wake command.
  • Volume/Playback Issues: Wake device from low-power/sleep mode; verify file naming.
  • Baud Change Fails: Wait 1s post-change; use factory reset if stuck.

Loading MP3 Files to Internal Chip Memory

The KT142C features 320KB of built-in flash storage for MP3 audio files, supporting up to 999 individual files or organized folder structures (up to 99 folders, each holding up to 255 files). Audio must be in MP3 format with a sampling rate of 8–32 kHz. No additional programming tools are required—updates occur via USB as a plug-and-play virtual drive.

File Naming Conventions

  • Use sequential numeric prefixes for direct track access: 001.mp3, 002.mp3, …, 999.mp3.
  • The chip matches files by name; non-compliant names will not play.
  • For folder organization: Place files in subfolders named 01/, 02/, etc. (e.g., 01/001.mp3 plays file 001 in folder 01). Folders and files may include alphanumeric suffixes (e.g., 001 Any Text Hint.mp3).

Steps to Load Files

  1. Connect the Chip: Plug the KT142C module into a USB port on your PC using the dedicated USB interface (typically via a breakout board or direct pins). The chip enumerates as a removable USB drive (e.g., “KT142C” or similar).
  2. Prepare Files:
    • Check if mp3 files sample rate is in range 8..32 kHz, if not you can resample mp3 files in free audio editor Audacity. Recently the program aggressively promotes commercial cloud services, and have very limited functionality without it. While downloading (https://www.audacityteam.org/ ) make sure not to click on the button “Download Audacity 3.7.5” (with services) instead click bellow the button on the text “Download without Muse Hub” instead.
    • Rename your MP3 files according to the convention above. Ensure total size fits within 320KB (compress if needed).
  3. Copy Files:
    • Open the USB drive in File Explorer (Windows) or Finder (macOS).
    • Drag and drop renamed MP3 files directly into the root directory (for flat structure) or create numbered folders (e.g., 01, 02) for organization.
    • Copy in ascending order if sequential playback is desired, though naming ensures correct indexing.
  4. Safely Eject: Right-click the drive and select “Eject” or “Safely Remove Hardware” to avoid corruption.
  5. Verify: Reconnect via UART in the GUI, query file count (e.g., via “Get File Count”), and test playback.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다