AudioInputAnalog and analogRead

Status
Not open for further replies.

GeppettoLab

Active member
Hi,
I'm using use the audio library without the Audio Board, to analyze a signal from a Electret Max 4466 from Adafruit, correctly modified and connected.
It works correctly but now I need to add to my project an IR sensor, the Sharp GP2Y0E02A. As i read everywhere i cannot use the analogRead() with the Audio Library because, even the Teensy 3.2 has two ADCs, some pins share the same ADC and the use of analogRead freeze the sketch.
I tested, it's true (i din't exactly understand why), but then I found on this thread a possible solution...

If I connect the mic board to an analog input that affer only to the ADC1, the audio library will use that ADC and I can use the other pins to read the analog value from IR sensor.
I tried connecting the mic to A18 (soldering the bottom of the Teensy board) but it doen't work and the sketch freeze, probably beacause the Audio library works only for ADC0 (?).
Then I connect the IR sensor to the A18 pin and the Mic to A2 pin and I have this problem:
The mic works correctly but the analogRead gives me strange values like

IRSensor 3315
IRSensor 3320
IRSensor 3210
IRSensor 65535
IRSensor 65535
IRSensor 65535
IRSensor 65535


I tried then with a simple sketch like this one:
Code:
#include <SPI.h>
#include <Audio.h>

AudioInputAnalog         adc0(A2);

void setup() {
  pinMode(A18, INPUT);
  Serial.begin(9600);
}

void loop() {

  Serial.print("IRSensor ");
  Serial.println(analogRead(A18));
  delay(100);
}

When I exclude the AudioInputAnalog line I obtain these results:
IRSensor 19
IRSensor 20
IRSensor 18
IRSensor 19
IRSensor 569
IRSensor 588
IRSensor 579
it works perfectly with a fine definition of distance from my hand

When is it included in the sketch, the same as before

IRSensor 3315
IRSensor 3320
IRSensor 3210
IRSensor 65535
IRSensor 65535
IRSensor 65535
IRSensor 65535

(the last values appear when I put my hand near the IR sensor).

What I'm not considering? It is at least possible to use analogRead with the audio library but without the Audio shield?

Thanks!
Luca
 
Status
Not open for further replies.
Back
Top