Difference between revisions of "BakeBit - Buzzer"
From FriendlyELEC WiKi
(→Introduction) |
(→特性) |
||
Line 7: | Line 7: | ||
* It can be used in electronic devices that need sound generators. | * It can be used in electronic devices that need sound generators. | ||
− | == | + | ==Hardware Spec== |
− | * | + | * Standard 2.0mm pitch 4 Pin BakeBit interface |
− | * | + | * PWM input |
− | * | + | * PCB dimension(mm): 20 x 24 |
− | [[File:BakeBit - Buzzerpcb.png|frameless|300px| | + | [[File:BakeBit - Buzzerpcb.png|frameless|300px| Buzzer PCB]] |
− | * | + | * Pin Description: |
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | | | + | |Pin || Description |
|- | |- | ||
− | |GND || | + | |GND || Supply Voltage 5V |
|- | |- | ||
− | |5V || | + | |5V || Gound |
|- | |- | ||
− | |NC || | + | |NC || Not Connected |
|- | |- | ||
− | |SIG || | + | |SIG || PWM Input |
|} | |} | ||
+ | |||
== 示例程序:Button And Buzzer == | == 示例程序:Button And Buzzer == | ||
Revision as of 13:36, 11 December 2016
Contents
1 Introduction
- The BakeBit-Buzzer is a passive buzzer. To drive this buzzer an oscillating source generating 2.7K square waves is needed.
- PWM input signals with different frequencies generate different sounds.
- It can be used in electronic devices that need sound generators.
2 Hardware Spec
- Standard 2.0mm pitch 4 Pin BakeBit interface
- PWM input
- PCB dimension(mm): 20 x 24
- Pin Description:
Pin | Description |
GND | Supply Voltage 5V |
5V | Gound |
NC | Not Connected |
SIG | PWM Input |
3 示例程序:Button And Buzzer
本示例需要配合BakeBit - Button使用。
3.1 硬件连接
简单的将 蜂鸣器 模块插入 D3接口,将 按键 插入 D4 接口,如下面这样:
3.2 示例源代码
import bakebit import time # Connect the BakeBit Ultrasonic Ranger to digital port D4 # SIG,NC,VCC,GND ultrasonic_ranger = 4 # Connect the BakeBit LED to digital port D3 led = 3 bakebit.pinMode(led,"OUTPUT") light = 0 while True: try: # Read distance value from Ultrasonic distance = bakebit.ultrasonicRead(ultrasonic_ranger) print(distance) if distance > 0: if distance<10: if light == 0: print("\ton") bakebit.digitalWrite(led,1) light = 1 else: if light == 1: print("\toff") bakebit.digitalWrite(led,0) light = 0 time.sleep(.2) except KeyboardInterrupt: bakebit.digitalWrite(led,0) break except TypeError: print ("Error") except IOError: print ("Error")
3.3 运行示例
假设你已经参考bakebit教程安装了BakeBit源代码,
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_Button_And_Buzzer.py:
cd ~/BakeBit/Software/Python sudo python bakebit_prj_Button_And_Buzzer.py
3.4 运行结果
当按下按键时,蜂鸣器会响起,松开按键时,蜂鸣器停止。
4 相关资料
- [Schematic](BakeBit - Buzzer.pdf)
- [BakeBit Github项目](https://github.com/friendlyarm/BakeBit)
- [BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)