Skip to content

Output Devices

Group Assignment 🔗

✔️ Measure the power consumption of an output device

Individual Assignment

✔️ Add an output device to a microcontroller board you've designed

✔️ Program it to do something

NOKIA Ringtone Player

I want to create a musical interface that can play ringtone. I started with the multi-purpose D11C devkit board developed by Quentin Bolsee for rapid prototyping. I connected it with a passive buzzer.

The working principle of a passive buzzer is using PWM generating audio to make the air vibrate. Changing to different vibration frequencies can cause different sounds. For example, sending a pulse of 523Hz can generate Alto Do; sending a pulse of 587Hz can generate midrange Re; and sending a pulse of 659Hz can produce midrange Mi. By carefully writing down the musical notes, sound durations, and delay durations, we are able to let it play a song.

In my case, I choose the iconic NOKIA tune, as the timbre of the passive buzzer sounds very similar to the sound of a mobile phone in the 2000s.

(Sound on)

The Process

1. PCB Board Production

Detailed workflow has been described in Input Devices.

  1. Milling
  2. Sourcing and soldering
  3. Loading the bootloader

2. Connecting the Passive Buzzer

Simple and straightword. Positive electrode wire connects to the PA8, negative electrode wire connects to the ground (GND).

3. Programming

1. Add pitches.h library in Arduino IDE.
2. Coding with musical notes.

Useful tools:

Online Tone Generator: previewing the pitch of the sound before uploading the program.

Musical Notes to Frequency Conversion

C
#include "pitches.h"


int melody[] = {
  NOTE_E5, NOTE_D5, NOTE_FS4, NOTE_GS4, NOTE_CS5, NOTE_B4, NOTE_D4, NOTE_E4, NOTE_B4, NOTE_A4, NOTE_CS4, NOTE_E4, NOTE_A4
};
int duration = 200;
int thisNote;



void setup() {

  Serial.begin(9600);


}

void loop() {
  for (int thisNote = 0; thisNote < 13; thisNote++) {
    // pin8 output the voice, every scale is 0.5 sencond
    tone(8, melody[thisNote], duration);
    delay(200);

    //  while (Serial.available() > 0) {
    //    thisNote = Serial.parseInt();
    //    if (Serial.read() == '\n') {
    //      tone(8, thisNote, duration);

  }

  delay(2000);
}
2. Verifying and Uploading

After uploading, the board will automatically play the sound while plugged into power.

Further Implementation

Make it as a realtime PCB instrument by sending serial messages from TouchDesigner.

CHOP Execute
# me - this DAT
# 
# channel - the Channel object which has changed
# sampleIndex - the index of the changed sample
# val - the numeric value of the changed sample
# prev - the previous sample value
# 
# Make sure the corresponding toggle is enabled in the CHOP Execute DAT.

def onOffToOn(channel, sampleIndex, val, prev):
    return

def whileOn(channel, sampleIndex, val, prev):
    return

def onOnToOff(channel, sampleIndex, val, prev):
    return

def whileOff(channel, sampleIndex, val, prev):
    return

def onValueChange(channel, sampleIndex, val, prev):
    op('Serial1').send(int(Val) , terminator='\n')
    print(Val)
    return

Resources

⬇️ Download Project Files and Assets