Giter VIP home page Giter VIP logo

rpio-rtttl-piezo's Introduction

rpio-rtttl-piezo

Plays Nokia ringtones on a piezo speaker over a Raspberry Pi's GPIO pin with PWM.

Compatible with Raspberry Pi Models A, B (revisions 1.0 and 2.0), A+, B+, 2, 3, Zero.

This script requires root privileges to access the hardware PWM clocks. See node-rpio in further reading below for more details. Hardware PWM is only available on the following pins:

  • Raspberry Pi 26-pin models: pin 12
  • Raspberry Pi 40-pin models: pins 12, 32, 33, 35

Install

$ npm install git+https://github.com/nochecksum/rpio-rtttl-piezo.git

Basic usage

You should always specify an output pin (using physical hardware numbering):

var piezo = require('rpio-rtttl-piezo');

piezo.play({
  pwmOutputPin: 32
});

Specify a ringtone

Use the RTTTL format to provide a melody for playback:

var piezo = require('rpio-rtttl-piezo');

piezo.play({
  pwmOutputPin: 32,
  rtttl: 'BTTF:d=16,o=5,b=200:4g.,p,4c.,p,2f#.,p,g.,p,a.,p,8g,p,8e,p,8c,p,4f#,p,g.,p,a.,p,8g.,p,8d.,p,8g.,p,8d.6,p,4d.6,p,4c#6,p,b.,p,c#.6,p,2d.6'
});

Repeat

Repeat the melody 4 times with a 250ms delay between repetitions:

var piezo = require('rpio-rtttl-piezo');

piezo.play({
  pwmOutputPin: 32,
  repeat: 4,
  repeatDelay: 250
});

Playback octave

Shift the melody up 3 octaves. This is useful to move a melody's frequency into the most efficient dynamic range (loudest) for your piezo speaker. Check your datasheet for details.

var piezo = require('rpio-rtttl-piezo');

piezo.play({
  pwmOutputPin: 32,
  rtttl: 'GSTQ:d=4,o=6,b=100:p,8f5,16p,8p,16p,8f.5,32p,p,e5,32p,8a5,16p,8p,16p,8a.5,a5',
  freqMultiplier: 3
});

Volume (duty cycle)

A note is played by generating a square wave with PWM. The duty cycle describes how long each period of the square wave should be active, thus how loud it will sound.

Good values are 2 (loudest), 8, 16, 32, 64.

var piezo = require('rpio-rtttl-piezo');

piezo.play({
  pwmOutputPin: 32,
  dutyCycle: 32
});

Further reading

rpio-rtttl-piezo's People

Contributors

luke255 avatar nochecksum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

spljs zonemr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.