Microphone not working on Adafruit Circuit Prayground Expres

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Microphone not working on Adafruit Circuit Prayground Expres

Post by jrwst36 »

Hello,

I just received my Adafruit Circuit Playground Express in my Adabox006. It's really a cool little thing. However, I believe that the microphone is broken. For example, none of the example sketches involving the microphone respond to sound. Also if I write a simple program to write the microphone output to the serial.print() it just prints 0.

I did that with this code.

Code: Select all

a = CircuitPlayground.mic.peak(10); // 10 ms of audio
Serial.println(a);
Is my microphone broken?

User avatar
danhalbert
 
Posts: 4653
Joined: Tue Aug 08, 2017 12:37 pm

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by danhalbert »

Please try the new 2.2.0rc1 version of CircuitPython. The microphone support has been much improved in that version.

Download this: https://github.com/adafruit/circuitpyth ... .0-rc1.uf2
from this page: https://github.com/adafruit/circuitpython/releases
and install by double-clicking the reset button, then copying the .uf2 file onto the CPLAYBOOT drive. Wait for CIRCUITPY to reappear. The contents of your CIRCUITPY drive will not change.

Let us know if this fixes the problems. Thanks!

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

I downloaded the file and copied it over to the attached CPLAYBOOT drive. Like you said, the drive disappeared and then reappeared. However, the microphone still has no functionality.

User avatar
danhalbert
 
Posts: 4653
Joined: Tue Aug 08, 2017 12:37 pm

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by danhalbert »

Sorry, I thought you were using CircuitPython, not Arduino. I didn't read your code sample carefully enough. I'll get back to you in a little while with another test.

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

To be explicit, I've tried the 'mic_meter' and 'Birthday_Candles' sketches with no results from the microphone, and my custom code to read the microphone output which results in streaming 0's.

Also the sketch 'mic_fft' doesn't compile.
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Adafruit Circuit Playground Express.

User avatar
danhalbert
 
Posts: 4653
Joined: Tue Aug 08, 2017 12:37 pm

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by danhalbert »

I've had a chance to look at the Arduino CircuitPlayground library now. The microphone code there works only with the analog microphone on the Circuit Playground Classic board. You have a Circuit Playground Express, which has a digital MEMS microphone. We have a preliminary library which supports that kind of microphone here: https://github.com/adafruit/Adafruit_ZeroPDM, but we haven't yet updated the CircuitPlayground Arduino library to use it.

However, since you got Adabox 006, which has a bunch of associated projects that use CircuitPython, I'd recommend you try the microphone with CircuitPython support. You can read about how to use CircuitPython in the Learn Guides: https://learn.adafruit.com/adabox006/ad ... n-projects and https://learn.adafruit.com/adafruit-cir ... ed-install. Copy the .uf2 file I mentioned above back to the board.

To test the microphone, copy the program below to CIRCUITPY as "main.py". If you're on Windows, then "Eject" the drive. It will not actually eject, but the Eject guarantees that the file is completely written. The program should start to run: it's a simple VU-meter-like application, so play sound or talk into the microphone. The Neopixels should light according to the sound level.

This is a slightly-hacked-up demo program, and we'll have a more final version in the near future.

Code: Select all

import audiobusio
import board
import math
import neopixel
import time

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1, auto_write=False)
pixels.fill((0, 0, 0))
pixels.show()


mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, frequency=16000)
volume_sample = bytearray(320)
mic.record(volume_sample, len(volume_sample))
print(volume_sample)
input_floor = max(volume_sample) - min(volume_sample) +1
print("Input floor: ", input_floor)

peak = 0

def pin(value, floor=None, ceiling=None):
    assert floor is not None or ceiling is not None
    assert floor is None or ceiling is None or ceiling > floor
    if floor is not None and floor > value:
        return floor
    if ceiling is not None and ceiling < value:
        return ceiling
    return value


