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
  • Forum
  • 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 1473 views
  • Likes 10 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 4 months 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 4 months ago

    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 unaffordable for parents). It is basically a cube-shaped audio player, with a NFC surface on top. Then, parents are supposed to purchase plastic toy characters which have embedded NFC tags. The child places it on the cube, and the cube makes a request to the cloud, to download the appropriate audio file (either music or an audiobook) into Flash storage. There is enough capacity to cache lots of files, so that subsequently there's no delay to download the files.

    The ridiculous thing is that each plastic character costs about £15, so effectively it becomes more of a gift for aunts/uncles to give, rather than parents to buy, because a child would soon want different music/stories. It's as crazy as if iTunes were to charge £15 for a song!

    Tonies is very popular, because it visually looks very "instagram-friendly", with all the cute plastic characters on magnetic shelves, so you can stick them on a wall near the child's bed etc. And when parents get together, if other mums see it on a shelf, then all of them want it for their kids. Plus, many department stores have walls full of the different characters in see-through pouches, to encourage people to build a collection for their toddlers. Really clever marketing all round.

    I wish there were an open source alternative, perhaps using an off-the-shelf better quality bookcase speaker. For music, Tonies is actually very poor quality in my opinion (since it has a small speaker in a small plastic case), it hurts my ears listening to a children's song on it.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB 4 months ago

    Nice post, good sound.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren 4 months ago in reply to ralphjy

    I am using a ATMEGA328PB (my go to micro). Due to a shortage of RAM, I am doing some realtime decompression to hold a line at time scan images.

    These LED panels have real simple hardware, on/off controls. The software has to handle all the PWM to mange variable intensities as well as line at a time multiplexing. Real brute force stuff, requiring a lot of realtime work.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy 4 months ago in reply to genebren

    That sounds like fun.  What are you using for the controller?   You can do a lot with a larger matrix of rgb leds.

    I wish the Uno Q had used a small OLED display rather than the discrete led matrix.  Hard to get a useful display with 13x8 pixels and monochrome.  It does support software grayscale which I haven’t used yet.  I would have preferred to have multi line text capability.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren 4 months ago

    Very cool! Thanks for sharing.

    I am currently working on a simple animation panel (64x32 pixels) that will include a MP3 player for my Grandkids.  The idea is to allow them to generate some images that can be animated onto a fixed background image (think simple flip books with some editor tools to provide side scrolling).  Tie in some triggerable sound clips to provide entertain sound bites.

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

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube