430 views|1 replies

272

Posts

0

Resources
The OP
 

Active buzzer in the GPIO basic experiment of the Allwinner H616 Walnut Pie development board [Copy link]

 

Introduction

In our daily life, many of our electronic devices will alarm when encountering a fault, and the sound is often more likely to attract people's attention than the indicator light. In this section, we will learn how to drive an active buzzer with Walnut Pie.

Purpose

Program the buzzer to make a beeping sound.

Experimental explanation

Buzzers are mainly divided into active buzzers and passive buzzers. Active buzzers make sounds through high and low level control (fixed frequency), and passive buzzers are controlled by PWN waves (can make sounds of different frequencies). In this section, we will explain the use of active buzzers.

The usage of active buzzer is similar to LED. You only need to give the buzzer a high level to make a sound.

Connection method of active buzzer and Walnut Pi: GND--GND, VCC -- 3.3V, IO -- PI15 (You can also change to the GPIO you want to use)

active_buzzer1

The name of the Walnut Pie PI15 in the Python library is board.KEY :

active_buzzer2

digitalio object

In CircuitPython, you can directly use the digitalio (digital IO) module to program IO input to achieve high and low level output. The specific introduction is as follows:

Constructor

active_buzzer=digitalio.DigitalInOut(pin)

Parameter Description:

  • pin Development board pin number. Example: board.PI15

How to use

active_buzzer.direction = value

Pin definition input/output. Value matching value is as follows:

  • digitalio.Direction.INPUT : Input.
  • digitalio.Direction.OUTPUT : Output.

time object

time can be used for delay.

Constructor

import time

Time module, import it directly:

How to use

time.sleep(value)

Delay.

  • value refers to the delay time, in seconds. A value of 1 means 1 second, and a value of 0.1 means 0.1 second, that is, 100ms.

The active buzzer uses the digitalio object just like the LED. In the output mode, we can use the code to change the input high and low levels every 0.5 seconds to make the buzzer beep.

Import digitalio related modules

Constructing active_buzzer object

Turn on the buzzer

Delay 0.5 seconds

Turn off the buzzer

Reference code

'''
实验名称:有源蜂鸣器
实验平台:核桃派
'''

#导入相关模块
import board, time
from digitalio import DigitalInOut, Direction, Pull

#构建蜂鸣器对象和初始化
active_buzzer = DigitalInOut(board.PI15) #定义引脚编号
active_buzzer.direction = Direction.OUTPUT  #IO为输出

for i in range(5):
    
    active_buzzer.value = False #打开蜂鸣器
    time.sleep(0.5) #延时1秒
    active_buzzer.value = True #关闭蜂鸣器
    time.sleep(0.5) #延时1秒   

Experimental results

Here we use Thonny to remotely run the above Python code on Walnut Pie. For more information about how to run Python code on Walnut Pie, please refer to: Running Python Code

active_buzzer3

When running the code, you can hear the active buzzer making periodic "beeping" sounds.

active_buzzer4

This post is from Domestic Chip Exchange

Latest reply

The picture is a little distorted, modify it when you have time so that it looks more comfortable.  Details Published on 2024-6-1 11:29
 
 

6827

Posts

11

Resources
2
 
The picture is a little distorted, modify it when you have time so that it looks more comfortable.
This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list