def fscale(original_min, original_max, new_begin, new_end, input_value, curve):
    if original_min > original_max:
        return 0
    curve = pin(curve, floor=-10, ceiling=10)
    curve = math.pow(10, curve*-0.1)
    input_value = pin(input_value, floor=original_min, ceiling=original_max)
    normalized_cur_val = (input_value - original_min) / (original_max - original_min)
    return new_begin + math.pow(normalized_cur_val, curve) * (new_end - new_begin)


volume_color = (200, 100, 0)
peak_color = (100, 0, 255)

while True:
    # Sample audio for a bit.
    mic.record(volume_sample, len(volume_sample))
    #print(volume_sample)
    magnitude = max(volume_sample) - min(volume_sample)
    print(magnitude)
    c = fscale(input_floor, 120, 0, 10, magnitude, 2)
    # Light up pixels that are below the scaled and interpolated magnitude.
    pixels.fill((0, 0, 0))
    for i in range(10):
        if i < c:
            pixels[i] = volume_color
    # Light up the peak pixel and animate it slowly dropping.
    if c >= peak:
        peak = min(c, 9)
    elif peak > 0:
        peak = peak - 1
    if peak > 0:
        pixels[int(peak)] = peak_color
    pixels.show()

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

Thank for your help. I was able to get another CircuitPython program to work ( the Snow Globe demo). But the code you sent me doesn't produce any results.

User avatar
danhalbert
 
Posts: 4653
Joined: Tue Aug 08, 2017 12:37 pm

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by danhalbert »

Could you try this with the 2.2rc1 .uf2 in the REPL (use a terminal program)?

Code: Select all

import board, audiobusio
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, frequency=16000)
b = bytearray(200)
mic.record(b, len(b))
print(b)
See if b is all zeros. If it is, then the microphone does have a problem, and we need to get you a new CPX.

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

Sorry, can you be a little more specific on what to do? I'm understanding run that code on the Circuit Playground, and look for the output on the terminal while running the REPL program. That REPL program doesn't seem to be a built in program in the terminal. Is it?

User avatar
danhalbert
 
Posts: 4653
Joined: Tue Aug 08, 2017 12:37 pm

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by danhalbert »

What operating system are you using? Then I can be more specific.

This guide section describes how to use Putty on Windows and screen on MacOS or Linux.
https://learn.adafruit.com/adafruit-cir ... nsole-repl
(To exit screen on Mac, type ctrl-A ctrl\)

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

I'm on a mac.

I have our code on the main.py and the REPL running. See attached pics. But the REPL isn't registering any incoming data.
Attachments
Screen Shot 2017-12-17 at 5.27.49 PM.png
Screen Shot 2017-12-17 at 5.27.49 PM.png (37.66 KiB) Viewed 697 times
Screen Shot 2017-12-17 at 5.26.00 PM.png
Screen Shot 2017-12-17 at 5.26.00 PM.png (49.66 KiB) Viewed 697 times

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

If I have the REPL already open and then drop the main.py file in to the CIRCUITPY drive, then I get the following output in terminal. (attached)
Attachments
Screen Shot 2017-12-17 at 5.37.58 PM.png
Screen Shot 2017-12-17 at 5.37.58 PM.png (44.34 KiB) Viewed 696 times

User avatar
danhalbert
 
Posts: 4653
Joined: Tue Aug 08, 2017 12:37 pm

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by danhalbert »

If you are at the ">>>" prompt and type ctrl-D, then CircuitPython will restart and will run main.py. But the all zeros means that the mic does not seem to be working. Write to [email protected] and ask for a new Circuit Playground Express, with a pointer to this thread. Give them your order number as well.

User avatar
jrwst36
 
Posts: 39
Joined: Sun Apr 17, 2011 8:22 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by jrwst36 »

I will do that, and thank you for all your help.

stevenquinn
 
Posts: 19
Joined: Sun Mar 26, 2017 1:24 am

Re: Microphone not working on Adafruit Circuit Prayground Ex

Post by stevenquinn »

Was looking for something only slight related (I'll post another topic) but I noticed here I'm getting the same result as the other person in this thread, all 00s when using that demo code. BUT I was first playing around with makecode and the mic input there seemed to work for me.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”