2025-02-11
Metro Environment Monitoring Demo On STM32基于 STM32 的地铁环境监测小综合
A small STM32 integration note combining OLED, LDR, DHT11, encoder input, timers, PWM brightness control, tricolor LEDs, and servo movement.STM32 小综合笔记:把 OLED、光敏电阻、DHT11、编码器、定时器、PWM 调光、三色灯和舵机动作放进同一个循环里。
Small Integration小综合
前面的练习都是单点:LED、按键、定时器、PWM、ADC。到了“地铁环境智能检测系统”这个题目,重点变成把这些单点放进同一个主循环里。名字听起来比较大,实际训练的是一块 STM32 板上多个外设怎么一起跑。
This demo used a metro scenario to connect peripherals into one observable embedded loop. The work stayed close to the board: sensing, display, timed update, interrupt input, and PWM output.
What Ran Together接在一起的模块
- OLED displayed current brightness, target brightness, LED PWM, temperature, and humidity.
- The LDR read ambient light through ADC.
- The encoder adjusted target brightness through external interrupts.
- DHT11 refreshed temperature and humidity on a fixed cadence.
- TIM4 generated PWM for white LED brightness control.
- Tricolor LEDs simulated status lamps, and the servo simulated door movement.
- OLED 实时显示当前亮度、目标亮度、LED PWM 和温湿度。
- LDR 通过 ADC 获取环境亮度。
- 编码器通过外部中断调整目标亮度。
- DHT11 按固定节奏读取温湿度。
- TIM4 输出 PWM 控制白色 LED 亮度。
- 三色 LED 模拟状态灯,舵机模拟车门开合动作。
The fragile part was the mix of rhythms: OLED refresh, DHT11 timing, encoder interrupts, PWM output, and light-sensor ADC sampling all running together. For a short exercise, debugging and delays could hold it together. If the system grew, the scheduling and module boundaries would need to become much clearer.
最容易出问题的是几个节奏混在一起:OLED 刷新、DHT11 时序、编码器中断、PWM 输出、光敏 ADC 采样都在跑。短期可以靠调试和延时顶住,但如果系统继续变大,就需要更清楚的任务调度和模块分层。
File文件
The main-loop excerpt keeps the module initialization, DHT11 update flag, ADC reading, OLED refresh, and PWM lookup output: metro environment main loop excerpt.
主循环摘录保留了模块初始化、DHT11 更新标志、ADC 读数、OLED 更新和 PWM 查表输出:metro environment main loop excerpt。
Looking Back回头看
This kind of small integration exposes the gap between "I can use one peripheral" and "I can keep several peripherals running together." It connected brightness, temperature, humidity, input, output, and display into one loop. For a first internship, that is sturdier than listing a set of STM32 peripherals learned.
这类小综合最大的价值是暴露“会一个外设”和“能把几个外设一起跑”之间的差距。它把亮度、温湿度、输入、输出和显示串进同一个循环。对于第一次实习来说,这比单独列一串“学习了 STM32 外设”更扎实。