SuperAPI AI Directory

@6171/pendulum-g-experiment

Data & analytics

View repository

Updated 10-16 08:34

About this skill

📐 Pendulum g-measurement experiment skill

Core capabilities

Build a complete set ofmicrocontroller magnetic-sensing automatic-timing pendulum experiment, including:

  1. Hardware solution (BOM + circuit diagram + 3D printed part design)
  2. Firmware (Arduino/ESP-IDF, serial protocol)
  3. PC-side monitoring console (Python WebSocket + real-time dashboard)
  4. Teaching documentation (lesson plan, student worksheet, debugging manual, error budget)
  5. Data analysis (T²-L fitting, swing angle comparison, error analysis)

Hardware solution

Sensor selection decision tree

用户想做单摆测g?
├── 有 A3144E 霍尔传感器
│   ├── 接线正确(VCC→3.3V, OUT→GPIO14+10kΩ上拉, GND→GND)
│   │   └── 正常使用,去抖设 3000μs
│   └── 反接烧毁/无响应
│       └── ⚠️ 替换为磁簧开关(四脚常开型,类似 MKA10110)
│           ├── 一脚接 GND,另一脚接 GPIO14(内置上拉即可)
│           ├── 无需外部上拉电阻,不怕反接
│           └── 去抖设 2000μs(磁簧抖动比霍尔多)
│
├── 有磁簧开关 → 直接使用,比霍尔更稳定
│
└── 从零开始 → 推荐磁簧开关方案(便宜、可靠)

Key parameters

Parameter Value Description
Sensor Reed switch / A3144E Hall Falling-edge trigger
Debounce time 2000-3000μs Reed requires smaller
Period measurement Average over 50 periods Accuracy ±0.001s
Swing angle control ≤5° Small-angle approximation has minimal error
Pendulum length measurement String length + bob radius 1mm error → 0.1% g error

Common faults

  1. Hall sensor reverse connection burn-out — A3144E will burn out if reverse-connected, no protection. Fix: replace with reed switch
  2. Reed switch count not incrementing — Use a multimeter to test continuity, manually bring near a magnet and check serial output
  3. WebSocket port conflict — lsof -ti:8765 | xargs kill -9
  4. Async code error — pendulum_monitor.py in await asyncio.sleep(0) must be placed inside an async function, cannot be used in __main__ top level

Firmware development

Pin allocation

ESP8266 (Wemos D1 Mini) 推荐引脚:
  D1 (GPIO5)  → OLED SCL
  D2 (GPIO4)  → OLED SDA
  D3 (GPIO0)  → 磁簧信号输入(下降沿中断)
  D4 (GPIO2)  → LED 指示灯
  D5 (GPIO14) → 按键 SW1
  D6 (GPIO12) → 按键 SW2
  
ESP32 推荐引脚:
  GPIO21 → OLED SDA
  GPIO22 → OLED SCL
  GPIO14 → 传感器信号(下降沿中断)
  GPIO27 → 按键 SW1
  GPIO26 → 按键 SW2
  GPIO25 → LED

Serial protocol

115200 baud, 8N1

L=1.000        设置摆长(米)
mode0          单次测周期
mode1          T²-L 拟合模式
mode2          摆角对比模式
reset          清零
data           输出CSV
calib=9.79     设置本地g参考值
info           输出系统信息

Flashing steps

  1. Install ESP32/ESP8266 board support package in Arduino IDE
  2. Install libraries: Adafruit_SSD1306, Adafruit_GFX
  3. Select board type, port, flash
  4. Verify with serial monitor at 115200

Monitoring console

Startup

pip3 install pyserial websockets
python3 pendulum_monitor.py --port /dev/cu.usbserial-140
# 浏览器打开 http://localhost:8080

Architecture

ESP32 ──串口──→ pendulum_monitor.py ──WebSocket──→ 浏览器仪表盘
                    │
                    └── HTTP :8080 提供页面

Port configuration

Purpose Default port Configuration parameters
HTTP dashboard 8080 --http-port
WebSocket 8765 --ws-port
Serial port Auto-detect --port

Documentation output

When the user needs a complete solution package, generate the following file structure:

pendulum_g/
├── 01_硬件方案.md          # 原理、BOM、电路图
├── 02_固件代码.md          # 烧录指南 + 完整代码
├── 03_打印件设计.md        # 3D打印文件描述
├── 04_教学教案.md          # 2课时教案
├── 05_数据可视化.md        # Python绘图脚本
├── README.md
├── index.html             # 下载页
├── pendulum_monitor.py    # 一体化监控台
├── firmware/
│   ├── pendulum_g.ino     # 完整固件
│   └── serial_logger.py   # 串口日志工具
├── docs/
│   ├── 调试手册.md        # 故障排查决策树
│   ├── 学生工作单.md       # 可打印工作单
│   ├── 误差预算表.md       # 误差分析
│   ├── BOM采购清单.md      # 标准版/零3D打印版/班级套装
│   ├── 装配工艺指南.md     # 装配步骤
│   └── 测试报告模板.md     # 测试报告模板
└── web/
    └── dashboard.html     # 独立仪表盘HTML

Delivery format

  • Teaching/general documentation → HTML (no MD)
  • Judges/formal submission → Word (.docx)
  • Teaching PPT → PPTX
  • Overall packaging → tar.gz
  • 3D printed parts → STL files

User scenarios

User says What to do
"I want to do a pendulum g-measurement experiment" Produce a complete solution, BOM→firmware→dashboard→documentation
"The Hall sensor is broken" Recommend a reed switch alternative, update firmware
"Help me set up a dashboard" Generate/Push pendulum_monitor.py, launch preview
"I want to compete" Complete solution package + Word judge materials + PPT
"Data is inaccurate" Check the debugging manual decision tree, pendulum length/pendulum angle/debounce