Skip to content

sparkfun/Qwiic_Buzzer_Py

Repository files navigation

Qwiic_Buzzer_Py

follow on Twitter

SparkFun Qwiic Buzzer

Python module for the SparkFun Qwiic Buzzer

This python package is a port of the existing SparkFun Qwiic Buzzer Arduino Library This package can be used in conjunction with the overall SparkFun qwiic Python Package.

New to qwiic? Take a look at the entire SparkFun Qwiic ecosystem.

Using this sensor on a Raspberry Pi? ⚠

Your system might need modification. See this note.

Contents

Supported Platforms

The qwiic Buzzer Python package current supports the following platforms:

Dependencies

This driver package depends on the qwiic I2C driver: Qwiic_I2C_Py

Documentation

The SparkFun qwiic Buzzer module documentation is hosted at ReadTheDocs

Installation

PyPi Installation

This repository is hosted on PyPi as the sparkfun-qwiic-buzzer package. On systems that support PyPi installation via pip, this library is installed using the following commands

For all users (note: the user must have sudo privileges):

sudo pip install sparkfun-qwiic-buzzer

For the current user:

pip install sparkfun-qwiic-buzzer

To install, make sure the setuptools package is installed on the system.

Direct installation at the command line:

python setup.py install

To build a package for use with pip:

python setup.py sdist

A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.

cd dist
pip install sparkfun_qwiic_buzzer-<version>.tar.gz

Raspberry Pi Use

For this sensor to work on the Raspberry Pi, I2C clock stretching must be enabled.

To do this:

  • Login as root to the target Raspberry Pi
  • Open the file /boot/config.txt in your favorite editor (vi, nano ...etc)
  • Scroll down until the block that contains the following is found:
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on
  • Add the following line:
# Enable I2C clock stretching
dtparam=i2c_arm_baudrate=10000
  • Save the file
  • Reboot the raspberry pi

Example Use

See the examples directory for more detailed use examples.

from __future__ import print_function
import qwiic_buzzer
import sys
import time

def runExample():
	print("\nQwiic Buzzer Example 1 - Buzz\n")

	# Create instance of device
	my_buzzer = qwiic_buzzer.QwiicBuzzer()

	# Initialize the device
	if my_buzzer.begin() == False:
		print("The device isn't connected to the system. Please check your connection", \
			file=sys.stderr)
		return

	print("\nQwiic Buzzer ready!")
	
	# Loop forever
	while True:
		my_buzzer.on()
		time.sleep(1)
		my_buzzer.off()
		time.sleep(1)     

if __name__ == '__main__':
	try:
		runExample()
	except (KeyboardInterrupt, SystemExit) as exErr:
		print("\nEnding Example")
		sys.exit(0)

SparkFun - Start Something

Releases

No releases published

Packages

 
 
 

Languages