Too many libraries

Hours and hours have gone into this project (literally more than a hundred)
Finally everything works, the 3D model is printed and everything is coming together.
All my software programs were put together (BME680, APC220, GPS, Servo Motor) All on a small Pro Micro.
As a matter of fact, the board couldn't even be any bigger 'cause it wouldn't fit otherwise.

So finishing up the last stuff and adding the last part to the main program (the SD Card)

Error message: Sketch too big.

Oh. my. god. How am I supposed to fix this? I commented out the SD library and it instantly worked, meaning the SD library is the problem. Somebody help please :frowning:

Leave out the SD card - from what I can see of the code, it isn’t necessary.

If I could, I would have already done that. Sadly, it is a strict requirement and therefore not possible to leave out.

By the way, these are the libraries:

#include <Servo.h>
#include <SoftwareSerial.h>
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

Whooosh

noodlefish:
Sadly, it is a strict requirement and therefore not possible to leave out.

Then clearly you need an Arduino with more memory.

Libraries by themselves are useless.

Why SoftwareSerial?
(I have a nasty suspicion we’ve had this conversation before)

I commented out the SD library and it instantly worked, meaning the SD library is the problem

Wooly thinking.

Post your whole code!

To reply to everything at once:

"Why SoftwareSerial"
Well, I think it's used for either the BME680 or the GPS, otherwise I wouldn't have put it in, I only copy pasted libraries. I just removed it and it's still too big, that wouldn't fix it though.

"Libraries by themselves are useless"
Uhm, I don't think so because whenever I remove the SD library it works, and if I leave it in it doesn't.

"Wooly thinking"
Yeah, I have no idea what this means

"Whooosh"
Yes, whooosh indeed.

When the box gets too small and their is an insistence on putting more things in the box; your going to need a bigger box.

“Whoosh” is the sound my hint that you post code made as it went right over your head.

Well, I think it’s used for either the BME680 or the GPS

Well, a BME680 is I2C or SPI, so that’s not it.

A GPS is usually serial, and you’re using a Pro Micro, so which device is using SoftwareSerial?
(We have had this conversation before)

Hey missdrew, It’s the same code as previous topic, but I added this new topic because it’s a different problem.
I’ll post the full code underneath.

In this code I DID add the library and the commands for the SD card (look at the commented lines to find where)

#include <Servo.h>
#include <SoftwareSerial.h>
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

bool maxheight = false;
bool deploy = false;
float servoAltitude = 150;

Servo servo;
File myFile;

#define BME_SCK 15
#define BME_MISO 14
#define BME_MOSI 16
#define BME_CS 3

#define SEALEVELPRESSURE_HPA (994.26) // Meet de druk op de grond!

Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
SoftwareSerial mySerial(8, 7); // (TX, RX)
Adafruit_GPS GPS(&mySerial);

void setup() {

  Serial.begin(9600);
  mySerial.begin(9600);

// SD Card

  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  
  myFile = SD.open("CanSat_Data.txt", FILE_WRITE);

// BME680

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }
  
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms
  delay(5000);

// GPS

  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(200);
  mySerial.println(PMTK_Q_RELEASE);

// Servo Motor

delay(200);
servo.attach(6);
delay(200);
servo.write(90);
delay(200);
servo.detach();
delay(200);

}

uint32_t timer = millis();

void loop() {
  
// Parsing

char c = GPS.read();
  if ((c))
  if (GPS.newNMEAreceived()) {
  if (!GPS.parse(GPS.lastNMEA()))
      return;
  }

  if (millis() - timer > 2000) {
    timer = millis();
    
// GPS

    if (GPS.fix) {          
      Serial.print("\n");
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.println(GPS.longitude, 4); Serial.println(GPS.lon);
      mySerial.print("\n");
      mySerial.print("Location: ");
      mySerial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      mySerial.print(", ");
      mySerial.println(GPS.longitude, 4); Serial.println(GPS.lon);
    }

// GPS SD Card

    if (myFile) {

    myFile.print("\n");
    myFile.print("Location: ");
    myFile.print(GPS.latitude, 4); Serial.print(GPS.lat);
    myFile.print(", ");
    myFile.println(GPS.longitude, 4); Serial.println(GPS.lon);

    myFile.close();
    }
  
// BME680

      Serial.print("Temperature = ");
      Serial.print(bme.temperature);
      Serial.println(" *C");
      mySerial.print("Temperature = ");
      mySerial.print(bme.temperature);
      mySerial.println(" *C");
    
      Serial.print("Pressure = ");
      Serial.print(bme.pressure / 100.0);
      Serial.println(" hPa");
      mySerial.print("Pressure = ");
      mySerial.print(bme.pressure / 100.0);
      mySerial.println(" hPa");
      
      Serial.print("Humidity = ");
      Serial.print(bme.humidity);
      Serial.println(" %");
      mySerial.print("Humidity = ");
      mySerial.print(bme.humidity);
      mySerial.println(" %");
      
      Serial.print("Gas = ");
      Serial.print(bme.gas_resistance / 1000.0);
      Serial.println(" KOhms");
      mySerial.print("Gas = ");
      mySerial.print(bme.gas_resistance / 1000.0);
      mySerial.println(" KOhms");
    
      Serial.print("Approx. Altitude = ");
      Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      Serial.println(" m");
      mySerial.print("Approx. Altitude = ");
      mySerial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      mySerial.println(" m");

// BME680 SD Card

  if (myFile) {

    mySerial.print("Temperature = ");
    mySerial.print(bme.temperature);
    mySerial.println(" *C");
    
    mySerial.print("Pressure = ");
    mySerial.print(bme.pressure / 100.0);
    mySerial.println(" hPa");
    
    mySerial.print("Humidity = ");
    mySerial.print(bme.humidity);
    mySerial.println(" %");

    mySerial.print("Gas = ");
    mySerial.print(bme.gas_resistance / 1000.0);
    mySerial.println(" KOhms");

    mySerial.print("Approx. Altitude = ");
    mySerial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    mySerial.println(" m");
    
    myFile.close();
    }
      
// Servo Motor

servoAltitude = servoAltitude - 20; //bme.readAltitude(SEALEVELPRESSURE_HPA);
Serial.println(servoAltitude);

if (servoAltitude >= 100) { Serial.println("Above 100 m"); maxheight = true; Serial.println(maxheight);}

  else { delay(1000); }
  
    if (maxheight == true and servoAltitude <= 50)
    {
        Serial.println("Deploying...");

        // SD Card

          if (myFile) {
          myFilr.print("\n");
          myFile.print(servoAltitude);
          myFile.println("Deploying...");
          myFile.close();
          }
        
        delay(100);
        servo.attach(6);

        delay(100);
        servo.write(0);
        delay(600);
        servo.write(90);
        delay(100);

        servo.detach();
        delay(100);
        
        maxheight = !maxheight;
    }
    else
    { delay(1000); }
   
  }
}

Not sure if the SD Card code is right, couldn’t test it yet.

SoftwareSerial mySerial(8, 7); // (TX, RX)
Adafruit_GPS GPS(&mySerial);

You have an unused hardware serial port - why aren’t you using it?

BTW who is going to be reading all the Serial prints during deployment?

TheMemberFormerlyKnownAsAWOL:
Well, a BME680 is I2C or SPI, so that’s not it.
A GPS is usually serial, and you’re using a Pro Micro, so which device is using SoftwareSerial?
(We have had this conversation before)

I know we’ve had this discussion before, and yes, you are right. I don’t need it.
I removed the SoftwareSerial library. Still too big.
Anything else I can try?

TheMemberFormerlyKnownAsAWOL:
You have an unused hardware serial port - why aren’t you using it?

Uhh not sure? Which one is that? Also, if I were to change it, would my program be less big and thus fix the problem?

Hey missdrew, It's the same code as previous topic,

Where did you post it in the previous topic? I can't find it.

You could also use the F macro to save space :

Also upgrade your board ? nano/UNO >>nano Every or MegaPro
( both have extra hardware serial ports )

noodlefish:
Uhh not sure? Which one is that? Also, if I were to change it, would my program be less big and thus fix the problem?

Start here.

I don’t know if it will fix your problem, partly because all I know about your problem is what you tell us.
So, not much.
(Please don’t make me type “Whooosh” again)

The code won't compile due to this

myFilr.print("\n");

It was the one you were just helping me with, about the SD card not working on the Pro Micro, anyways that's not important because that problem is solved.

If you wanted to see it, here it is though:

And yes, I saw the "myfilr" but I fixed that and it wasn't the problem, the sketch is just too big

hammy:
You could also use the F macro to save space :

But that’s not going to make the sketch any smaller

hammy:
You could also use the F macro to save space :
The hidden Arduino Macro F() fixes random lock ups - Bald Engineer

Also upgrade your board ? nano/UNO >>nano Every or MegaPro
( both have extra hardware serial ports )

Correct, the sketch needs to be smaller as missdrew said. Also I can’t use another board, because it won’t fit.