Too many Libraries

Recently I have been trying to create a digital compass that always points towards a set of coordinates. However, I have run into a major wall with the Arduino Nano being that my libraries are taking up too much program memory. Right now I have these libraries installed:

//for the Neo 6M GPS module
#include <TinyGPS++.h>
//for serial communication with GPS
#include <SoftwareSerial.h>
//Used to separate the gyrometer and OLED display data lines
#include <Wire.h>
//Gyrometer library
#include <MPU6050_tockn.h>
//Smaller OLED library
#include <U8g2lib.h>
//GPS haversine math for f64
#include <Gps64.h>

This takes up about 158% of program memory and 89% of dynamic memory. I have already modified the gps64 to remove unnecessary functionalities but have not been able to do much else. Is there any way to get out of this bind?

P.S.
This is all supposed to fit in an Altoid tin which so far works with an Arduino Nano but may not work with the larger models like the Uno or Mega.

Are you running out of SRAM or flash ?

As the compiler gets rid of most unused functions for you, it’s probably Time to go to a more capable arduino. An ESP32 would give you one extra hardware port and more memory whilst being small (and you get WiFi on top, although in a metal enclosure it won’t really work so well). Teensy 3.2 could also be a way forward.

FleshyOverlord:
This takes up about 158% of program memory and 89% of dynamic memory. I have already modified the gps64 to remove unnecessary functionalities but have not been able to do much else. Is there any way to get out of this bind?

Without a description of you actual project, or seeing your code, its hard for the forum to guess which might be a better choice of libraries.

There is no point to modifying libraries by removing code, the complier should only be including whats actually needed in the first place.

Sounds like you need an Arduino with more memory.

from a 60 seconds of copy pasteing from google:

Arduino Nano is 32Kb of flash

Arduino mega = 256k

esp = 512K, 1MB or 4MB depending on the board chosen.

rasberry pi = older beta Model B boards, 128 MB was allocated by default ... For the later Model B with 512 MB RAM

intel stick = 2 GB.

it's not worth rewriting libraries. get the right board for your project

I would suspect that the main problem is related to U8g2lib and you may be able to optimize how you use the display to reduce the code size.

FleshyOverlord:
This is all supposed to fit in an Altoid tin which so far works with an Arduino Nano but may not work with the larger models like the Uno or Mega.

God only knows what an Altoid tin is, but a Mega Pro is not that much bigger than a Nano - 38x54.

Google “altoid tin projects” and all will be revealed.

The brand new “nano every” has a lot more memory. Before buying one download the board to the IDE and try to compile your code for it.

Also how do you think a GPS module is going to work inside a tin?

Thank you for all your suggestions I think I may purchase the Arduino Mega Pro for its much larger memory size. However, if you have any code optimizations I have linked a copy of my code below.

GPS.ino (3.21 KB)

That Mega Pro is larger than a Nano, and you don't need all those pins. And it's not breadboard compatible, which won't make putting your prototype together easy.

There are other alternatives, which easily match or beat the Mega Pro on speed and memory. For example, I have a Protoneer Nano-Arm, which has 256K flash and 32K ram and runs at 48MHz. Same footprint as Nano. And there are many others like Teensy LC or 3.2 or AdaFruit ItsyBitsy M0... I guess your project will be battery powered, so the fact that these boards run 3.3V should be an advantage.

Mega has four hardware serial ports.
Further to your current situation:
Do you really need software serial?
If you aren't using graphics, you don't need a graphics library and I believe the Adafruit OLED text library is a lot smaller.

I am using the u8g2 library for graphics and am using the "page" setting which saves memory by shrinking the memory frame buffer of the OLED display by saving only one vertical line. To my current knowledge, I need to also use software serial to communicate with the GPS

FleshyOverlord:
To my current knowledge, I need to also use software serial to communicate with the GPS

That may not be true, but probably not relevant either, as the real problem is probably the graphics library.