Help an idiot sleep better tonight

Hello

As is obvious Im new here. I recently recieved my teensy 3.1 and started messing around with LED control. I was connecting various data pins to a switch and then to ground. Never could get the circuit to work (in case you havent noticed Im an idiot kid trying to learn off web guides). Have I pontentially damaged my teensy? I never connected anything to v out, only data and ground. Thanks.

There is a possibility but, the only way to say for sure is check the functionality of each pin.
What code were you try to run?

I was connecting various data pins to a switch and then to ground.

And were you defining those pins using pinMode(pin,INPUT_PULLUP) in the setup function?
If not that is why it is not working.

LarryD:
There is a possibility but, the only way to say for sure is check the functionality of each pin.
What code were you try to run?

i was using code as shown in the example below for getting the switch to change what was posted to serial monitor, except i changed the result of the if clause to digitalWrite(13, HIGH) when switch was LOW and digitalWrite(13,LOW) when switch was high. Also modified pinmode(10, INPUT) to pinmode(10, INPUT_PULLUP) as I was trying to use built in pullup resistors. Im afraid I had the digital pin and gnd bridged, as I connected to the button on the wrong side.

Example: Teensyduino Tutorial #3: Input pins and using Arduino's Serial Monitor with Teensy

Grumpy_Mike:
And were you defining those pins using pinMode(pin,INPUT_PULLUP) in the setup function?
If not that is why it is not working.

everything was connected as shown in the pictures in that link except that the button was turned 90 degrees and I tried various digital pins.

Sorry if Im a bit confuzing; Im trying to type in mobile(which drives me nuts) and its late

All I think I did was to have ground and data connected all the time

Hi,
Have you tried any programs you had working before on the controller to see if all is well or unwell?

Does the controller have an onboard LED connected to output 13?
If so have you loaded the blink example from the IDE to see if you can get it to blink?

Tom.... :slight_smile:

Please define not working. What is it not doing?

Those miniature switches have four pins but two on each side are joined. Have you rotated the switch 90 degrees?

Weedpharma

TomGeorge:
Hi,
Have you tried any programs you had working before on the controller to see if all is well or unwell?

Does the controller have an onboard LED connected to output 13?
If so have you loaded the blink example from the IDE to see if you can get it to blink?

Tom.... :slight_smile:

yes pin 13 is connected to an LED on the teensy 3.1, which still works fine as of right now.

Keyboard.println commands work fine as well as controlling pin 13; that's about all I can test. I don't have any LED's to test the digital pins that I was trying to connect the switch to.

weedpharma:
Please define not working. What is it not doing?

Those miniature switches have four pins but two on each side are joined. Have you rotated the switch 90 degrees?

Weedpharma

teensy isn't responding to button presses no matter how I configure things. At one point I had the switch rotated 90 degrees, but now I have it configured properly. Even when I connect to a different GND and digital pin on the teensy and have the button oriented properly nothing happens. If I have the program like this:

void setup() {
pinMode(21, INPUT_PULLUP);
pinMode(13, OUTPUT);
}

void loop()
{
if (digitalRead(21) == LOW) {
digitalWrite(13, LOW);
} else {
digitalWrite(13,HIGH);
}
delay(250);
}

...the LED is always on. But if I have i like this:

void setup() {
pinMode(21, INPUT_PULLUP);
pinMode(13, OUTPUT);
}

void loop()
{
if (digitalRead(21) == HIGH) {
digitalWrite(13, LOW);
} else {
digitalWrite(13,HIGH);
}
delay(250);
}

The light is always off.

Thanks for all the help :smiley:

Would testing each pin with an LED using digitalWrite to make it turn on be enough to tell if everything was OK?

dr_deconstruct:
Would testing each pin with an LED using digitalWrite to make it turn on be enough to tell if everything was OK?

Connecting an LED directly to a pin, may damage the board. You need to place a resistor (say ~1K) in series, to prevent the LED drawing more current than the output pin can drive.

[edit] On 5V AVR Arduino boards, like the Uno,[/edit] you can connect the positive (Anode) of an LED directly to a digital pin which is in INPUT_PULLUP mode. The integrated pull up resistor is 5K, which allows just enough current (5V / 5000 Ohms = 1mA) to flow to dimly light an LED.[edit] But this won't work on Teensy 3.1, which uses a 3.3V ARM chip with 50K pull up resistors.[/edit]

Also, one of the most effective ways to trouble shoot is to simplify.

void setup (void) {
  pinMode(21, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

void loop(void) {
  bool buttonState = false;
  buttonState = digitalRead(21);
  digitalWrite(13, buttonState);
}

What happens to the LED when you push the button?

The internal pullup is 20-50K. Barely lights an LED. Barely.

Have you tried not using the button - just a piece of wire instead?

Some of those push buttons have leads that are too short to make good contact in some breadboards - so you need to verify first:

  1. the leads do make contact

  2. that the button is working sans everything else

Basically, set things up so that one of your pins outputs a HIGH - and you can light an LED with it (with a current limit resistor in between of course).

Then - insert the switch between the LED and the arduino's pin. If you can press the button, and the LED lights up - then the switch is good and making good contact. Otherwise, you know to suspect the switch and/or the leads - and work from there.

MattS-UK:
Connecting an LED directly to a pin, may damage the board. You need to place a resistor (say ~1K) in series, to prevent the LED drawing more current than the output pin can drive.

Alternatively, you can connect the positive (Anode) of an LED directly to a digital pin which is in INPUT_PULLUP mode. The integrated pull up resistor is 5K, which allows just enough current (5V / 5000 Ohms = 1mA) to flow to dimly light an LED.

Also, one of the most effective ways to trouble shoot is to simplify.

void setup (void) {

pinMode(21, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

void loop(void) {
  bool buttonState = false;
  buttonState = digitalRead(21);
  digitalWrite(13, buttonState);
}




What happens to the LED when you push the button?

nothing happens; the LED remains on the whole time to matter what

cr0sh:
Have you tried not using the button - just a piece of wire instead?

Some of those push buttons have leads that are too short to make good contact in some breadboards - so you need to verify first:

  1. the leads do make contact

  2. that the button is working sans everything else

Basically, set things up so that one of your pins outputs a HIGH - and you can light an LED with it (with a current limit resistor in between of course).

Then - insert the switch between the LED and the arduino's pin. If you can press the button, and the LED lights up - then the switch is good and making good contact. Otherwise, you know to suspect the switch and/or the leads - and work from there.

the LED remains on using MattS-UK's code, even if I directly connect the input pin and ground with a jumper. This is true no matter which digital pin or ground I use.

I ran this code and everything worked fine if I connected a jumper between 9 and ground... It appears something is wrong with my breadboard....

void setup() {
Serial.begin(38400);
pinMode(9, INPUT);
}

void loop()
{
if (digitalRead(9) == HIGH) {
Serial.println("Button is not pressed...");
} else {
Serial.println("Button pressed!!!");
}
delay(250);
}

CrossRoads:
The internal pullup is 20-50K. Barely lights an LED. Barely.

My bad.

Missed the bit where the OP said, “Teensy 3.1”

Sorry about that.

dr_deconstruct:
I ran this code and everything worked fine if I connected a jumper between 9 and ground... It appears something is wrong with my breadboard....

Are you sure it was not your earlier choice to use Pin 21, that was the problem?