Add a Tone

Introduction

This documents how to add a tone to your DevEdge IoT Developer Kit.

Prerequisites

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

  1. Open Terminal.

  2. 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

  1. Open Command Line (CMD).

  2. 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

  1. Open Windows PowerShell.

  2. 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.

  1. Download the following .mid file: Beethoven_Symphony_No5_Fate.mid

  2. Move the .mid to the $HOME/zephyrproject folder.

  3. 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 is out.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 (default 9600)
      • {list, convert} specifies the action to perform, list shows the available instruments for conversion, convert initiates the conversion
      • filename is the filename for the input MIDI file

  4. 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

  1. Open Terminal.

  2. 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>
    
  3. 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

  1. Open Command Line (CMD).

  2. 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

  1. Open Windows PowerShell.

  2. 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.

  1. 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.

  2. Open your serial app on your computer. For demonstration purposes we will use Serial on a Mac.

  3. Select the serial port that is connected to your IoT Developer Kit then click Open.

  4. Under Terminal > Settings > Line Settings > Baud Rate make sure the following values are set then click OK:
    1. Baud Rate / Speed - 9600
    2. Data Rate - 8
    3. Parity - None
    4. Stop Bits - 1
    5. Flow Control - None

  5. 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.

  1. Enter the following in your serial app.

    fs ls /tmo
  2. Look for the out.bin file. If it is does not exist please try Step C again.

  3. Play the out.bin file by entering the following in your serial app.

    tmo buzzer player /tmo/out.bin

  4. 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.