Digistump Forums

The Digispark => Digispark (Original) Support => Topic started by: allanonmage on September 22, 2013, 02:10:23 pm

Title: Is this internal pull up resistor enough for a toggle switch?
Post by: allanonmage on September 22, 2013, 02:10:23 pm
New to digispark, though not so new to arduino.

I'd like to have one of the inputs sense a toggle switch.  I think that normally I could use the pull up resistor and connect the switch to the input and ground.  The digispark has less impedance on its input though.  Is it enough impedance to work for this application?  Should I use an external resistor?

I watched a video on youtube to grasp pull up and down resistors, so I'm still a little shaky on some of the electronicals.
Title: Re: Is this internal pull up resistor enough for a toggle switch?
Post by: allanonmage on September 22, 2013, 02:47:19 pm
This is how I think it would look using the internal pull up resistor.

*edit*
The reason I'm asking is this blurb:

Digital Read:  NOTE: The internal pull-up resistor (turned on by calling digitalWrite(0) after setting the pin to output, where 0 is the pin number) are much weaker (about 25 kohm) on an ATtiny than on an Arduino, so the onboard LED interferes with them. If you need them, you can use a different port. Change your circuit to not need the internal pull-up, or cut the LED trace. For Model A this would apply to P1 for Model B this would apply to P0.(Model Identification (http://digistump.com/wiki/digispark/tutorials/modelbi2c))

Found here:
http://digistump.com/wiki/digispark/tutorials/basics
Title: Re: Is this internal pull up resistor enough for a toggle switch?
Post by: semicolo on September 22, 2013, 05:33:39 pm
You know there's an onboard regulator and you don't need the external one? Don't forget the switch goes to ground, it's tied to +5V on your schematic.

You'd better not use the pin connected to the onboard led as an input with the internal pullup, the easiest way is to use another pin, you'll have no problem with any other, if you want to keep USB feature, P3/P4 must be kept.

I'd use P5, because it's almost useless as an output.
Title: Re: Is this internal pull up resistor enough for a toggle switch?
Post by: allanonmage on September 22, 2013, 08:21:11 pm
I know there's an internal regulator, but the battery pack I have selected is in the hole of 6 volts.  And you can't feed 5 or 6 volts into the regulator, right?  Once I get out of prototype and into production with this, I have the option for a higher voltage pack.

Quote
You'd better not use the pin connected to the onboard led as an input with the internal pullup, the easiest way is to use another pin, you'll have no problem with any other, if you want to keep USB feature, P3/P4 must be kept.
I thought pin 0 had the LED?  I was leaving pin 0 empty because of that.

Speaking of pins, in testing (see new diagram), I noticed that pins 5 and 6 yeilded different results when they were set to go high.  Pin 5 was able to drive the LED and the transistor/siren fine.  Pin 6 is not able to drive the LED to the same brightness, nor is it able to drive the transistor/siren (no sound).  I don't understand why this is the way it is.

The orange line is a manual test right now.  Eventually that will be a set of RCA cables that loop around something.  This wire will be 20 - 60' round trip.  Does that change anything?


Code: [Select]
void setup(){
  pinMode(1,INPUT); //detects circuit
  pinMode(2,INPUT); // debug reset
  pinMode(4,OUTPUT); // LED for alarm
  pinMode(5,OUTPUT); // siren
 
  digitalWrite(4,LOW);
  digitalWrite(5,LOW);
 
 
} // end setup()



void loop(){
 
  if(digitalRead(1)==LOW){
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
  } // end if
 
  if(digitalRead(1)==HIGH){
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
  } // end if
 
} // end loop()
Title: Re: Is this internal pull up resistor enough for a toggle switch?
Post by: MichaelMeissner on September 22, 2013, 09:49:22 pm
I thought pin 0 had the LED?  I was leaving pin 0 empty because of that.
If you got one of the first digisparks from the kickstarter campaign, and you did not order an I2C shield, it had the led on pin 0 (model B board).  The later kickstarter boards (including the orders for everybody that ordered an I2C shield at the same time) got the model A board with the Led on pin 1.  Boards ordered after the kickstarter campaign should be all model A's.  I believe the resistor for the Led was interfering with I2C, which is why the board got changed mid-stream.  http://digistump.com/wiki/digispark/tutorials/modelbi2c (http://digistump.com/wiki/digispark/tutorials/modelbi2c)
Title: Re: Is this internal pull up resistor enough for a toggle switch?
Post by: allanonmage on September 23, 2013, 04:28:26 am
I ordered mine last week. It says rev4 on the board.
Title: Re: Is this internal pull up resistor enough for a toggle switch?
Post by: semicolo on September 23, 2013, 07:11:47 am
I know there's an internal regulator, but the battery pack I have selected is in the hole of 6 volts.  And you can't feed 5 or 6 volts into the regulator, right? 

Speaking of pins, in testing (see new diagram), I noticed that pins 5 and 6 yeilded different results when they were set to go high.  Pin 5 was able to drive the LED and the transistor/siren fine.  Pin 6 is not able to drive the LED to the same brightness, nor is it able to drive the transistor/siren (no sound).  I don't understand why this is the way it is.


If fact it looks like you can, VCC will be a little low (under 5V) but the digispark will run happily.
You should use P0-P5 to refer to the pins, not P1-P6 or we'll have some misunderstandings.
I was saying that P5 is weak and useless as an output, that's what you experienced with your LED.
Why? Because it's the reset pin and it's said in the datasheet you can't get a lot of current from it, voltage drops a lot when you drain even a few mAs.