ATtiny85 Supported Commands?

Lately i have had a problem with certain sketches not working correctly on an ATtiny85-20PU.
The blink sketch works fine on the ATtiny85 but this sketch below will not, also this sketch below does work correctly on an Arduino board.

The list of supported commands for ATtiny85 are

Also the Arduino reference page is 

The one possible thing i can see as not being supported might be "  round  " on line 33 causing this sketch to not work properly.
I do not know this for a fact as i can not actually find anything that is not supported.
Do you know if " round " is a hang up for ATtiny85's?
//int IRSense = A0;  //For ATnega328
int IRSense = 2;  // For ATtiny85
//int IRTrans = 9;  // For ATnega328
int IRTrans = 3;  // For ATtiny85
//int LED1 = 10;    // For ATmega328
int LED1 = 4;     // For ATtiny85
int valueAmbient = 0;

void setup()
pinMode(IRSense, INPUT);
pinMode(IRTrans, OUTPUT);

void ambient()
valueAmbient = analogRead(IRSense);

void loop() {

int value = analogRead(IRSense);
int value2 = round(value - valueAmbient);
int dist = (((value2+15.0)/(value2*(value2+100.0)))*2000.0);

if (dist <= 10){ 

sort by: active | newest | oldest
Libahunt4 years ago
I can't give you an answer why it does not work, but just some ideas what to test.

If data type is int, you don't need to use numbers like 15.0, 100.0 and 2000.0 - these are actually floats. Use 15, 100 and 2000 instead.

Also you don't need round() because analogRead() retuns an integer number (you also defined reading as such) and subtracting two integers also gives integer.

If that does not help, move around the inputs - just maybe-maybe one I/O pin is faulty, that does not show with blink sketch.
WWC (author)  Libahunt4 years ago
Libahunt Thanks for the input

It will work without the round.
Will not work with the .0's removed. On the Arduino board.

Sadly it still would not work any witch way on the tiny's either.

Ya i had changed pins around and tried other chips but still the same story.
Seams to be an issue with these IR sketches. Other sketches still work correctly.
Libahunt WWC4 years ago
Couple of more random ideas.
I remember having trouble with choosing right clock speed when I burned sketches onto Attiny85 with Arduino as programmer. I think it compiled and burned with different options, but delays and stuff acted weird. Analog to digital converter sure uses some time counting, but I don't know if the program can affect it, feels not too likely. On the other hand you say blink works right, so probably timing is not the issue here.

Is your power supply for attiny stable? Someone more knowledgeable than me (knowledgeable in programmable electronics in general, but not AVR controllers in particular) suggested unstable power supply for a reason my attiny binary clock project did not work as intended (same situation as yours, particular problem was related to analogRead part, and it worked fine with Arduino). But I managed to fry some components before finding out (which now makes me very curious to bring it out from the drawer and try again...). So if you keep on searching, don't leave analogRead out from suspect list.
WWC (author)  WWC4 years ago
Maybe a porting issue. PORTB
AvinK211 months ago

SoftwareSerial command is supported or not to ATtiny85...


Libahunt4 years ago
Hi again. I took my project with analogRead problem out from the drawer and successfully fixed it. :) See if it helps you too.

My information source was this

So I did two things:

1) changed pin number from 4 (digital pin number) to 2 (analog input number) . In your example the equivalent would be changing IRSense from 2 to 1. Pin numbers can be duplicate if one of them is digital and other analog. Yes, confusing.

2) removed pinMode(..., INPUT) completely

Let us know if this helps.

ATtiny45 ATtiny85 pinout
(image from
WWC (author)  Libahunt4 years ago
This look promising. Just so i am clear.
Any place it has....... pinMode...... in the line i should completely remove this line?
Analog defaults to analogRead in this configuration?

Also use the Analog pin numbers not the Digital pin numbers. ?
Libahunt WWC4 years ago
Remove the line where you declare pinMode for the analog input, leave all the digital ones intact.

// pinMode(IRSense, INPUT) ; delete this

in your example.

Also use the number of analog input only for the pin that is used for analog in, leave all digital inputs and outputs as they are.

//int IRSense = 2; becomes
int IRSense = 1;

Analog defaults to analogRead in this configuration?

Seems like that.
(Actually command named analogWrite is not that analog in itself, it outputs PWM pulses with different duty cycles not actual analog voltage values. So analogRead is the only really analog operation that can be done with these controllers.)
WWC (author)  Libahunt4 years ago
Hi Libahunt

You are correct, the changes you suggested fixed this program so it is now working. Altho the LED1 flashes some but i don't thing it is from the fix i think that may have to do with program it self.
Libahunt WWC4 years ago
I'm glad to hear!

I thought maybe you could select this answer thread as best, instead of my previous random thoughts. Doesn't matter to me but someone may land here through search engine while investigating similar problem and then the information would be much clearer.
WWC (author)  Libahunt4 years ago
If your answer is a reply then it can not be selected as best answer. Only direct answers can be selected as best answer. The only direct answer you had was the one i picked.
Thanks again.
Libahunt WWC4 years ago
Okay, for some reason my browser shows them both aligned as first level comments. Nevermind and thanks.
WWC (author)  Libahunt4 years ago
Thanks for the continued input.

I want to try this but i used my last IR's on a different project. it will be a couple of days before i have some more. I will send you a report after that.
The Attiny's issues are generally with hardware and not software. Round doesn't concern hardware. If the code compiles, I'd say its something else.
WWC (author)  steveastrouk4 years ago
I am checking. Rechecking.
Not done with banging my head on the desk part yet
WWC (author)  WWC4 years ago
With this sketch is loaded on either an ATtiny85 or ATtiny2313 what happens is the LED1 will blink about half the speed of the IRTrans.

When loaded on an Arduino board then it works correctly.
I haven't tried it on a stand alone 328, guess i could try that next.

The tiny's are running at 1Mhz and the Arduino is of course at 16Mhz,
could that be an isue?