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

Thread: Teensy 2 : internal LED issue with pin PD6

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    7

    Teensy 2 : internal LED issue with pin PD6

    Hey everyone !

    I'm building a project using Teensy 2, and everything works perfectly.

    Except for one thing : I'm using the 12 Analog In pins to measure voltages coming from potentiometers. It works fine with every pin, but the PD6 one .. which is connected to the internal LED.

    When changing the voltage on that pin, the luminosity of the LED changes (which is fine) the problem is I canot get the voltage down to 0 ..

    I'm then using the AnalogRead function and converting it into a MIDI information. But the MIDI message will go down to 2 and not 0.
    (For other Analog Inputs I can do 0-127, but this one only 2-127).


    I though there might be a way to deactivate the LED to solve the problem, but haven't been able to figure it out.


    Any information would be useful
    Many thanks ! Max.


    Click image for larger version. 

Name:	pinout2a.png 
Views:	24 
Size:	242.9 KB 
ID:	12117


    I don't think it is because of a mistake into my code, but just in case :


    #include <Bounce.h>

    // define how many pots are active up to number of available analog inputs
    #define analogInputs 12
    // make arrays for input values and lagged input values
    int inputAnalog[analogInputs];
    int iAlag[analogInputs];
    // make array of cc values
    int ccValue[analogInputs];
    // index variable for loop
    int i;


    void setup() {
    // MIDI rate
    Serial.begin(31250);
    pinMode(0, INPUT_PULLUP);
    pinMode(1, INPUT_PULLUP);
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(4, INPUT_PULLUP);
    pinMode(5, INPUT_PULLUP);
    pinMode(6, INPUT_PULLUP);
    pinMode(7, INPUT_PULLUP);
    pinMode(8, INPUT_PULLUP);
    pinMode(9, INPUT_PULLUP);
    pinMode(10, INPUT_PULLUP);
    pinMode(11, INPUT_PULLUP);
    }

    void loop() {
    // loop trough active inputs for knobs
    for (i=0;i<analogInputs;i++){
    // read current value at i-th input
    inputAnalog[i] = analogRead(i);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 7){
    // calc the CC value based on the raw value
    ccValue[i] = inputAnalog[i]/8;
    // send the MIDI
    usbMIDI.sendControlChange(i+20, ccValue[i], 14);
    // set raw reading to lagged array for next comparison
    iAlag[i] = inputAnalog[i];
    }
    delay(1); // limits MIDI messages to reasonable number
    Serial.println(inputAnalog[11]);


    }

    }

  2. #2
    Not familiar with the Teensy 2, but desoldering the LED should deactivate it. I'm guessing that that your measurement is messed up by some leakage current through the LED.

    I have the T3.2 and I use the pin with the LED only as a status indicator. (on, off, bllinking fast/short, etc.)

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Thanks for your answer

    Actually I'm planning on doing about 30 items, each having a teensy in it so I'd rather find an other solution that desoldering

    Maybe putting a greater resistance potentiometer would do it ?

  4. #4
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,265
    FWIW, on a Teensy 2.0, I just ran a simple loop printing out the value of analogRead(A10). If I jumper A10 to 5v, i get 1020 (and LED comes on). If i jumper to GND, i get 0. Can you try that as a test? Does your pot actually go to 0/GND?

  5. #5
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Thanks for your feedback !

    So I did just that and here are the results :
    At the potentiometer signal pin I measured 0V
    Through the AnalogRead I get a value of 15/16
    And the MIDI message is 2

    This is really weird, and I don't understand the problem .. the thing is this only occurs on this specific pin, though all my potentiometers are daisy chained.
    It also happens on all my three prototypes, exactly the same way.

    A schematic explaining the situation :


    Click image for larger version. 

Name:	teensy 2 sch.png 
Views:	15 
Size:	41.8 KB 
ID:	12125

  6. #6
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Quote Originally Posted by manitou View Post
    FWIW, on a Teensy 2.0, I just ran a simple loop printing out the value of analogRead(A10). If I jumper A10 to 5v, i get 1020 (and LED comes on). If i jumper to GND, i get 0. Can you try that as a test? Does your pot actually go to 0/GND?
    Hey,

    So I just took a new Teensy 2, never used before.
    Tested analogread on A10 and when connected to ground I get 16..
    I think this is just an inherent problem due to the LED.

    Do you know if I can solve this by using a bit of code ?
    Like if analogread(A10)=16 then ccValue =0

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,290
    Quote Originally Posted by Maxi_CF View Post
    At the potentiometer signal pin I measured 0V
    Normally you should get about 1.8 volts due to the LED, if the pot is turned to a position that would have made more than 1.8V. Below about 1.8V the LED conducts very little current. It may still have some effect, but it certainly should not be able to clamp the voltage so very close to GND.

    Any chance your program actually has a pinMode() and digitalWrite() for the LED? I don't see anything like that in the code you posted. But putting the pin into OUTPUT mode is the only plausible explanation for the voltage staying very close to 0 volts, and getting analogRead numbers so close to zero.

  8. #8
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,265
    Quote Originally Posted by Maxi_CF View Post
    Do you know if I can solve this by using a bit of code ?
    Like if analogread(A10)=16 then ccValue =0
    ADC values can be a bit fuzzy and affected by nearby circuitry, so you could do something like if (analogRead(A10) < 20) ...

    Are you using PJRC teensy 2s? (as opposed to counterfeits). Maybe attach a photo of your setup.

  9. #9
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,265
    maybe I see a problem in your sketch in post #1. You do pinMode(11,INPUT_PULLUP); but pin 11 is A10 ! try removing the pinMode for pin 11

    Click image for larger version. 

Name:	pinout2b.png 
Views:	6 
Size:	203.1 KB 
ID:	12141
    Last edited by manitou; 12-05-2017 at 01:49 PM.

  10. #10
    Junior Member
    Join Date
    Oct 2017
    Posts
    7
    Hey everyone,

    Thanks for your help !!
    Some pieces of answer

    - Regarding using a real Teensy : absolutely bought them on the website
    - Regarding pinMode : I have to admit I just copy pasted the example code for MIDI and I don't really know what it means .. after removing all my pinmodes this solved the problem !! I now get an analogread of 0 when my pot is at 0. Thanks a lot !!

    - An other thing I did before you mentioned this :

    ccValue[10] = 1.015*(inputAnalog[10]-15)/8;
    It worked fine as well, I got the proper MIDI notes on all the range (0-127).


    Now the only problem left is that I don't get the correct values for analogread on the rest of the range : for instance when my potentiometer is at middle position I should get 1020/2 but I get less .. 410 instead of 510.
    I think I can correct this by using a different potentiometer (more or less resistance, I still have to make some tests).

    I will keep you posted on the matter !

Posting Permissions

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