Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: AudioInputAnalog and analogRead

Hybrid View

  1. #1
    Member
    Join Date
    Nov 2014
    Location
    Italy
    Posts
    31

    AudioInputAnalog and analogRead

    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

  2. #2
    Member
    Join Date
    Nov 2014
    Location
    Italy
    Posts
    31
    I don't know how to ask for an help for this thread without write something useless like this...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •