The sampler object represents a 12-bit ADC sampler, running from a timer and thus sampling at a given frequency. It is only available on the following imps: imp001, imp002, imp003 (Murata part number LBWA1ZV1CD) and impC001. It is not available on the imp004m (Murata part number LBEE5ZZ1MD) or the imp005 (Murata part number LBWA1UZ1GC-901).
Although the data is presented as 16-bit values, current imp hardware has only 12 bits of resolution. impOS provides a single sampler which accessed as hardware.sampler. Though the object is instantiated for you, you must configure it before use with the method sampler.configure().
The sampler can be configured to use any of the compatible imp’s ADC-capable pins at a wide range of sample rates. It can be configured to sample a single pin or a group of pins (passed into sampler.configure() as an array of pin objects), in which case all of the pins are sampled every period, almost simultaneously.
The sampler is supplied with an array of data buffers. Each time a buffer is filled, a callback function is called to process the data. Optionally, the buffers can be pre-processed with a small selection of filters: an infinite impulse response (IIR) normalizer, an A-law audio compressor, or both. See Wikipedia on A-law.
All pins on the imp001 have ADCs, and can be used with the sampler. Of the additional pins on the imp002, only Pin A and Pin B can be used; pins 1 through 8 have ADC support as per the imp001. The imp003 has a different pin nomenclature from its predecessors: its ADC pins are A-C, E, F, H-K, N and W. The impC001's ADC pins are U and W. See the imp pin mux documentation.
Sampling proceeds ‘in the background’, under interrupt; to stop the sampler after a certain time, set a timer with imp.wakeup().
When a buffer containing samples is ready for processing, a nominated function is called automatically. This function is registered using sampler.configure() and must be implemented if you plan to use the imp’s ADC.
The sampler object has the following member methods: