element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Review Blogs Arduino Uno Q - USB Audio
  • Blogs
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Sub-Groups
  • More
  • Cancel
  • New
Join RoadTests & Reviews to participate - click to join for free!
  • Share
  • More
  • Cancel
  • Author Author: ralphjy
  • Date Created: 25 Apr 2026 4:37 PM Date Created
  • Views 337 views
  • Likes 9 likes
  • Comments 10 comments
Related
Recommended
  • RoadTest
  • arduino uno q
  • USB speaker
  • sound generator brick
  • USB audio files

Arduino Uno Q - USB Audio

ralphjy
ralphjy
25 Apr 2026

Now that I've got two different ways to attach USB peripherals (hub and OTG adapter) to the Uno Q, I decided to try out a couple of audio apps with a USB speaker.

First I used the Sound Generator Brick to create some music.  This has the feel of sound generation that I used to do with the original Uno using frequency and duration to produce music.  Of course, this is much more sophisticated and can use different waveforms plus produce sounds algorithmically (synthesis).  And I get to use a USB speaker Relaxed.

image

 

Sound Generator Fur Elise example

image

The Brick overview has the tone data for Beethoven's Fur Elise, so I'll just play that.

   fur_elise = [
      ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4),
      ("B4", 1/4), ("D5", 1/4), ("C5", 1/4), ("A4", 1/2),

      ("C4", 1/4), ("E4", 1/4), ("A4", 1/4), ("B4", 1/2),
      ("E4", 1/4), ("G#4", 1/4), ("B4", 1/4), ("C5", 1/2),

      ("E4", 1/4), ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4),
      ("B4", 1/4), ("D5", 1/4), ("C5", 1/4), ("A4", 1/2),

      ("C4", 1/4), ("E4", 1/4), ("A4", 1/4), ("B4", 1/2),
      ("E4", 1/4), ("C5", 1/4), ("B4", 1/4), ("A4", 1.0),
   ]

I decided that it would be nice to add something to display on the LED matrix while the music was playing.

The Uno Q has 13x8 matrix rather than the the 12x8 matrix used on the Uno R4, so I needed to use the Arduino Uno Q LED Matrix Animator.  I created the image of a note and exported it to a json file.  I am using only a single image rather than an animation.  I needed to create a left justified array of 4 uint32_t integers to represent the 104 matrix bits (13x8) for the sketch.  The last integer is padded with zeroes in the 3 least significant bytes.

image

The python program controls the sound generation and playback over the USB speaker and the handshake for the LED matrix

main.py

from arduino.app_bricks.sound_generator import SoundGenerator, SoundEffect
from arduino.app_utils import *
import time

# Use 'master_volume' instead of 'volume'
player = SoundGenerator(master_volume=0.01, sound_effects=[SoundEffect.adsr()])

fur_elise = [
    ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4),
    ("B4", 1/4), ("D5", 1/4),  ("C5", 1/4),  ("A4", 1/2),

    ("C4", 1/4), ("E4", 1/4),  ("A4", 1/4),  ("B4", 1/2),
    ("E4", 1/4), ("G#4", 1/4), ("B4", 1/4),  ("C5", 1/2),

    ("E4", 1/4), ("E5", 1/4),  ("D#5", 1/4), ("E5", 1/4), ("D#5", 1/4), ("E5", 1/4),
    ("B4", 1/4), ("D5", 1/4),  ("C5", 1/4),  ("A4", 1/2),

    ("C4", 1/4), ("E4", 1/4),  ("A4", 1/4),  ("B4", 1/2),
    ("E4", 1/4), ("C5", 1/4),  ("B4", 1/4),  ("A4", 1.0),
]

# Start an infinite loop
while True:
    for i, (note, duration) in enumerate(fur_elise):
        # Toggle between frame 0 and frame 1
        frame_to_show = i % 2
        
        # This calls the C++ setFrame function
        Bridge.call("setFrame", frame_to_show)
        
        player.play(note, duration)
    
    time.sleep(1)

App.run()

The sketch just controls the matrix.

sketch.ino

#include "Arduino_LED_Matrix.h"
#include "Arduino_RouterBridge.h"

Arduino_LED_Matrix matrix;

// Define a "Musical Note" frame (13x8)
const uint32_t frameA[] = { 0xfe04102, 0x8104082, 0x470e387, 0x0 };

// Define a "Bar" frame
const uint32_t frameB[] = { 0x0, 0x0, 0x0, 0x0 };

void setFrame(int frameId) {
    if (frameId == 0) {
        matrix.loadFrame(frameA);
    } else {
        matrix.loadFrame(frameB);
    }
}

void setup() {
    matrix.begin();
    Bridge.begin();
    // Register the function so Python can call it
    Bridge.provide("setFrame", setFrame);
}

void loop() {
    // Bridge processes requests here
}

I did a quick check to see what USB devices were seen:

image

It sees the hub, hub Ethernet and SD card interfaces, and the USB speaker as Device 005 and the USB drive as Device 006.  I will be using the drive in the next mp3 player app.

And that the audio player could ID the speaker:

image

And a quick video:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

mp3 player

Next I thought it would be useful to create an mp3-player app that would play music stored on the USB drive.  This turned out be be a lot more challenging than I expected.  This seems like it would be a simple task with a Linux OS, but the difficulty arises with implementing it in the AppLab environment.  Apps in AppLab are created in a sandboxed environment that is implemented using Docker containers.  I didn't initially grasp the all the ramifications of this and I did what I usually do and created a global mount point for the USB drive.  Linux could see the drive which is an HP 150 32GB drive that I use to store a single MP3 file borrowed from a previous project.  It was found as Bus 001 Device 006 in the previous USB scan.  It is drive /dev/sda with partition /dev/sda1.

image

So, I mounted the partition on directory /mnt/usb and set access permissions for the user (arduino).  And it is initially empty except for a directory that HP puts on there by default.

image

I used WinSCP to transfer the Christmas mp3 file from my host PC.

image

image

So, I thought all was good and proceeded to install a lightweight MP3 player, mpg123.

image

image

 

Good news and bad news about a sandboxed environment

It's been a while since I've worked in a sandboxed environment, so I thought that I had done what was required to run my app.  I referenced the file I wanted to play as being located in the "/mnt/usb/" directory and called the system subprocess "mpg123" to play it. 

Quick test

import subprocess
import os

# Point to your mounted USB path
MUSIC_PATH = "/mnt/usb"

def play_song(filename):
    full_path = os.path.join(MUSIC_PATH, filename)
    # '-a hw:1,0' specifies the USB speaker (Card 1, Device 0)
    # '--quiet' keeps the logs clean
    process = subprocess.Popen(["mpg123", "-a", "hw:1,0", "--quiet", full_path])
    return process

# Simple test: Play the first mp3 found
files = [f for f in os.listdir(MUSIC_PATH) if f.endswith('.mp3')]
if files:
    print(f"Now playing: {files[0]}")
    player = play_song(files[0])
else:
    print("No MP3 files found on the drive.")

The program did not run in the AppLab environment because it could not find /mnt/usb or mpg123.  This is a feature of a sandboxed environment that I hadn't considered.  The sandbox is created to isolate the app from the host Linux environment so that a misbehaving app cannot crash the system.  One of the ways that it does this by restricting file and process access to within the sandbox, so it could not access either of these elements that I had created in the system environment.

What is somewhat confusing is that the system can see and access the app file structure.  You can see the files in the mp3-player app in the WinSCP window.  There are probably many ways to solve the file problem.  One way is to create a directory in the app file structure (music in this case) and just copy files from the /mnt/usb.  Or you can mount the USB drive directly to the music directory.  I've tried both and they both work (python code stays the same)  One thing that does not work in the sandbox is a symlink to /mnt/usb.  Depending on your development requirements you might try other solutions.  

image

To solve the process/program problem I needed to install mpg123 in the sandbox python environment since it isn't installed by default.  The only way to currently install python programs in AppLab is to use requirements.txt  This requires that a package wheel is available for the program that you want to install.  It turns out that there is not a wheel currently available for python 3.13.5 which is installed in AppLab. And there is currently not the capability to build a binary from source (lots of tools missing).  So, I ended up searching for a different MP3 player and decided on pygame which is a bit more capable and resource heavy than mpg123.

image

image

 

With these changes the app worked.

 

Volume control

Since I have a Modulino Knob, I decided to add volume control and display the volume level on the LED matrix.  I initially intended to display the level as a "VU" meter style bar graph, but the 13 "pixel" horizontal resolution of the matrix is too coarse so I ended up just displaying the volume level as 0-100% in text.

image

This post has been way too long, so I'll just include the code and the demo video.

sketch.ino

#include <Arduino_Modulino.h>
#include <Arduino_LED_Matrix.h>
#include <Arduino_RouterBridge.h>

ModulinoKnob knob;
ArduinoLEDMatrix matrix;
int lastVolume = -1;

void setup() {
  Bridge.begin();
  Monitor.begin();
  Modulino.begin(Wire1);
  knob.begin();
  matrix.begin();
  knob.set(50); 
}

void loop() {
  int vol = knob.get();
  if (vol > 100) { vol = 100; knob.set(100); }
  else if (vol < 0) { vol = 0; knob.set(0); }

  if (vol != lastVolume) {
    Monitor.print("VOL:");
    Monitor.println(vol);
    Bridge.notify("volume", vol);
    
    matrix.beginDraw();
    matrix.clear(); // This is the fix for the "ghost digits"
    matrix.stroke(0xFFFFFFFF);
    matrix.textFont(Font_4x6);
    //matrix.beginText(0, 1, 0xFFFFFFFF);
    //matrix.print("V");
    // Small adjustment for positioning
    // If it's a single digit, move it right so it's centered
    if (vol < 10) {
      matrix.beginText(9, 1, 0xFFFFFFFF); 
    } else if (vol < 100) {
      matrix.beginText(5, 1, 0xFFFFFFFF);
    } else {
      matrix.beginText(1, 1, 0xFFFFFFFF);
    }
    matrix.print(vol);
    matrix.endText();
    matrix.endDraw();
    

    
    lastVolume = vol;
  }
  delay(50);
}

main.py

import os
import time
import pygame
from arduino.app_utils import App, Bridge

pygame.mixer.init()
current_dir = os.path.dirname(os.path.abspath(__file__))
MUSIC_PATH = os.path.join(current_dir, "music")

# 1. This function only handles the volume updates
def update_volume(vol_data):
    try:
        new_vol = float(vol_data) / 100.0
        pygame.mixer.music.set_volume(new_vol)
        print(f"Volume updated to: {vol_data}")
    except Exception as e:
        print(f"Volume error: {e}")

# 2. This function starts the song and returns immediately
def start_playback():
    songs = [f for f in os.listdir(MUSIC_PATH) if f.endswith('.mp3')]
    if not songs:
        print("No music found!")
        return

    pygame.mixer.music.load(os.path.join(MUSIC_PATH, songs[0]))
    pygame.mixer.music.play(-1) # -1 means loop forever
    print(f"Playing: {songs[0]}")

# Register the volume callback
# Every time the MCU calls Bridge.notify("volume", val), this runs
print("Registering 'volume' callback.")
Bridge.provide("volume", update_volume)

# Start the music
start_playback()

print("Starting App Service...")
# App.run() keeps the script alive and listens for Bridge events
App.run()

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • shabaz
    shabaz 15 days ago +1
    Nice work! Have you (or genebren or anyone else with kids/grandchildren etc) heard of "Tonies"? I learned about it about a month ago, it's something all mums desire for their kids (but in reality are…
  • shabaz
    shabaz 15 days ago in reply to ralphjy

    There's no screen (just audio), deliberately to get them off TV/tablets etc. One of the use-cases is to make them fall asleep with bedtime lullabies/classical-inspired music (which is low-quality through the small speaker unfortunately).

    There is a "blank" character (another £15) to allow uploading custom stories/songs, again very excessively priced.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy 15 days ago in reply to shabaz

    Interesting toy, but my grandson is almost 4 now and we've been trying to limit his screen time.  He gets enough of that kind of stimulation at home, so we certainly wouldn't use a toy like that here.  I've been fascinated by how he makes up his own stories and acts them out.

    That being said, I think an NFC responsive unit that could be used for educational purposes is a great idea.  I actually have NFC stuff that I could use, but don't have any idea what would be a good application for a youngster.  Maybe you guys will come up with a good example.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren 15 days ago in reply to shabaz

    That is a pretty cool idea! 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz 15 days ago in reply to genebren

    An idea I was thinking of, was rather than plastic characters (which admittedly look nice, and could even be 3D-printed and painted perhaps, since the painting could be made into an activity) was to instead use one of those tiny polaroid-like printers or cameras.. and that way if a child sees something interesting (like a tiger at the zoo) the parent takes a photo of it, and then sticks an NFC tag behind it. Then, the child has a real memory attached to the song or story. Even without a printer/camera, the tags could be stuck on the back of say small cards where the parent is responsible for drawing an illustration.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren 15 days ago in reply to shabaz

    I had not heard of this before. I see what you mean about the pricing, pretty expensive. The concept is kinda of neat, but not totally unique. There have been a few video games where you could introduce characters into the game by setting them on a portal (Skylander or Disney Infinity).

    My grandkids are 9 and 11, so there musical choices are mostly video game or other pre-teen pop characters. I think we can find suitable sound clips on the web and tie them to the animations. 

    Still cool ideas! I am now thinking how I could integrate NFC tags.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube