LED pins give problems with pullups.

Status
Not open for further replies.

Djinny

Member
Alright, this is my teensy ++2.0 code, i have the same problem on my teensy 3.2 on pin 13.

Pin6 on the ++2, and pin13 on the T3.2, have the same problems.
They have LEDs on them, and when i use this code, they don't trigger.

These are all common Ground buttons, and i need to keep them common ground, so i can't have P6/P13 as a normal input. it has to have the internal pullup.
This code as is, has pin37 also shared to joystick button 7
Any way to fix this without physically removing the LED? Is there something that i'm simply missing?
What ever fix you can come up with, i'd like for it to work for the Teensy 3.2 as well. Thank you.

Code:
//Teensy++2.0
#include <Bounce.h>

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10);  // which is appropriate for
Bounce button3 = Bounce(3, 10);  // most mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10);
Bounce button6 = Bounce(6, 10);
Bounce button7 = Bounce(7, 10);
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
Bounce button10 = Bounce(10, 10);
Bounce button11 = Bounce(11, 10);  // 10 = 10 ms debounce time
Bounce button12 = Bounce(12, 10);  // which is appropriate for
Bounce button13 = Bounce(13, 10);  // most mechanical pushbuttons
Bounce button14 = Bounce(14, 10);
Bounce button15 = Bounce(15, 10);
Bounce button16 = Bounce(16, 10);
Bounce button17 = Bounce(17, 10);
Bounce button18 = Bounce(18, 10);
Bounce button19 = Bounce(19, 10);
Bounce button20 = Bounce(20, 10);
Bounce button21 = Bounce(21, 10);
Bounce button22 = Bounce(22, 10);
Bounce button23 = Bounce(23, 10);
Bounce button24 = Bounce(24, 10);
Bounce button25 = Bounce(25, 10);
Bounce button26 = Bounce(26, 10);
Bounce button27 = Bounce(27, 10);
Bounce button28 = Bounce(28, 10);
Bounce button29 = Bounce(29, 10);
Bounce button30 = Bounce(30, 10);
Bounce button31 = Bounce(31, 10);
Bounce button32 = Bounce(32, 10);
Bounce button33 = Bounce(33, 10);
Bounce button34 = Bounce(34, 10);
Bounce button35 = Bounce(35, 10);
Bounce button36 = Bounce(36, 10);
Bounce button37 = Bounce(37, 10);



void setup() {
  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);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(19, INPUT_PULLUP);
  pinMode(20, INPUT_PULLUP);
  pinMode(21, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
  pinMode(23, INPUT_PULLUP);   
  pinMode(24, INPUT_PULLUP);
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);
  pinMode(27, INPUT_PULLUP);
  pinMode(28, INPUT_PULLUP);
  pinMode(29, INPUT_PULLUP);
  pinMode(30, INPUT_PULLUP);
  pinMode(31, INPUT_PULLUP);
  pinMode(32, INPUT_PULLUP);
  pinMode(33, INPUT_PULLUP);   
  pinMode(34, INPUT_PULLUP);
  pinMode(35, INPUT_PULLUP);
  pinMode(36, INPUT_PULLUP);
  pinMode(37, INPUT_PULLUP); 
}

