Sketch too big. Error compiling for board ATtiny13

Im using Arduino IDE with UNO and ATtiny13V. Im getting the error message "Sketch too big. Error compiling for board ATtiny13." So I need to get a different ATtiny version? Would ATtiny85 work?

void setup(){

pinMode(2, INPUT_PULLUP);   // toggle switch. pulse/solid
pinMode(1, INPUT_PULLUP);   // on/off switch 
pinMode(0, OUTPUT);        // led

}
void loop()
{

    // Check on/off switch
    if (digitalRead(1) == HIGH) // switch is off
    {  
      digitalWrite(0, LOW); // led is off
    }
    else
    {
      // Check pulse/solid switch
      if (digitalRead(2) == HIGH) // switch is off
    {       
        digitalWrite(0, HIGH);  // led is set to solid
    }
      else
    {
      // led is set to pulse mode
      float in, out;
      for (in = 4.712; in < 10.995; in = in + 0.00700)
    {
      out = sin(in) * 127.5 + 127.5;

        analogWrite(0, out);
        delay(1.5);
        
      }
    }
  }
}

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

This is all your code???
I am not familiar with ATtiny, but it must be very tiny if this does not fit.
I think something else must be wrong.
Did it give any other info during/after compilation?

1 Like

Both analogWrite and delay take an int as argument.
So it is better to cast your float to an int...
...or not use floats at all (use integer maths).
And maybe you mean delay(1500);
And press Ctrl-T to auto format your code... the curly brackets are messy...

1 Like

The floats are eating up most of your memory.
On a attiny25 it compiles fine, so Attiny25, 45 or 85 could work.

It's a quite complicated pulse pattern you want to achieve. Curious what that could ever be for.

1 Like

It has 64 bytes of eeprom and that is all???

You might look at ways to get rid of the floats...
What pattern are you trying to achieve?
You could use a sin table (but that would also need memory...). If you want 10 degree steps, you would need only 9 uint8_t.

Edit: you might not have sufficient flash to store the program. Using sin() wil also include some way to calculate sin.... if that is done with a series expansion, then that might take considerable space.

Thanks! I will buy the attiny25 and try. Just a pulsing led for a MUTE indicator in an audio system. Found the code her: Pulse a LED - SparkFun Electronics

A nice pulsing /fading in and out effect.

You will not need floats for that....
Our eyes do not see the difference between 250 and 255...
You could try a bit shift...
Start with
00000001
Then move the 1 left with <<
When it is 10000000, move the 1 right with >>.
Sawtooth would also be an option.
Do not expect our eyes to perceive a sine wave pattern upon a sine wave pattern.
We cannot see the difference between 250 and 255, but the difference between 1 and 2 is very very easy to see...

1 Like

64 bytes of RAM and 1K of program memory. Floating point math functions are "about 1k" on AVRs, so...

I will buy the attiny25

You might want to consider one of the newer chips, like the ATtiny402 or ATtiny412.
These are newer, have a full set of peripherals, have 4k of program memory, and are cheaper as well (with pretty reasonable availability.) They'll require a different core, though, like Dr Azzy's tinyMegaCore.

1 Like

I still see no reason at all to go to another ATtiny.
I see more than one reason to get rid of the floats and of sin().
What can ATtiny do if it cannot fade in and out a LED???

1 Like

Have a google of “ heartbeat “ with Arduino , there are some probably better sketches for your needs .

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.