StarFive VisionFive GPIO User manual

Using VisionFive GPIO to Make A
Buzzer Beep

Legal Statements
PROPRIETARY NOTICE
Contact Us
StarFive

Preface
About this document
Revision History
Table 0-1 Revision History
Version Released Revision
Notes and noces
•Tip:
•Note:
•Important:
•CAUTION:
•Warning:
StarFive

Contents
1. Introducon.........................................................................................................................................................................7
2. Preparaon.......................................................................................................................................................................... 8
3. Running Demo Code.......................................................................................................................................................... 10
4. Demo Source Code............................................................................................................................................................ 11
StarFive

List of Tables
StarFive

List of Figures
StarFive

1. Introducon
1.1. 40-Pin Header Denion
Figure 1-1 40-Pin Denion
StarFive

2. Preparaon
2.1. Preparing Hardware
Table 2-1 Hardware Preparaon
Type M/O*Item Notes
•
•
•
•
•
•
•
•
•
Note:
2.1.1. Hardware Setup
Table 2-2 Connect LED to the 40-Pin Header
40-Pin GPIO Header
Passive Buzzer
Pin Number Pin Name
StarFive

Figure 2-1 Connect Buzzer to the 40-Pin Header
1
3
5
7
9
11
17
19
13
15
2
4
6
8
10
12
18
20
14
16
5V Power
5V Power
GND
GPIO14 (UART TX)
GPIO13 (UART RX)
GPIO45
GPIO19
GND
GND
GPIO21
3.3V Power
GPIO48 (I2C SDA)
GPIO47 (I2C SCL)
GPIO46
GND
GPIO44
3.3V Power
GPIO18 (SPI MOSI)
GPIO22
GPIO20
VCC
I/O
GND
Passive Buzzer
2.2. Preparing Soware
Flashing Fedora OS to a Micro-SD Card VisionFive
Single Board Computer Quick Start Guide
Using
SSH over Ethernet Using a USB to Serial Converter VisionFive Single Board Computer Quick Start Guide
pipVisionFive.gpio
sudo pip install VisionFive.gpio
sudo pip3 install VisionFive.gpio
Tip:
sudo yum install python-devel python3-devel
sudo python setup.py install
sudo python3 setup.py install
StarFive

3. Running Demo Code
buzzer.py
VisionFive.gpio
pip show VisionFive.gpio
Result:
Location: /usr/local/lib64/python3.9/site-packages
/usr/local/lib64/python3.9/site-
packages
cd /usr/local/lib64/python3.9/site-packages
sample-code
cd ./VisionFive/sample-code/
sample-code
sudo python buzzer.py
sudo python3 buzzer.py
◦Enter Pitch (200 to 20000)400
Note:
◦Enter Cycle (seconds)100
Example:
[riscv@fedora-starfive sample-code]$ sudo python3 buzzer.py
Enter Pitch (200 to 20000): 400
Enter Cycle (seconds): 100
Result:
StarFive

4. Demo Source Code
buzzer.py
'''
Please make sure the buzzer is connected to the correct pins.
The following table describes how to connect the buzzer to the 40-pin header.
-----------------------------------------
Passive Buzzer___Pin Number_____Pin Name
VCC 1 3.3V Power
GND 6 GND
I/O 18 GPIO19
-----------------------------------------
'''
import VisionFive.gpio as GPIO
import time
buzz_pin = 19
ErrOutOfRange = 0
def setup():
#Configure the direction of buzz_pin as out.
GPIO.setup(buzz_pin, GPIO.OUT)
#Configure the voltage level of buzz_pin as high.
GPIO.output(buzz_pin, GPIO.HIGH)
def pitch_in_check():
val_in = input('Enter Pitch (200 to 20000): ')
val = float(val_in)
if 200 <= val <= 20000:
return val
else:
print('The input data is out of range (200 to 20,000 Hz). Please re-enter.')
return ErrOutOfRange
def loop(pitch, cycle):
delay = 1.0 / pitch
cycle = int((cycle * pitch)/2)
#Buzzer beeps.
while cycle >= 0:
GPIO.output(buzz_pin, GPIO.LOW)
time.sleep(delay)
GPIO.output(buzz_pin, GPIO.HIGH)
time.sleep(delay)
cycle = cycle - 1
def destroy():
GPIO.output(buzz_pin, GPIO.HIGH)
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
#Input value of pitch (200 to 20,000 Hz).
pitch = pitch_in_check()
while pitch == 0:
pitch = pitch_in_check()
#Input value of cycle time (seconds).
cycle_in = input("Enter Cycle (seconds): ")
cycle = int(cycle_in)
#The buzzer beeps with the specified pitch and cycle.
loop(pitch, cycle)
StarFive
Table of contents
Other StarFive Computer Hardware manuals
Popular Computer Hardware manuals by other brands

ATI Technologies
ATI Technologies RADEON 9800 PRO Getting started guide

Texas Instruments
Texas Instruments DAC8803/14 EVM user guide

Addonics Technologies
Addonics Technologies CCHESEXC34 installation guide

Creative
Creative EF0960 Safety & Regulatory Guide

Exsys
Exsys EX-6500E user manual

EK-Quantum
EK-Quantum Velocity2 D-RGB -LGA 1700 user guide

Moxa Technologies
Moxa Technologies ABC-02-USB Quick installation guide

ARVOO
ARVOO PICASSO PCI-2SQ user manual

RAK
RAK LB801 user manual

Cypress Semiconductor
Cypress Semiconductor CY7C1353G Specification sheet

Alphacool
Alphacool GPX-N 1080pro-M16 instruction manual

Agilent Technologies
Agilent Technologies G3588-68015 user manual