void loop() {
  // read analog inputs and set X-Y position
  Joystick.X(analogRead(A0));
  Joystick.Y(1023 - analogRead(A1));
  Joystick.Z(analogRead(A2));
  //Joystick.Xrotate(analogRead(A3)); //commenting these out so other people can use this.
  //Joystick.Yrotate(analogRead(A4));
  Joystick.Zrotate(analogRead(A5));
  Joystick.sliderLeft(analogRead(A6));
  Joystick.sliderRight(analogRead(A7));

  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button0.update();
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();
  button10.update();
  button11.update();
  button12.update();
  button13.update();
  button14.update();
  button15.update();
  button16.update();
  button17.update();
  button18.update();
  button19.update();
  button20.update();
  button21.update();
  button22.update();
  button23.update();
  button24.update();
  button25.update();
  button26.update();
  button27.update();
  button28.update();
  button29.update();
  button30.update();
  button31.update();
  button32.update();
  button33.update();
  button34.update();
  button35.update();
  button36.update();
  button37.update();

  // Check each button for "falling" edge.
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button0.fallingEdge()) {
    Joystick.button(1, 1);
  }
  if (button1.fallingEdge()) {
    Joystick.button(2, 1);
  }
  if (button2.fallingEdge()) {
    Joystick.button(3, 1);
  }
  if (button3.fallingEdge()) {
    Joystick.button(4, 1);
  }
  if (button4.fallingEdge()) {
    Joystick.button(5, 1);
  }
  if (button5.fallingEdge()) {
    Joystick.button(6, 1);
  }
  if (button6.fallingEdge()) {
    Joystick.button(7, 1);
  }
  if (button7.fallingEdge()) {
    Joystick.button(8, 1);
  }
  if (button8.fallingEdge()) {
    Joystick.button(9, 1);
  }
  if (button9.fallingEdge()) {
    Joystick.button(10, 1);
  }
  if (button10.fallingEdge()) {
    Joystick.button(11, 1);
  }
  if (button11.fallingEdge()) {
    Joystick.button(12, 1);
  }
  if (button12.fallingEdge()) {
    Joystick.button(13, 1);
  }
  if (button13.fallingEdge()) {
    Joystick.button(14, 1);
  }
  if (button14.fallingEdge()) {
    Joystick.button(15, 1);
  }
  if (button15.fallingEdge()) {
    Joystick.button(16, 1);
  }
  if (button16.fallingEdge()) {
    Joystick.button(17, 1);
  }
  if (button17.fallingEdge()) {
    Joystick.button(18, 1);
  }
  if (button18.fallingEdge()) {
    Joystick.button(19, 1);
  }
  if (button19.fallingEdge()) {
    Joystick.button(20, 1);
  }
  if (button20.fallingEdge()) {
    Joystick.button(21, 1);
  }
  if (button21.fallingEdge()) {
    Joystick.button(22, 1);
  }
  if (button22.fallingEdge()) {
    Joystick.button(23, 1);
  }
  if (button23.fallingEdge()) {
    Joystick.button(24, 1);
  }
  if (button24.fallingEdge()) {
    Joystick.button(25, 1);
  }
  if (button25.fallingEdge()) {
    Joystick.button(26, 1);
  }
  if (button26.fallingEdge()) {
    Joystick.button(27, 1);
  }
  if (button27.fallingEdge()) {
    Joystick.button(28, 1);
  }
  if (button28.fallingEdge()) {
    Joystick.button(29, 1);
  }
  if (button29.fallingEdge()) {
    Joystick.button(30, 1);
  }
  if (button30.fallingEdge()) {
    Joystick.button(31, 1);
  }
  if (button31.fallingEdge()) {
    Joystick.button(32, 1);
  }
  if (button32.fallingEdge()) {
    Keyboard.press(KEY_1);
  }
  if (button33.fallingEdge()) {
    Keyboard.press(KEY_2);
  }
  if (button34.fallingEdge()) {
    Keyboard.press(KEY_3);
  }
  if (button35.fallingEdge()) {
    Keyboard.press(KEY_4);
  }
  if (button36.fallingEdge()) {
    Keyboard.press(KEY_5);
  }
  if (button37.fallingEdge()) {
    Joystick.button(7, 1);
  }
  
  // Check each button for "rising" edge
  // Update the Joystick buttons only upon changes.
  // rising = low (pressed - button connects pin to ground)
  //          to high (not pressed - voltage from pullup resistor)
  if (button0.risingEdge()) {
    Joystick.button(1, 0);
  }
  if (button1.risingEdge()) {
    Joystick.button(2, 0);
  }
  if (button2.risingEdge()) {
    Joystick.button(3, 0);
  }
  if (button3.risingEdge()) {
    Joystick.button(4, 0);
  }
  if (button4.risingEdge()) {
    Joystick.button(5, 0);
  }
  if (button5.risingEdge()) {
    Joystick.button(6, 0);
  }
  if (button6.risingEdge()) {
    Joystick.button(7, 0);
  }
  if (button7.risingEdge()) {
    Joystick.button(8, 0);
  }
  if (button8.risingEdge()) {
    Joystick.button(9, 0);
  }
  if (button9.risingEdge()) {
    Joystick.button(10, 0);
  }
  if (button10.risingEdge()) {
    Joystick.button(11, 0);
  }
  if (button11.risingEdge()) {
    Joystick.button(12, 0);
  }
  if (button12.risingEdge()) {
    Joystick.button(13, 0);
  }
  if (button13.risingEdge()) {
    Joystick.button(14, 0);
  }
  if (button14.risingEdge()) {
    Joystick.button(15, 0);
  }
  if (button15.risingEdge()) {
    Joystick.button(16, 0);
  }
  if (button16.risingEdge()) {
    Joystick.button(17, 0);
  }
  if (button17.risingEdge()) {
    Joystick.button(18, 0);
  }
  if (button18.risingEdge()) {
    Joystick.button(19, 0);
  }
  if (button19.risingEdge()) {
    Joystick.button(20, 0);
  }  
  if (button20.risingEdge()) {
    Joystick.button(21, 0);
  }  
  if (button21.risingEdge()) {
    Joystick.button(22, 0);
  }
  if (button22.risingEdge()) {
    Joystick.button(23, 0);
  }
  if (button23.risingEdge()) {
    Joystick.button(24, 0);
  }  
  if (button24.risingEdge()) {
    Joystick.button(25, 0);
  }
  if (button25.risingEdge()) {
    Joystick.button(26, 0);
  }
  if (button26.risingEdge()) {
    Joystick.button(27, 0);
  }  
  if (button27.risingEdge()) {
    Joystick.button(28, 0);
  }
  if (button28.risingEdge()) {
    Joystick.button(29, 0);
  }
  if (button29.risingEdge()) {
    Joystick.button(30, 0);
  }  
  if (button30.risingEdge()) {
    Joystick.button(31, 0);
  }
  if (button31.risingEdge()) {
    Joystick.button(32, 0);
  }
  if (button32.risingEdge()) {
    Keyboard.release(KEY_1);
  }
  if (button33.risingEdge()) {
    Keyboard.release(KEY_2);
  }  
  if (button34.risingEdge()) {
    Keyboard.release(KEY_3);
  }
  if (button35.risingEdge()) {
    Keyboard.release(KEY_4);
  }
  if (button36.risingEdge()) {
    Keyboard.release(KEY_5);
  }
  if (button37.risingEdge()) {
    Joystick.button(7, 0);
  }
}
 
