Asked — Edited

Import Respeaker USB Mic Array DOA Information To Ez-B

I am going to buy a Seeed ReSpeaker USB Mic Array.  I would like to send ReSpeaker sound Direction Of Arrival (DOA) information to Ez-b.  If can get it into Ez-b I can write a script that will send instructions to my robot Max and allow Max to point to the person speaking.  How would I go about getting this ReSpeaker information into the Ez-B script?

User-inserted image

User-inserted image

Here is the link to information concerning  Seeed ReSpeaker USB Mic Array.  I will most likely need direction on how to get it to work with Ez-B.

wiki.seeedstudio.com/ReSpeaker-USB-Mic-Array/

If link does not load.  Right click link and select the Go to wiki.seeedstudio.com/ReSpeaker-USB-Mic-Array/.  That should let you see the information.

Thanks Ellis


Related Hardware EZ-B v4
Related Controls Movement Script Script

ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

PRO
Synthiam
#9  

Oh - that could be the case as well. I only have one sensor to test with. It made sense to build a little trigger system between the sensors and the ezb using an arduino uno. You can use a smaller one like a micro or something. They're super cheap and very tiny. All you need are a few ADC's and a Serial UART to write the result to the ezb.

This code i wrote for you on the Arduino will send the microphone index that detected audio past the threshold. It'll only start triggering on that specific port again when the elapsed timeout has passed. I set that timeout to 5 seconds (5000 ms). There's some additional logic that can be added to remove false positives. For example, we can sample all ADC's and compare for the highest one AND check that against the threshold. If you want to go this path, which i think will work, i can make additional changes....


// the mininum ADC value before triggering a sound input
#define AUDIO_ADC_MIN_THRESHOLD 500

// the analog adc input pins that have an audio sensor connected
#define ADC_PINS (int[]){A0, A1, A2, A3}

// the number of pins in the array above
#define ADC_PIN_COUNT 4

// how long before resetting the sample trigger
// this prevents the same audio trigger from being detected over and over
// I set it to 5000 ms (5 seconds) for testing
#define SIGNAL_EXPIRE_TIME_MS 5000

// we keep track of the last time a trigger was detected
unsigned long LAST_TIMES[ADC_PIN_COUNT];

void setup() {
   
  Serial.begin(115200);

  // init the last times
  for (int i = 0; i < ADC_PIN_COUNT; i++)      
    LAST_TIMES = millis();
}

void loop() {

  // loop through the pins
  for (int i = 0; i < ADC_PIN_COUNT; i++) {

    // if the trigger last time hasn't expired yet, continue the loop
    if (LAST_TIMES[i] + SIGNAL_EXPIRE_TIME_MS > millis())
      continue;

    // get the current pin value 
    int val = analogRead(ADC_PINS[i]);

    // if the pin value exceeds the threshold, record the trigger time and send the index to the ezb
    if (val > AUDIO_ADC_MIN_THRESHOLD) {

      LAST_TIMES[i] = millis();

      Serial.write(i);
    }    
  }
}

Now that the arduino has sent the triggered index to the ezb via UART, we have to detect it on the ezb. To do this, we first need to initialize the uart that you'll be using. I do this in the connection control using JAVASCRIPT...


// initialize the hardware uart to 115200 baud
UART.initHardwareUart(0, 115200);

// Start the check audio loop
ControlCommand("Check Audio", "ScriptStart");

Now we need to detect and do something with the data from the hardware uart. A script that runs in the background is a good idea. As you can see in the above script, i called this one [i]Check Audio.  This will be started when a connection occurs from the script above.



while (true) {
   
  var avail = UART.hardwareUartAvailable(0);
   
   if (avail > 0) {
   
  var data = UART.hardwareUartRead(0, avail);
   
  for (i = 0; i < data.length; i++) { 
         
    print("Sound detected on mic: " + data[i]);
  }             
   }   
   
   // pause for a bit, no need to get crazy 
   sleep(1000);         
}

PRO
Synthiam
#10  

On the code above - for some reason our website parsed and removed all the array [] references. I’ll have to get Amin to look at that this week. So the code is broke:(

#11   — Edited

On the above comment about voltage.  The sound sensor was powered with 5V.  I try to keep those correct.

Thanks DJ for catching the code issue and writing the code for using arduino.

PRO
Synthiam
#12  

5v with a common ground?

#13  

You are right.  Common Ground!  I always try to do this but sometimes I can forget.  Thanks for the advice.

#14  

Did anyone fix the array problem?

PRO
Synthiam
#15  

It's in the website bug report list - hasn't been done yet. Several things in front:D