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 !
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.
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.
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:
https://www.instructables.com/id/Simple-RGB-Notific...
https://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.
toneAC() - Stop output.
noToneAC() - Same as toneAC().
Our arduino is ready, let's wire our buzzer.
Here is the list of components you will need:
Total : 7.98€ (2.43€)
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)
Don't forget to isolate the circuit from the arduino (see video)
You can either use tape/hot glue/Blu-Tack (patafix)
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
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.
If ubuzzer doesn't works, check that
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
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!
First we need to use a software to create a virtual midi port, we are going to use loopMidi for this
We will use LMMS to control our buzzer but you can use any music software that manages midi out to do so.
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 : https://www.instructables.com/id/Make-NES-Music-Wit...
In my previous instructables we have seen how to make a portable application in python to control Arduino.
https://www.instructables.com/id/Simple-RGB-Notific...
https://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
We will need python 3 and pyserial to control our Arduino.
pip install pyserial
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.
pip install cython
python setup.py install
We have all the dependencies to use ubuzzer.py, let's check if it works:
python ubuzzer.py
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
We have our application ready to be bundled in an installer, we will use inno setup compiler to do this.
;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