{"id":30376500,"url":"https://github.com/cpldcpu/candlesense","last_synced_at":"2025-08-20T14:14:39.134Z","repository":{"id":309695722,"uuid":"1029961044","full_name":"cpldcpu/CandleSense","owner":"cpldcpu","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-13T08:51:12.000Z","size":9711,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-13T10:27:17.605Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cpldcpu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-31T21:24:35.000Z","updated_at":"2025-08-13T08:51:15.000Z","dependencies_parsed_at":"2025-08-13T10:37:28.224Z","dependency_job_id":null,"html_url":"https://github.com/cpldcpu/CandleSense","commit_stats":null,"previous_names":["cpldcpu/candlesense"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/cpldcpu/CandleSense","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpldcpu%2FCandleSense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpldcpu%2FCandleSense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpldcpu%2FCandleSense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpldcpu%2FCandleSense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpldcpu","download_url":"https://codeload.github.com/cpldcpu/CandleSense/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpldcpu%2FCandleSense/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271330320,"owners_count":24740820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-20T14:14:35.490Z","updated_at":"2025-08-20T14:14:39.126Z","avatar_url":"https://github.com/cpldcpu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using Candle Flame Oscillations as a Clock Source\n\nDetecting oscillations in a candle flame triplet using only wires and a CH32V003 microcontroller. \n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"media/flameosc_small.gif\" alt=\"Device overview\"/\u003e\n\u003c/p\u003e\n\n- **[Blog article](https://cpldcpu.com/2025/08/13/candle-flame-oscillations-as-a-clock/)**\n\n- **[Original project on HaD.io](https://hackaday.io/project/203763-deriving-1-hz-from-candle-flame-oscillations)**\n\n## Overview\n\nThis project uses the ADC in the MCU to implement a capacitive sensor that is able to detect motion of a candle flame and can extract the flicker frequency. The system samples the capacitive sensor, applies filtering and signal processing, and outputs processed data for analysis via the CH32Fun framework.\n\nIn addition, the flicker frequency is used as a frequency normal to blink a status LED at 1 Hz\n\n### Pin Configuration\n\n- **PA2**: Capacitive sensor input (sensed vs GND)\n- **PC4**: Status LED output\n\n## Project Structure\n\n```\n├── src/\n│   ├── main.c              # Main firmware code\n│   ├── funconfig.h         # CH32Fun configuration\n│   └── ch32fun/            # CH32Fun framework (git submodule)\n├── analyze_data.py         # Offline data analysis \n├── plot_realtime_qt.py     # Real-time data visualization and collection\n├── Makefile               # Build configuration\n└── *.csv                  # Collected sensor data files\n```\n\n## Firmware Operation\n\n1. **Capacitive Sensing**: Uses CH32V003's ADC-based capacitive touch sensing from the CH32Fun framework.\n2. **Signal Processing**:\n   - Low-pass filter: `avg = avg - (avg\u003e\u003e5) + raw_value`\n   - High-pass filter: `hp = raw_value - (avg\u003e\u003e5)`\n3. **Zero Crossing Detection**: Detects positive transitions in the high-pass signal\n5. **LED Control**: Uses a residual counter to convert 9.9 Hz flicker frequency to 1 Hz LED blink rate\n\n### Data Output Format\n\nThe firmware outputs tab-separated values:\n```\nraw    avg    hp    zero_cross\n46747  1495604  10   0\n46734  1495601  -3   0\n```\n\nWhere:\n- `raw`: Raw ADC reading\n- `avg`: Low-pass filtered average (×32 scaling)\n- `hp`: High-pass filtered signal (flame detection)\n- `zero_cross`: Binary flag for zero crossing events\n\n## Software Tools\n\n### Real-time Monitoring (`plot_realtime_qt.py`)\n\nReal-time plotter using PyQtGraph.\n- **Three-panel display**: Raw/filtered signals, flicker detection, zero crossings\n- **Data logging**: Automatic CSV file creation with timestamps\n\n**Dependencies:**\n```bash\npip install pyqtgraph PyQt5 numpy\n```\n\n**Usage:**\n```bash\nsudo make monitor | python3 plot_realtime_qt.py\n```\n\n### Data Analysis (`analyze_data.py`)\n\nWill read and analyze collected data files, showing time series plots of raw data, touch detection, and frequency analysis.\n\n**Dependencies:**\n```bash\npip install pandas matplotlib numpy scipy\n```\n\n**Usage:**\n```bash\npython3 analyze_data.py \u003ccsv_file\u003e\n```\n\n## Building and Flashing\n\n### Initial Setup\n\n```bash\n# Clone with submodules\ngit clone --recursive \u003crepository-url\u003e\n```\n\n### Build Commands\n```bash\n# Build and flash firmware\nmake flash\n\n# Monitor output (requires appropriate permissions)\nmake monitor\n```\n```bash\n# Build and flash firmware\nmake flash\n\n# Monitor output (requires appropriate permissions)\nmake monitor\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpldcpu%2Fcandlesense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpldcpu%2Fcandlesense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpldcpu%2Fcandlesense/lists"}