The "problem" is that the LED pins are naturally pulled down by the LED in series with a 470R (Teensy 3.2) or 1000R (Teensy 2++) resistor which is too much load for the internal >10k pull up resistor.

Besides unsoldering either the LEDs or the corresponding series resistors, you might reinforce the pull up current by adding external pull up resistors to these pins. For the Teensy 3.2 a 330R resistor between pin 13 and +3.3V, and for the Teensy 2++ a 560R resistor between pin 6 and +5V should do the job in conjunction with push buttons between the pin and GND.
 
I'll try the resistors to +v.
Though i don't have a problem removing the LED's resistors, i don't care about the LEDs at all, i won't be able to see them once the Teensys are installed.
Thank you.
 
It's a lot more than just 8 axis. and just changing the descriptor won't do it.
This is what all my stuff does.
8 axis, all 10bit., y axis is reversed, so up is actually up.
32 joypad buttons (directinput maximum)
and keyboard keys #1-6 (not numpad), this is just to exceed the maximum 32 :D
no hat switches. none of my games register the hat switches right, they always just detect them as 4 gamepad buttons anyways.

This is for teensy 2.0++, but could work for teensy 2.0 as well, with some tweaks to the ino.

You have to set it to keyboard/mouse/joystick, and not serial/keyboard/mouse/joystick. And you replace the usb_hid, not the usb_serial_hid, or what ever.
to use pin6, you'll need to either use the booster resistor to 5v, mentioned a couple posts up, or remove the LED's resistor.
I used the booster resistor and it worked fine, but i just removed the resistor in the end simply because i don't need an LED.

There's a "binaries" file in there, it's just a simple txt file that didn't get the .txt added. It was just to help me figure out what everything had to be.

Edit: Really Paul should make 8 Axis the default. It's possible to add hats to my current config pretty easily at the end. Since windows detects up to 8 axis (from what i can tell) it should be the default.
Even my T3.2 uses 8 axis now. ^_^
 

Attachments

  • usb_hid.zip
    17.4 KB · Views: 61
Last edited:
Thanks for code.
But... the zip doesnt have the joystick class file (usb_joystick.h).
:confused:

Another, i tried to change the usb descripto file by adding to extra axes (rx, ry) however when i build it only shows the original 6 (using the default files) so i guess there is some other file that nees updating. so far no luck finding which one or ones.
Any help you can give?
 
Last edited:
My code is for the Teensy++ 2.0 and the 2.0, not the 3.0 or higher.

For 3.1 and 3.2, and probably the other cortex, you want this one. https://forum.pjrc.com/threads/33294-Posting-my-Teensy-Joystick-codes-so-other-people-can-use-it

usb_hid is for 2.0/++2.0, the usb_joystick.h file is for the teensy 3.x, which is why it's in the teensy3 core folder.
Since i did something similar for the 3.2 i should note, it's only 16 button, and you can't just change it to 32buttons, it requires quite a bit of alterations to make it work for 32 buttons. I only needed 16, so it's 16.
 
Last edited:
Status
Not open for further replies.
Back
Top