---
title: "【Raspberry Pi】2 - Passive Buzzer"
url: "https://ouro.foundation/files/ache0108/raspberry-pi2-passive-buzzer"
id: "560ab4ab-8e05-4a56-8ed9-c301bf109637"
type: "file"
---

# 【Raspberry Pi】2 - Passive Buzzer

File by @ache0108 in #ache0108 (all) · .md · 2.0 KB

- Asset id: `560ab4ab-8e05-4a56-8ed9-c301bf109637`
- Page: https://ouro.foundation/files/ache0108/raspberry-pi2-passive-buzzer



## Contents

```md

## I. Passive Buzzer Drive Principle
- Working Principle: Requires an external **PWM pulse signal** to drive sound production.
- Application Characteristics:
  - Sharp sound, suitable for alarms, notification tones.
  - Poor contact can cause pitch inaccuracy.

### 1. Tone Frequency Settings
- Low Range (C3–B3)
  `Tone_CL = [131,147,165,175,196,220,247,262]`
- Mid Range (C4–B4)
  `Tone_CM = [262,294,330,349,392,440,494,523]`
- High Range (C5–B5)
  `Tone_CH = [523,587,659,698,784,880,988,1047]`
- Hardware Limitation: Buzzer has rated frequency range; exceeding it causes detuning/silence.

### 2. Music Programming Implementation
1) Initialization Setup
- Initialize using `TonalBuzzer(buzzer_pin)`
- Stop sound: `stop()`

2) Note Playback
- Core: Play by frequency
- Time Unit: `duration = 0.5` corresponds to a **1/16th beat**

3) Song Playback
- Use `song` array to store note frequencies
- Use `beat` array to store corresponding durations
- Loop playback to implement melody

### 3. Music Programming Techniques
- Note Index: `Tone_CM[3]` = Mid-range mi
- Rhythm Conversion:
  - 0.5 → 1/16th beat
  - 1 → 1/8th beat
  - 2.5 → 5 times base duration
- Exception Handling: `try-except` catches `Ctrl+C`, safely stops sound.

---

## II. Knowledge Summary
| Knowledge Point | Core Content | Technical Key Points | Implementation Difficulties |
|---|---|---|---|
| Buzzer Drive | Requires external PWM pulse drive | Passive buzzer needs square wave drive | Poor contact causes pitch inaccuracy |
| Scale Frequency Mapping | Hertz corresponds to notes | Low/Mid/High frequency tables | Hardware frequency range limitation |
| Music Programming Structure | Two arrays for pitch + rhythm | song/beat paired playback | Duration calculation, dynamic delay |
| Playback Control | Single note / song playback functions | play_note / play_song | Linear pitch adjustment, detuning |
| Hardware Adaptation | Adapt to buzzer frequency response | Accept non-standard scales for minor keys | High pitch sharp, fixed timbre |
```

## Use it

- Download: https://database.ouro.foundation/storage/v1/object/public/public-files/dd119e84-657f-4895-b379-7e7f600ab9d7/019dceed-3f57-719f-8805-1638c27330e0.md?v=1777293155129
- Over Ouro MCP: `download_asset(id="560ab4ab-8e05-4a56-8ed9-c301bf109637")` returns the file or a download link.
- Find routes that take it: `get_compatible_routes(asset_id="560ab4ab-8e05-4a56-8ed9-c301bf109637")`, then pass it as `input_assets={"file": "560ab4ab-8e05-4a56-8ed9-c301bf109637"}`.
- From Python: `ouro.files.retrieve("560ab4ab-8e05-4a56-8ed9-c301bf109637")`
