My name is Ryosuke Kamei and I am an IT consultant based on the idea of "gentle IT"! Currently, in my work, I am doing upstream processes focusing on requirements analysis and requirements definition, but I also write programs! As part of our friendly IT activities, we will introduce "Raspberry Pi 3" (commonly known as Raspberry Pi), which has the philosophy of "providing inexpensive PCs that can be programmed for education"!
This time, the buzzer will sound! [Razpai Magazine-June 2016 Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 ⑦ Make notifications and warning sounds](https://www.amazon.co.jp/ Razpai Magazine-June 2016 No.-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? = 18fd04738627edef8d6fffd6c9b8f9c2) is referred to.
The wiring diagram is [Razpai Magazine-June 2016 Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 ⑦ Make notifications and warning sounds](https://www.amazon.co.jp/ Razpai Magazine- June 2016-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? Ie = UTF8 & dpID = 61P3o6Agz + L & dpSrc = sims & preST = _OU09__BG0,0,0,0_FMpng_AC_UL_160 = sr2smail-22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) As it is.
If you get an image like this, referring to the picture of the circuit
Text version
From the Raspberry Pi side
--Raspberry Pi 2nd pin (5V) --Piezoelectric buzzer plus side --Raspberry Pi 6th pin (GND) --Transistor emitter (E) --Raspberry Pi 16th pin (SCL) --Resistance 10kΩ --Transistor collector (C)
From the piezoelectric buzzer
--Piezoelectric buzzer plus side --Raspberry Pi 2nd pin (5V) * Duplicate --Piezoelectric buzzer minus side --Transistor base (B)
Program is also [Razpai Magazine-June 2016 Issue Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 ⑦ Make Notifications and Warning Sounds](https://www.amazon.co.jp/ Razpai Magazine-2016 June issue-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? -22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) was used as a reference for repair. You can control ON / OFF with arguments and set how many seconds the buzzer sounds!
The source is uploaded to GitHub, so please use it as you like.
Clone with git
$ git clone https://github.com/RyosukeKamei/raspberrypi3.git
buzzer.py
#Library to control GPIO
import wiringpi
#Timer library
import time
#Argument reception
import sys
#GPIO terminal with buzzer connected
buzzer_pin = 23
#Initial setting
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode( buzzer_pin, 1 )
#argument
param = sys.argv
#1st argument
# on :Make a sound
# off :The sound stops
order = param[1]
#2nd argument Number of seconds to make a sound
second = int(param[2])
if order == "on":
#Sounds when the first argument is on
wiringpi.digitalWrite( buzzer_pin, 1 ) # 1 :Make a sound
print ("Buzzer on")
else:
#Stop the sound when the first argument is off
wiringpi.digitalWrite( buzzer_pin, 0 ) # 0 :Make a sound
print ("Buzzer off")
if order == "on" and second > 0:
#Seconds display
print (str(second)+"Seconds")
#If the number of seconds is 1 or more, the sound will be played for the specified number of seconds.
time.sleep( second )
wiringpi.digitalWrite( buzzer_pin, 0 ) #Stop the sound
print ("Buzzer off")
I recorded the video of how it is moving.
Sound the buzzer for 5 seconds
$ sudo python3 buzzer.py ON 5
Sound the buzzer (do not stop)
$ sudo python3 buzzer.py ON 0
Stop the buzzer
$ sudo python3 buzzer.py OFF 0
Install Raspberry Pi 3 → Wireless LAN → Japanese input / output → Operate from Mac
Install Docker on RaspberryPi3 Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Easy construction] Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Trial and error]
Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!
Programming with Node-RED programming with Raspberry Pi 3 and programming normally Light the LED with python on Raspberry Pi 3 (Hello World) Detect switch status on Raspberry Pi 3 Run a servo motor using python on Raspberry Pi 3 Control the motor with a motor driver using python on Raspberry Pi 3! Detect slide switch using python on Raspberry Pi 3! Detect magnet switch using python on Raspberry Pi 3! Detect temperature using python on Raspberry Pi 3! Sound the buzzer using python on Raspberry Pi 3! Detect analog signals with A / D converter using python on Raspberry Pi 3! Detect "brightness" using python on Raspberry Pi 3! Detect "temperature (using A / D converter)" using python on Raspberry Pi 3! Output to "7-segment LED" using python on Raspberry Pi 3!
Coding rules "Let's write gentle code" (FuelPHP) Naming convention "Friendly to yourself, team-friendly, and unseen members after 3 months"
PHP environment + Eclipse is linked to Apache using Docker Building FuelPHP development environment using Docker Create CRUD skeleton using initial settings of FuelPHP development environment using Docker and scaffold FuelPHP database migration
Recommended Posts