You are on page 1of 6

technology workshop craft home food play outside costumes

Simple MIDI Buzzer


by madnerd on December 15, 2016

Table of Contents

Simple MIDI Buzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: Simple MIDI Buzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: Upload Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 2: Wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3D printed case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 3: Install Ubuzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 4: Play midi files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

LoopMidi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

LMMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 5: Make your own Arduino Installer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Install Python 3 / pyserial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Install rtmidi2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Start ubuzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Compile ubuzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Make an installer with inno setup compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

http://www.instructables.com/id/Simple-MIDI-Buzzer/
Intro: Simple MIDI Buzzer
Are you nostalgic of the good old pc speaker? This tutorial is for you!

We will learn how to control a buzzer using a MIDI keyboard and even compose music with it!

Last but not least we will see how to make an installer that will install a python application and also the drivers for an Arduino Nano so you can share your Arduino
projects with anyone !

First we will see how to upload our code on an Arduino


Then we will learn how to wire a buzzer
Afterwards we will use our buzzer with a MIDI keyboard and a music software
Finally I will show you how to make an installer for your Arduino projects!

As always, all documentations/code are available in french/english at http://github.com/pigetArduino/ubuzzer


Everything is under really permissive licence (CC-A/MIT) so you can reuse it in your own tutorials.

Warning: This application is an alpha, and could not works correctly.

Step 1: Upload Arduino Code


First we need to upload the code on our Arduino.
We will not use the standard tone library, we will use toneAC instead that will allow us to control our buzzer more precisely.

Download the arduino code/librairies : http://ubuzzer.madnerd.org


Copy them into your sketch folder (Documents/arduino)
Upload ubuzzer.ino

Board : Arduino Nano / Processor : Atmega328

We will use the code I made to control Arduino with a python application, it is by far not optimize but easy to use.
Check out my instructables on this subject for more information:
http://www.instructables.com/id/Simple-RGB-Notific...
http://www.instructables.com/id/UTest-Make-USB-Dev...

Here is how toneAC works, it is similar to the tone library but as you can see, it allow to control volume and to use the buzzer without interrupting your sketch.

toneAC( frequency [, volume [, length [, background ]]] ) - Play a note.

frequency - Play the specified frequency indefinitely, turn off with toneAC().
volume - [optional] Set a volume level. (default: 10, range: 0 to 10 [0 = off])
length - [optional] Set the length to play in milliseconds. (default: 0 [forever], range: 0 to 2^32-1)
background - [optional] Play note in background or pause till finished? (default: false, values: true/false)

toneAC() - Stop output.


noToneAC() - Same as toneAC().

http://www.instructables.com/id/Simple-MIDI-Buzzer/
Step 2: Wiring
Our arduino is ready, let's wire our buzzer.

Here is the list of components you will need:


Arduino nano CH340G: 2
10 Buzzer : 1.80 (1 Buzzer:0.18)
Resistor pack 400pcs (3) (1 resistor: 0.0071)
5 pcs stripboard (1.18) (1 stripboard : 0.24 )

Total : 7.98 (2.43)

Pin 10 : RESISTOR (100Ohm) --- Buzzer +


Pin 9 : Buzzer -

You can also add a led next to the buzzer, so it will light up when a note is played.
Just add a led (before the resistor)

Pin 10 : RESISTOR (100Ohm) --- Led + / Buzzer +


Pin 9 : Led - / Buzzer -

Don't forget to isolate the circuit from the arduino (see video)
You can either use tape/hot glue/Blu-Tack (patafix)

3D printed case

As for my others instructables, we will use an all purpose case for arduino nano projects made by Olivier Sarrailh : https://github.com/pigetArduino/ubuzzer/tree/mast...

Keep in made, you won't be able to properly close the case as the buzzer takes too much place, but you should still be able to close it

http://www.instructables.com/id/Simple-MIDI-Buzzer/
Step 3: Install Ubuzzer
Our device is ready to be used, we will see how to install our application that will translate each notes played on your computer into frequency sent with serial on our
Arduino.

Download ubuzzer installer: http://ubuzzerdapp.madnerd.org


Start ubuzzer_setup.exe

If ubuzzer doesn't works, check that

Windows is updated
Visual C++ redistribuable is installed
No software using MIDI is started

The installer is bundled with Arduino nano clone (CH340) drivers and will install it if necessary.

