Out of memory in Attiny85, tips needed

Hello all!

I'm trying to build an IR themometer using MLX90614, the objective is to read the sensor and show the data in an android app. But i'm having issues with memory.

My current code: (usage is 101%)

#include <TinyWireM.h>
#include <Adafruit_MiniMLX90614.h>
#include <DigiCDC.h>


int TINY_SDA   =     0;               //ATtiny SDA pin 5
int TINY_SCL   =     2;              //ATtiny SCL pin 7

Adafruit_MiniMLX90614 mlx = Adafruit_MiniMLX90614();

int delayval = 50; // DELAY

void setup() {
 SerialUSB.begin(); 
 mlx.begin();            
}

void loop() {

 float ambientTemp = mlx.readAmbientTempC();
 float objTemp = mlx.readObjectTempC();
 SerialUSB.println(objTemp); 
 SerialUSB.refresh();  



 delay(delayval);

}

(it doesn't work because of line 22, this line makes the usage go to 101%)

The main problem is with DigiCDC, it works, but it is using 70%+ more of my RAM, how can I make it smaller? I thought about editing myself digiCDC library, but I cannot find it anywhere in my pc.

I tried to install the new bootloader provided by digispark, but with no success (almost destroyed the attiny)

Besided that, what can I do, any digiCDC alternatives to communicate with android phones? I just need the usage to go a little bit down. I see SoftSerial is an option but I don't have pins for that, also, I don't have an adapter for the OTG cable like this
guy.
Thanks

What happens when you stop using floating-point?

Usage goes to 93%, but I need floats for accuracy and benchmarks, but good idea, at least now I can debug.

but I need floats for accuracy

That statement is almost certainly false

precision != resolution != accuracy

I mean, I need resolution of at least 0.1 degrees. That's why I need floats

You don't need floats.
The data does not come out of the thermopile as a floating point value.

Let me see, maybe I'm not following you.

The library that i'm using returns a double value when I try to read objects

double Adafruit_MiniMLX90614::readObjectTempC(void) {
  return readTemp(MLX90614_TOBJ1);
}

Indeed, i can change that to float because I need 0.1 resolution for my temperature (eg: 21.5)

In my code, I call the following:

float objTemp = mlx.readObjectTempC();

where I need to attribute float to objTemp variable bececause I still need 0.1 resolution

now, If I call the function directly

SerialUSB.println(mlx.readObjectTempC());

I get an 102% of usage.

If i Use an int value, I will not havethe resolution I want (because of int). I don't undertsand what do you mean by saying I don't need floats. Can you elaborate?

Can you use the LTO (Link Time Optimisation) compiler option to reduce the size?

you could change the pin definition from int to define.... and just put 50 in the delay value instead of the int.... should save you a bit of memory....

Imagine that there's a unit called the centiCelsius.
One hundred centiCelsius make one degree Celsius.

Now can you see why floating point is not necessary?

float Adafruit_MiniMLX90614::readTemp(uint8_t reg) {
  float temp;
  
  temp = read16(reg);
  temp *= .02;
  temp  -= 273.15;
  return temp;
}

/*********************************************************************/

uint16_t Adafruit_MiniMLX90614::read16(uint8_t a) {
  uint16_t ret;

  TinyWireM.beginTransmission(_addr); // start transmission to device 
  TinyWireM.write(a); // sends register address to read from
  TinyWireM.endTransmission(false); // end transmission
  
  TinyWireM.requestFrom(_addr, (uint8_t)3);// send data n-bytes read
  ret = TinyWireM.read(); // receive DATA
  ret |= TinyWireM.read() << 8; // receive DATA

  uint8_t pec = TinyWireM.read();

  return ret;
}

You should be able to see from the library, the value returned from "read16()" is then used by readTemp() to convert it in to a float.
Rather than use that function, write your own to take the value from read16() and convert it in to "centiCelcius" rather than Celsius...
I.e. multiply the initial value by 100 and return an int.
You can then simply Serial.print(temp / 100) + (".") + ( temp % 100). (PSUEDO!)

I'll expand a little:

  temp = read16(reg);
  temp *= .02;
  temp  -= 273.15;
  return temp;

Here, reg is a 16bit unsigned int. Say the temperautre sensor returned "18,000" for the sake of an example...

The little bit of code above takes that returned 16bit unsigned int, divides it by 50 (*0.02) and then takes 273.15 away from it to give the temperature in Celsius returned as a float.

18000 * 0.02 = 360
360 - 273.15 = 86.85

Now, what we could do instead...

Take the 18,000 and multiply it by 100...

Now temp = 1,800,000

1800000 / 50 = 36000
36000 - 27315 = 8685

Now when we do 8685/100 = 86
8685 % 100 = 85

Print ("86") + (".") + ("85")

The library that i'm using returns a double value when I try to read objects

You don't really need a library, and the Adafruit library is particularly obnoxious, because it uses floats (same as doubles).

Here is an example of MLX90614 code that does not use floating point arithmetic.