attiny13A weird problem

Hi. i'm trying to use attiny13a with basic I/O.

I connected a LED to pin 0 and a basic switch with a pulldown resistor to pin 2.
But when I press the button the LED's power lowers(doesn't turn off completely) and when I let go it goes back to full power(on).
This happens indefinitely(I can keep pressing and releasing the button and get the same result over and over again)

heres the code:

int led=0;
int buts=2;

void setup() {                
  pinMode(led, OUTPUT);
  pinMode(buts,INPUT);
}

void loop() {
  digitalWrite(led, HIGH);
  while(digitalRead(buts) ==LOW);
  digitalWrite(led, LOW);
  while(true);
}

This code works as expected:

int led=0;
int buts=2;

void setup() {                
  pinMode(led, OUTPUT);
  pinMode(buts,INPUT);
}

void loop() {
  digitalWrite(led, digitalRead(buts));
}

What happens here?

What is the pull-down resistor value? And what is each end of the button connected to?

Works fine on my test attiny13A.

How are you powering it? It may be power related.

Do you still have your ISP programmer attached when testing? (Normally the ISP programmers should be high impedance when it's not programming but some may not and cause interference)

You didn't mention but you should have a resistor (at least 330 ohm or more) in series with you LED so you don't overdrive the output pin.

Also which attiny13 core are you using?

OK, show us the resistor itself. A photo.

My betting is that it is coded brown, black, black, red and not brown, black, black, red, red.

And as always, I think you should have the pushbutton to ground and the resistor to +5V. Less likely to have destructive problems with shorts in wiring Nice diagram, by the way! :smiley:

hiduino:
Works fine on my test attiny13A.

How are you powering it? It may be power related.

Do you still have your ISP programmer attached when testing? (Normally the ISP programmers should be high impedance when it's not programming but some may not and cause interference)

You didn't mention but you should have a resistor (at least 330 ohm or more) in series with you LED so you don't overdrive the output pin.

Also which attiny13 core are you using?

  1. I'm powering it using the ISP's power(USB)
  2. I've tried disconnecting the ISP(except power supply), didn't work. So I've started to ignore it and am currently keeping all the wires connected for now. I should say that a led on the arduino board(uno) turns off when I push the button.
  3. Of course I have a resistor protecting the LED(I don't even remember it's value, I have them sorted by LED type and color)
  4. what do you mean by core?
    this?
    GitHub - tekstop/attiny at Arduino1

Paul__B:
OK, show us the resistor itself. A photo.

My betting is that it is coded brown, black, black, red and not brown, black, black, red, red.

And as always, I think you should have the pushbutton to ground and the resistor to +5V. Less likely to have destructive problems with shorts in wiring Nice diagram, by the way! :smiley:

  1. EDIT: Whoa, image sige!
    avialable here: Dropbox - 2014-08-24 01.28.39.jpg - Simplify your life

  2. I know a pullup is better and I plan to use the internal pullap eventually, but for now I just want it to work.....

  3. Thanks! Actually I just searched "online circuit drawer" and this was the first result =P

  4. Also, I forgot to say that I can't do delay. either by delay(ms); or by for(int i=0;i<10000000;i++);. it does nothing. the program keeps looping without delaying any (noticeable by the human eye) time at all.

You may want to try smeezekitty's core13. I've had good results with this one.

http://forum.arduino.cc/index.php?topic=89781.0

see attached file.

attiny13.zip (12.6 KB)

I am not understanding your code

while(digitalRead(buts) ==LOW);
  digitalWrite(led, LOW);
  while(true);

While syntax is:
while condition statement

";" is a null statement.

while(digitalRead (buts) == LOW) {
  ;  // wait here
}

...

while (true) {
  ; // wait forever
}

Is that what you meant?

nirnir93:
5. EDIT: Whoa, image sige!
available here.

I do think you should measure those resistors. My interpretation of the coding is that they are 120 ohm 1%. The photo does leave much to be desired (in figuring out the colours) and it is much better to post things here ("Additional Options...") than to use troublesome websites like "dropbox", especially when they are clearly marked as bad sites with the message "The Dropbox website requires JavaScript.". :roll_eyes:

nirnir93:
8. Also, I forgot to say that I can't do delay. either by delay(ms); or by for(int i=0;i<10000000;i++);. it does nothing. the program keeps looping without delaying any (noticeable by the human eye) time at all.

I was myself thinking that you were using some bizarre code, but - that's another matter; I was concentrating on that resistor as the problem.

polypagan:
I am not understanding your code

while(digitalRead(buts) ==LOW);

digitalWrite(led, LOW);
  while(true);




While syntax is:
while condition statement

";" is a null statement.



while(digitalRead (buts) == LOW) {
  ;  // wait here
}

...

while (true) {
  ; // wait forever
}




Is that what you meant?

Indeed. of course I tried your way too, before posting. Didn't help.
(; is a null statement, meaning it's a statement nonetheless)

hiduino:
You may want to try smeezekitty's core13. I've had good results with this one.

core13: An Arduino core for the Attiny13 *testers wanted* - Microcontrollers - Arduino Forum

see attached file.

The code i'm using is from instructables, I'll try this when I get home.
Unfortunately, that will be Thursday.

Paul__B:

nirnir93:
5. EDIT: Whoa, image sige!
available here.

I do think you should measure those resistors. My interpretation of the coding is that they are 120 ohm 1%. The photo does leave much to be desired (in figuring out the colours) and it is much better to post things here ("Additional Options...") than to use troublesome websites like "dropbox", especially when they are clearly marked as bad sites with the message "The Dropbox website requires JavaScript.". :roll_eyes:

nirnir93:
8. Also, I forgot to say that I can't do delay. either by delay(ms); or by for(int i=0;i<10000000;i++);. it does nothing. the program keeps looping without delaying any (noticeable by the human eye) time at all.

I was myself thinking that you were using some bizarre code, but - that's another matter; I was concentrating on that resistor as the problem.

Sorry about Dropbox, as you can see I'm new here =]. Next time I'll know.
I'll try hiduino's code on Thursday, and I'll measure the resistors then. But if you look at the picture as upside-down, it can bee 10k 1% too. Stupid color code.

Any, thanks everybody! As I said, I'll update on Thursday! Have a good week!

nirnir93:
The code I'm using is from instructables,

Oh dear! That would explain a lot of things!

nirnir93:
on Thursday, and I'll measure the resistors then. But if you look at the picture as upside-down, it can bee 10k 1% too.

No, it actually does not matter which way up it is. The clue is that one band - the tolerance band - is spaced further away from the others.

We await Thursday with bated breath.

UPDATE

Hi everyone. solved the problem! in short:

  1. The resistor is indeed 10k(9.5, but who's counting?). After making sure it works, I switched to internal pullup.
  2. smeezekitty's code WORKES!! delay and all!
    I don't have a sourceForge accounts, but is there any way I can thank him in this forum?(Noob here, I don't even know if I can bump his post :~)

Anyway, thank a lot everybody! :slight_smile: :slight_smile: 8) $) :wink: :smiley: :grin: XD
Tomorrow i'll buy the last part I need and if you tell me where, I'll post schematics+Code+pics of the project(a completely invisible drawer in an Ikea shelf)