Once ubuzzer has started, you can use it with a midi keyboard, just plug it in and ubuzzer will automatically detected your midi device, your arduino will also be
automatically connected.

You can also test your buzzer with the Arduino Serial Monitor:
Baudrate : 115200 / No Line Ending

UBuzzer --------> Check if this is the right device and returns OK


X -------> Where X is the frequency to play continuously
OFF -------> Stop sound

Step 4: Play midi files


You don't have a midi keyboard ? Don't worry I got you covered!
We will use LMMS (a free music software) to control it!

LoopMidi

First we need to use a software to create a virtual midi port, we are going to use loopMidi for this

Download loopMidi http://www.tobias-erichsen.de/software/loopmidi.h...


Click on + to create a virtual midi port

LMMS

We will use LMMS to control our buzzer but you can use any music software that manages midi out to do so.

Download LMMS : https://lmms.io/download/#windows


On TripleOscillator change the volume to 0
Click on the gear next to TripleOscillator
Click on Midi and choose your virtual midi port (Loopmidi by default)

Examples are available in apps/ubuzzer/lmms , you can also import midi files.
Keep in mind the buzzer can only play one note at a time.

You can learn how to use LMMS with this short tutorial : http://www.instructables.com/id/Make-NES-Music-Wit...

http://www.instructables.com/id/Simple-MIDI-Buzzer/
Step 5: Make your own Arduino Installer
In my previous instructables we have seen how to make a portable application in python to control Arduino.
http://www.instructables.com/id/Simple-RGB-Notific...
http://www.instructables.com/id/UTest-Make-USB-Dev...

Now we will see how to make an installer for your arduino projects.
Source code is available in apps/ubuzzer

Install Python 3 / pyserial

We will need python 3 and pyserial to control our Arduino.

Download python 3 : https://www.python.org/downloads/


During the installation, tick Add Python 3.5 to PATH
Open a command prompt (Windows Key + cmd) and install pyserial

pip install pyserial

Install rtmidi2

In order to make our Arduino understands MIDI we will use rtmidi2 for python,
this library will allow us to easily makes instruments with Arduino.

You will need Visual Studio to compile rtmidi2.


Download rtmidi2
Download Visual Studio Community
Install Visual Studio Community and Select
Programming Languages
Visual C++Common Tools for Visual C++
Python Tools for Visual Studio
In the command line go to rtmidi2 folder
Type

pip install cython


python setup.py install

Start ubuzzer

We have all the dependencies to use ubuzzer.py, let's check if it works:


Open a command prompt (Windows key + cmd)
Go to the source code (apps/ubuzzer/)
Type:

python ubuzzer.py

Compile ubuzzer

We can ,now, compile ubuzzer as a windows application.


You will need pyinstaller
pip install pyinstaller

Compile python software using compile.bat or


pyinstaller --noconsole --icon=ubuzzer.ico ubuzzer.py

Make an installer with inno setup compiler

We have our application ready to be bundled in an installer, we will use inno setup compiler to do this.

Download inno setup compiler: http://www.jrsoftware.org/isinfo.php

http://www.instructables.com/id/Simple-MIDI-Buzzer/
Download Arduino Drivers for nano ch340g : http://nano.madnerd.org
Open app/buzzer/buzzer_installer.iss
Change paths for the application / drivers

;CHANGE PATHS before compiling!


#define APP "Y:\arduino\ubuzzer\apps\ubuzzer\dist\ubuzzer\"
#define DRIVERS "c:\nano"

in [RUN], we install the drivers silently


[Run]
;Silent install for arduino nano ch340g drivers
Filename: {app}\nano\setup.exe; Parameters: "/s"; WorkingDir: {app}\nano;
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&, '&')}}"; Flags: nowait postinstall skipifsilent

Related Instructables

Arduino Arduino/Easy How To Burn a Arduino play Getting Started


Arpeggiated Driver Bootloader to (micro)music Project L.U.V.I.A with Arduino
Bass Glitch Animation Clone Arduino without shield (Low cost and
Synth Control Board Nano 3.0 by Akin by ninuxi Ultrasonic Codebender by
Electronic by WisarUK Yildiz Visual Ardumotive_com
Instrument by Impairment aid)
robotgeek_official by Wilfred aka
devilprometheus

Advertisements

Comments

http://www.instructables.com/id/Simple-MIDI-Buzzer/

You might also like