Teensy 2 : internal LED issue with pin PD6

Status
Not open for further replies.

Maxi_CF

Member
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.


pinout2a.png


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 = analogRead(i);
// if magnitude of difference is 8 or more...
if (abs(inputAnalog - iAlag) > 7){
// calc the CC value based on the raw value
ccValue = inputAnalog/8;
// send the MIDI
usbMIDI.sendControlChange(i+20, ccValue, 14);
// set raw reading to lagged array for next comparison
iAlag = inputAnalog;
}
delay(1); // limits MIDI messages to reasonable number
Serial.println(inputAnalog[11]);


}

}
 
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.)
 
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 :p

Maybe putting a greater resistance potentiometer would do it ?
 
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?
 
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 :


teensy 2 sch.png
 
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
 
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.
 
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.
 
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

pinout2b.png
 
Last edited:
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 !
 
Status
Not open for further replies.
Back
Top