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
  • 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
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog Pi IoT - Pilot - #5 Add USB sound card and a couple of enclosures
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: sebathorus
  • Date Created: 8 Jul 2016 9:26 AM Date Created
  • Views 1019 views
  • Likes 4 likes
  • Comments 6 comments
  • piiot
  • piiot challenge
  • pi iot design challenge
  • pilot
Related
Recommended

Pi IoT - Pilot - #5 Add USB sound card and a couple of enclosures

sebathorus
sebathorus
8 Jul 2016

Hello

 

     For my project I need to have a microphone for giving voice commands and detecting sounds. Because RaspberryPi board don't have a microphone input, I used for this task an external USB sound card adapter, Konig 3D Sound, based on C-Media CM108 Audio Controller. I also add a small audio amplifier and speaker for music and audio feedback.

     USB sound card is connected to RaspberryPi through an USB Hub which act also as power distribution board for all components, see below image:

 

image

 

In order to install/enable USB sound card, let's check USB devices attached to RPi:

 

pi@pilot1:~ $ lsusb
Bus 001 Device 005: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 004: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

 

and sound modules:

 

pi@pilot1:~ $ cat /proc/asound/modules

 0 snd_bcm2835
 1 snd_usb_audio

showing that the USB soundcard is visible.

Next, I need to set snd_usb_audio (my USB soundcard) to be default sound playing device (position 0). One way to do this is to edit alsa-base.conf to load snd-usb-audio as first option. Compared to Raspbian Wheezy, in Raspbian Jessie this file no longer exists by default so I have to create it with the following content:

 

pi@pilot1:~ $ sudo nano /etc/modprobe.d/alsa-base.conf

options snd_usb_audio index=0
options snd_bcm2835 index=1
options snd slots=snd-usb-audio,snd-bcm2835

 

In /usr/share/alsa/alsa.conf configuration file check to have following lines:

 

defaults.ctl.card 0

defaults.pcm.card 0

 

Make sure you have ~/.asoundrc file populated as follow:

 

pcm.!default {
        type hw
        card 0
}
ctl.!default {
        type hw
        card 0
}

 

If not installed, install alsa-base, alsa-utils and mpg321 (or mpg123, mplayer, etc.) :

 

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install alsa-base alsa-utils mpg321 mplayer
sudo reboot

 

To check your configuration use command:

 

amixer -c 0 - to display current settings. Mine looks like this:

 

pi@pilot1:~ $ amixer -c 0
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 151
  Mono:
  Front Left: Playback 137 [91%] [-2.69dB] [on]
  Front Right: Playback 137 [91%] [-2.69dB] [on]
Simple mixer control 'Mic',0
  Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch pswitch-joined cswitch cswitch-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: Playback 0 - 127 Capture 0 - 16
  Mono: Playback 26 [20%] [4.87dB] [off] Capture 0 [0%] [0.00dB] [on]
Simple mixer control 'Auto Gain Control',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
pi@pilot1:~ $

 

and

 

alsamixer -c 0 - to modify speakers and microphone levels.

 

To check if the sound card is really working launch for example:

 

aplay -D plughw:0,0 /usr/share/sounds/alsa/Front_Center.wav

 

Ok, with playback working, let's check the recording side. Plug microphone into USB sound card input and launch:

 

arecord -D plughw:0,0 -f cd /home/pi/Music/test.wav

 

Use Ctrl+C to stop recording.

 

Check the result with the following command:

 

aplay -D plughw:0,0 /home/pi/Music/test.wav

 

Use alsamixer -c 0  to adjust sound levels to meet your requirements. That's it. Now both audio playback and recording are working on Raspberry Pi.

 

If someone know a better/cleaner way to install an external USB sound card with audio out and microphone, please share it in comments bellow.

 

     Now is time to take all pieces and put everything in a nice box. As with most of my projects, it was a real struggle to find an enclosure to fit all components I have so far and at the same time to be suitable to be put in plain sight. So after spending more than a week on this subject, I found an enclosure from a broken wireless router which looks like the right choice, still not perfect, but will do for now:

image

image

image

Situation is about the same on the sensors side where the hunt for enclosures is still on. So far only one of them have an enclosure made from a kitchen timer...

image

image

Oddly enough, "antenna" is actually the temperature sensor which have to be as far as possible from ESP module to be able to show real temperature values. So far I did not found a way to shield the sensor from radio interference caused by ESP module and keep it inside the enclosure.

  • Sign in to reply

Top Comments

  • balearicdynamics
    balearicdynamics over 9 years ago +1
    Nice solution. I also appreciated the use of the box of a Linksys router to host the parts... Enrico
  • DAB
    DAB over 9 years ago in reply to sebathorus +1
    It looks like about 2 Watts, I am not up to speed on what a class B amplifier can do, but from the specs it looks like it can drive a pair of speakers reasonably well. Overall it appears to be a very good…
  • sebathorus
    sebathorus over 9 years ago in reply to balearicdynamics

    Thanks Enrico

     

    Looks like peeling the sticker from the router did not helped much, I was caught anyway...image

     

    -=Seba=-

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • sebathorus
    sebathorus over 9 years ago in reply to DAB

    I think 2W sounds plausible. The small PC speaker I used as audio amplifier + speaker is rated at 3W.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago in reply to sebathorus

    It looks like about 2 Watts, I am not up to speed on what a class B amplifier can do, but from the specs it looks like it can drive a pair of speakers reasonably well.

     

    Overall it appears to be a very good component.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago

    Nice solution. I also appreciated the use of the box of a Linksys router to host the parts...

     

    Enrico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • sebathorus
    sebathorus over 9 years ago in reply to DAB

    Thank you

     

    I don't know exactly how much power it have, the only indication from official specification is power rating 5V/0.5A.  CM108 chip data sheet say about two power modes, 100mA and 500mA but I don't know which one is used in this case.

    I only tested it a couple of times with headphones (and volume was ok), most of the time I used it connected to a PC speaker.

     

    -=Seba=-

    • 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 © 2025 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