Find file History
mangini Update all drivers to version 1.0
Change-Id: I6e482d09e9a1ba876d6dc9b50d2f12a70b5dc0b7
Latest commit be189aa May 6, 2018

PWM Speaker driver for Android Things

This driver supports speaker and piezo buzzer peripherals using the PWM protocol.

NOTE: these drivers are not production-ready. They are offered as sample implementations of Android Things user space drivers for common peripherals as part of the Developer Preview release. There is no guarantee of correctness, completeness or robustness.

How to use the driver

Gradle dependency

To use the pwmspeaker driver, simply add the line below to your project's build.gradle, where <version> matches the last version of the driver available on jcenter.

dependencies {
    compile '<version>'

Sample usage


// Access the speaker:

Speaker mSpeaker;

try {
    mSpeaker = new Speaker(pwmPinName);
} catch (IOException e) {
    // couldn't configure the speaker...

// Make it play:

try { /* tone */);
} catch (IOException e) {
    // error setting speaker

// Stop a currently playing tone:

try {
} catch (IOException e) {
    // error stopping speaker

// Close the speaker when finished:

try {
} catch (IOException e) {
    // error closing speaker


Copyright 2016 Google Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.