Contents[Hide]
Download zip archive

Description

We use the microphone on the Kiwi Multi-Sensor for this app note. You'll use the to collect data and then save the data to a file on a PC for later analysis. For data collection we are making use of the microphone.

The overall process is as follows, assuming you have two .NOWs, one set up for collecting and another for exfiltration. 

  • Use the Kiwi Microphone Data Collector ("Data Collector") to collect the data. Put a microSD card into the .NOW set up for collecting and then start the program. It will collect data until you tell it to stop by pressing a button. The data are stored on the microSD card. The sampling interval is 1000 microseconds, which is 1000 samples per second.

  • You can use the Data Collector Exfiltrator ("Exfiltrator") and the Data Collector Host ("Host") to transfer the data from the microSD card to a PC. 

Compatibility

eMote.NOW 1.0, eMote version 4.3.1.12 and Visual Studio 2012.

Key Ideas

Overall, the app note illustrates how to collect microphone data and exfiltrate to a PC. We buffer data using DataStore and, when collection is done, copy it to a microSD card; this because writing to microSD is much slower than DataStore

Description

Collecting the radar data requires realtime performance. The analog-to-digital (ADC) driver populates buffers with samples and signals a call-back when the buffers are full. The call-back handler, ADCCallback, must deal with them before the next call-back. We do this by starting another buffer processing thread (WriteSampleBufferQueue) that waits on a semaphore. ADCCallback copies the buffers, signals WriteSampleBufferQueue, and returns.

  • Collection should continue even if buffer processing takes too long. Sometimes the time it takes for WriteSampleBufferQueue to deal with a particular pair of buffers is longer than the time it takes to collect the next pair. We handle this by setting up a circular queue of buffer pairs. ADCCallback inserts the current pair into the queue and WriteSampleBufferQueue dequeues and processes them. If processing for one pair takes too long but subsequent pairs take sufficiently less time, it can catch up without missing data. If the queue gets full, we declare a bad collect and terminate with an error.
  • Collection should not be disrupted by garbage collection. The eMote garbage collector, GC, runs when free space on the heap runs low. GC, which starts spontaneously, can interrupt any part of the program. We avoid this by ensuring that the free space does not decrease during the collection itself. Primarily, this means that the buffers needed for enqueing are pre-allocated. In addition, if the Visual Studio debugger is not attached, Debug.Print statements (which create and discard strings and therefore reduce free space) are suppressed.
  • Sample storage should be fast enough to keep up with collection. Writing to the microSD card is fairly slow: too slow do in real time. Instead, we collect to DataStore storage and when done, copy from DataStore to the microSD card. The Persistent Object Storage app note also shows how to use DataStore.

Setup

For convenience, we recommend using multiple .NOWs: one for the Data Collector and another for Exfiltrator. If necessary, you can use just one .NOW, deploying the program you need when you need it. 

Connect the Kiwi Multi-Sensor to the .NOW as follows.

Kiwi     .NOW
Name Pin   Name Pin
Mic Out J2/5   ADC 1 J12/8
Mic Power J2/10   +2v J11/2
Gnd J2/11   Ground  J12 / 10
Vin J2/12   VOut J11/1

Next, connect a momentary contact, single pole, single throw push-button switch to the .NOW as follows:

.NOW
Name Pin
GPIO_J11_PIN5 J11 / 5
Ground J12 / 10

The switch is used to let the Data Collector know that sampling should stop.

We're using a single source of power. It can be either USB power from a PC or some other USB power source, or a battery pack with of at least 3.65 v. A 3-cell battery pack with nominal 4.5 v works well. For field use, it's convenient to have an on-off switch on the battery pack.

Operation

Install a microSD card into the .NOW. To open the connector, slide it towards the radio antenna (away from the battery connector). It will move about 4 mm. Raise the top of the connector by lifting from the antenna side. It will lift back about 120 degrees, allowing you to insert or remove the microSD card. When inserting, the pins on the card must contact the pins on the board. To close the connector, lay the top back flush with the board and slide away from the antenna (towards the battery connector). Always take care to be gentle as the hinge is easily damaged.

  • Connect power. This can be either USB power or battery power if at least 4 v. 
  • Check for error. If there is a problem accessing the microSD card, you'll see "err" displayed on the .NOW LCD panel.
  • Start collection. When you're ready, press the reset button to restart the program. See .NOW Board Components for the location of the reset button. After a brief start up, the LCD panel will display "cccc". Move out of the sampling field; the BumbleBee has a maximum range of about 10 meters. 
  • When you are finished collecting, press the momentary-contact push button that you attached. This will stop the collection.
    • On the .NOW LCD panel you will see "xxxx" as it processes the final buffers of data that were collected, followed by "tttt" as the data are copied from DataStore to the microSD card. When all is done, you will see "0000" (all zeroes).
    • If you see "err", there was some hardware error and the collection failed.
    • If you see "full", the sample buffer queue filled because processing took too long. Again, the collection failed.
  • Disconnect power. This is optional if you're using USB power. If you're using battery power, turn off the battery or remove the connector to avoid draining the battery when not collecting.

Standards for microSD cards in the industry are loose and not all cards work on all systems. We have found good results with cards made by SanDisk. For ordinary data collection, a 2 GB capacity is more than enough.

After you collect, you can use the Data Collector Exfiltrator and Data Collector Host app notes to copy the data from the microSD card to a disk file on the PC.

After you have the data on a PC you can use the provided MATLAB Scripts to visualize the data. Alternatively, you can use Audacity (a free, open-source, multi-platform audio editor) to graph the data and listen to it. To do so, start Audacity and then:

  • Click File > Import > Raw Data.
  • Select the file, such as MicTest.data and click Open.
  • On the Import Raw Data form, choose Encoding: Unsigned 8 bit PCM; Byte order: No endianness; Channels: 1 Channel (Mono); Start offset: 0; Amount to import: 100; Sample rate: 1000. Changes from the default are in bold. Click Import.

Suggestions

Try integrating the Wireless Data Collector app note with this app so that collected values are sent wirelessly by Data Collector to Exfiltrator and thence directly to Host, bypassing the need to use a microSD card for intermediate storage.