Add a Tone
Introduction
This documents how to add a tone to your DevEdge IoT Developer Kit.
Prerequisites
- A DevEdge IoT Developer Kit.
- An up-to-date clone of
DevEdge-IoTDevKit-ZephyrSDK
. - A working install of Python 3.6 or greater.
A board flashed with tmo_shell tag version tmz-sdk-1.19.1-qa or later.
Why would I want to implement the instructions in this document?
If you wish to add a custom tone to your DevEdge IoT Developer Kit this document will help your accomplish this goal.
Configuration
Step A
Setup a Python virtual environment.
For Linux / macOS
Open Terminal.
-
Enter the following:
cd ~/zephyrproject
python3 -m venv midi_tb_venv
source midi_tb_venv/bin/activate
pip install -r DevEdge-IoTDevKit-ZephyrSDK/scripts/requirements.txt
deactivate
For Windows Command Line
Open Command Line (CMD).
-
Enter the following:
cd %USERPROFILE%\zephyrproject
#For some installs the command for python3 is actually py -3 e.g. py -3 -m venv ft_venv
python3 -m venv midi_tb_venv
midi_tb_venv\Scripts\activate.bat
pip install -r DevEdge-IoTDevKit-ZephyrSDK\scripts\requirements.txt
deactivate
For Windows PowerShell
Open Windows PowerShell.
Enter the following:
cd $home\zephyrproject
#For some installs the command for python3 is actually py -3 e.g. py -3 -m venv ft_venv
python3 -m venv midi_tb_venv
midi_tb_venv\Scripts\Activate.ps1
pip install -r DevEdge-IoTDevKit-ZephyrSDK\scripts\requirements.txt
deactivate
Step B
Download the MIDI file and learn the Python syntax.
Download the following .mid file: Beethoven_Symphony_No5_Fate.mid
-
Move the .mid to the $HOME/zephyrproject folder.
-
Learn the Python conversion syntax below. The syntax for the script is as follows
DevEdge-IoTDevKit-ZephyrSDK/scripts/midi_tone_bin.py [-i INSTRUMENTS] [-o OUTPUT] [-s SERIAL] [-b BAUD] {list,convert} filename
Where:
-
INSTRUMENTS
is a comma delimited list of instrument indices to use (use*
for all, default is*
)OUTPUT
is the output file name to be used (default isout.bin
or/tmo/out.bin
if a serial device is specified)SERIAL
is the serial port for the device on which to right the file (if not specified, the output file is stored to your local machine)BAUD
is the baud rate for the device's serial port (default9600
){list, convert
} specifies the action to perform,list
shows the available instruments for conversion,convert
initiates the conversionfilename
is the filename for the input MIDI file
-
-
An example script can be seen below:
python DevEdge-IoTDevKit-ZephyrSDK/scripts/midi_tone_bin.py list Beethoven_Symphony_No.5_Fate.mid
Step C
Activate the Python virtual environment then convert the file to a binary.
For Linux / macOS
Open Terminal.
Enter the following:
cd ~/zephyrproject
source midi_tb_venv/bin/activate
#Replace <arguments> with the desired arguments
python DevEdge-IoTDevKit-ZephyrSDK/scripts/midi_tone_bin.py <arguments>
-
An example screenshot can be seen below. Note that the conversion of the .mid file to a binary file can take a bit of time. Here is the example script that was used in the screenshot:
python DevEdge-IoTDevKit-ZephyrSDK/scripts/midi_tone_bin.py -s /dev/cu.usbmodem000900xxxxx convert Beethoven_Symphony_No.5_Fate.mid
For Windows Command Line
Open Command Line (CMD).
Enter the following:
cd %USERPROFILE%\zephyrproject
midi_tb_venv\Scripts\activate.bat
#Replace <arguments> with the desired arguments
python DevEdge-IoTDevKit-ZephyrSDK\scripts\midi_tone_bin.py <arguments>
For Windows PowerShell
Open Windows PowerShell.
Enter the following:
cd $home\zephyrproject
midi_tb_venv\Scripts\Activate.ps1
#Replace <arguments> with the desired arguments
python DevEdge-IoTDevKit-ZephyrSDK\scripts\midi_tone_bin.py <arguments>
Step D
Connect your board to your computer.
-
Connect your IoT Developer Kit using the USB-A to USB-C cable provided to your computer like in the screenshot below. Ensure that the J-Link USB-C Debug port (port on the right) is plugged into your computer.
Open your serial app on your computer. For demonstration purposes we will use Serial on a Mac.
Select the serial port that is connected to your IoT Developer Kit then click Open.
- Under Terminal > Settings > Line Settings > Baud Rate make sure the following values are set then click OK:
- Baud Rate / Speed - 9600
- Data Rate - 8
- Parity - None
- Stop Bits - 1
-
Flow Control - None
-
At the command line screen press Enter on your keyboard. The uart command prompt appears. To learn more about uart, please read the document Interacting with the Kit at CLI via tmo_shell.
Step E
Play the generated file using the DevEdge IoT Developer Kit's built in buzzer.
-
Enter the following in your serial app.
fs ls /tmo
Look for the out.bin file. If it is does not exist please try Step C again.
Play the out.bin file by entering the following in your serial app.
tmo buzzer player /tmo/out.bin
-
Below is a video demonstrating this feature in action:
Troubleshooting
-
Problem 1 - In Step C I keep receiving an "[Errno 16] Resource busy" error. Why do I keep receiving this?
- Solution 1 - You may have a serial app already attached to that particular port. Close the serial app and try the
python DevEdge-IoTDevKit-ZephyrSDK/scripts/midi_tone_bin.py -s /dev/cu.usbmodem000900xxxxx convert Beethoven_Symphony_No.5_Fate.mid
command again.
FAQ
- Question 1 - Will the out.bin file still exist on my IoT Developer Kit after I unplug it?
- Answer 1 - Yes it will not.
- Question 2 - Is there a tmo_shell command I can use to stop the song from playing?
- Answer 2 - There is not, unfortunately. The only thing you can do is unplug the kit in order to stop the song / tone.