Microphone read

Discussion in 'Arduino IDE' started by andreiM, Feb 12, 2016.

  1. andreiM

    andreiM New Member

    Joined:
    Feb 12, 2016
    Messages:
    5
    Likes Received:
    0
    Hello guys. I'm a very beginner of this whole Arduino programming and using of UDOO. I have a UDOO Quad with latest LUbuntu version, a usual PC microphone with a 3.5mm jack and a couple of leds. As one of my first projects I thought of using the mic as an audio "sensor" and writing a program that listens to the mic and whenever it gets any audio wave, it returns some value that will make the led lit.
    I am pretty familiar with C++ programming but I have no idea if there are any premade libraries/functions to access the pink mic port in Arduino/Python/C languages tho I did some research before writing this thread. Any help would be useful.
    Thanks
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Andrea Rovai and andreiM like this.
  3. andreiM

    andreiM New Member

    Joined:
    Feb 12, 2016
    Messages:
    5
    Likes Received:
    0
    Thank you for the reply the first link is very clear and I understood the idea but still I'm not very sure about how I get the led lit using python, had a look at 2nd link but it doesn't say much. Could you personally explain a bit about the way I can access the led now using python? Or come up with a link. Sorry for bothering I just want to make sure I understand everything.
    Thanks

    PS1: is python the easiest/single option? Is there any way to do this only using Arduino IDE?
    PS2: what is the difference between unidirectional and bidirectional programs mentioned in the 2nd link?
     
  4. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    I only know python so I am stuck to that. Besides for a beginning programmer (like me) it is the easiest way.

    But the issue is that you cannot connect a mic to the Arduino side without an extra amplifier as the signals of a mic are not in the 0-5V (or 3.3 V) range that the Arduino needs. You can google around for this. The mic is connected to the Linux side I suppose. I don't have a quad, is there an audio in connector? So I suppose the audio analysing should be done on the Linux side. And that can be done with any programming language you want.

    In the link I gave is a link to a github were you can download the source files for the Arduino and Linux side. Open those files, they are self explaining. In the .ino file the example is used to switch a led based on information coming from the Linux side.

    Unidirectional means one way (sending commands/information from Linux to Arduino) and bidirectional means both ways. You only need the one way option.
     
    andreiM likes this.
  5. andreiM

    andreiM New Member

    Joined:
    Feb 12, 2016
    Messages:
    5
    Likes Received:
    0
    Thanks again for the reply I'm starting to get the hang of it I guess. Yes the quad has 2 audio ports 1 in 1 out and it works I just tested my mic with a sound record application and it does it's job. I'll probably post an update during the following days.
     
  6. andreiM

    andreiM New Member

    Joined:
    Feb 12, 2016
    Messages:
    5
    Likes Received:
    0
    Well I am back already @waltervl with a little issue. Here is the output of cat /proc/asound/cards:
    0 [vt1613audio ]: vt1613-audio - vt1613-audio
    vt1613-audio
    1 [imxhdmisoc ]: imx-hdmi-soc - imx-hdmi-soc
    imx-hdmi-soc

    As well as the output of arecord -l :
    **** List of CAPTURE Hardware Devices ****
    card 0: vt1613audio [vt1613-audio], device 0: HiFi vt1613-0 []
    Subdevices: 1/1
    Subdevice #0: subdevice #0

    So. as much as I understood of these, the name of the audio card or the MIC port is vt1613-audio and the name of the the audio output through hdmi is imx-hdmi-soc. As I stated before, both of these are tested and are working. So I proceeded installing the AlsaAudio library for python as I saw in the first link you posted (http://stackoverflow.com/questions/...icrophone-in-python-and-process-it-on-the-fly). Everything went smooth with the build and installation but after that I tried to run the "consistency test" as they name it. Well this was the output of python test.py:

    ...E..ALSA lib conf.c:4687:(snd_config_expand) Unknown parameters CARD=default
    ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default:CARD=default
    .
    ======================================================================
    ERROR: testPCM (__main__.PCMTest)
    Open a PCM object on every device
    ----------------------------------------------------------------------
    Traceback (most recent call last):
    File "test.py", line 96, in testPCM
    pcm = alsaaudio.PCM(device=pd)
    ALSAAudioError: Invalid argument [sysdefault:CARD=vt1613audio]

    ----------------------------------------------------------------------
    Ran 7 tests in 1.079s

    FAILED (errors=1)

    After running the python recordtest.py successfull, when I try to play with with python playbacktest.py abcd.wav, I get the following error:
    ALSA lib conf.c:4687:(snd_config_expand) Unknown parameters CARD=default
    ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default:CARD=default
    Traceback (most recent call last):
    File "playbacktest.py", line 42, in <module>
    out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, card=card)
    alsaaudio.ALSAAudioError: Invalid argument [default:CARD=default]

    I get the same error even if I type python playbacktest.py -c imx-hdmi-soc abcd.wav

    I know it's a lot of syntax here but I'd be very thankful if somebody would give me an idea/solution.
    Thanks
     
  7. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    I am sorry, can't help you with this.
     
  8. andreiM

    andreiM New Member

    Joined:
    Feb 12, 2016
    Messages:
    5
    Likes Received:
    0

Share This Page