Go Down

Topic: attiny13A weird problem (Read 546 times) previous topic - next topic

nirnir93

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:
Code: [Select]

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:
Code: [Select]

int led=0;
int buts=2;

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

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


What happens here?

hiduino

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



hiduino

#3
Aug 23, 2014, 11:42 pm Last Edit: Aug 23, 2014, 11:51 pm by hiduino Reason: 1
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?


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!   :D

nirnir93

#5
Aug 24, 2014, 12:37 am Last Edit: Aug 24, 2014, 12:41 am by nirnir93 Reason: 1

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?
https://github.com/tekstop/attiny/tree/Arduino1


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!   :D


5. EDIT: Whoa, image sige!
avialable here: https://www.dropbox.com/s/w6o6kfqu0jb1dep/2014-08-24%2001.28.39.jpg?dl=0
6. I know a pullup is better and I plan to use the internal pullap eventually, but for now I just want it to work.....
7. Thanks! Actually I just searched "online circuit drawer" and this was the first result =P

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.

hiduino

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.

polypagan

I am not understanding your code
Code: [Select]

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


While syntax is:
while condition statement

";" is a null statement.

Code: [Select]


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

...

while (true) {
  ; // wait forever
}


Is that what you meant?
There are 10 kinds of people in the world, those who understand binary, and those who don't.

Paul__B


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.".   :smiley-roll:


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.

nirnir93


I am not understanding your code
Code: [Select]

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


While syntax is:
while condition statement

";" is a null statement.

Code: [Select]


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)


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.


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



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.".   :smiley-roll:


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!

Paul__B


The code I'm using is from instructables,

Oh dear!  That would explain a lot of things!



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.

nirnir93

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! :) ^_^ 8) $) ;) :D :smiley-mr-green: 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)

Go Up