Difference between revisions of "BakeBit - Buzzer"

From FriendlyELEC WiKi
Jump to: navigation, search
(运行结果)
(相关资料)
Line 98: Line 98:
 
When users press the button the buzzer will beep. When the button is released the buzzer will be silent.
 
When users press the button the buzzer will beep. When the button is released the buzzer will be silent.
  
==相关资料==
+
==Resources==
 
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/5/5b/04-SCHEMATIC_Buzzer.pdf BakeBit - Buzzer.pdf])
 
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/5/5b/04-SCHEMATIC_Buzzer.pdf BakeBit - Buzzer.pdf])
*[BakeBit Github项目](https://github.com/friendlyarm/BakeBit)
+
*[BakeBit Github Project Page](https://github.com/friendlyarm/BakeBit)
*[BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)
+
*[BakeBit Starter Kit User's Manual(中文)](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)
 +
 
 +
==Update Log==
 +
===December-11-2016===
 +
* Released English version

Revision as of 13:49, 11 December 2016

查看中文

1 Introduction

Buzzer
  • 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

Buzzer PCB

  • Pin Description:
Pin Description
GND Supply Voltage 5V
5V Gound
NC Not Connected
SIG PWM Input

3 Code Sample: Button And Buzzer

A BakeBit - Button module is needed in this test case.

3.1 Hardware Connection

Connect the buzzer module to the NEO-Hub at D3 and the button module to the NEO-Hub at D4:

Button And Buzzer-1.jpg Button And Buzzer-2.jpg

3.2 Source Code

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")

Github

3.3 Run Source Code

Before you run the source code you need to follow the steps in bakebit tutorial to install the BakeBit package.
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_Button_And_Buzzer.py" program:

cd ~/BakeBit/Software/Python
sudo python bakebit_prj_Button_And_Buzzer.py

3.4 Observation

When users press the button the buzzer will beep. When the button is released the buzzer will be silent.

4 Resources

5 Update Log

5.1 December-11-2016

  • Released English version