Hi! I have recently been programming a bunch of components to the Arduino Uno, and I have come across a problem. I seem to have reached 100% of program storage space and 101% of dynamic memory. I have been using suggestions like F() macros and it helps, but it doesn't seem to be enough. I use a BMP280 sensor, an Adafruit SD card reader, and a Ultimate Breakout GPS.
I am not sure if libraries are relevant(I think they are), but I have the following libraries installed:
- SD(by Arduino)
- Adafruit BMP280 Library
- Adafruit BusIO
- Adafruit GPS Library
- Adafruit Unified Sensor
- GPS(By Helder Rodrigues)
My full sketch is here:
//GPS
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
//BMP280 Code
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
//SD Card Reader
#include <SPI.h>
#include <SD.h>
//GPS
SoftwareSerial mySerial(8,7);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO true
//BMP 280
Adafruit_BMP280 bmp;
//SD card readed
//Pin num connected to CS
File dataFile;
//Buzzer
//const int buzzerPin = 9;
//SD Card Reader
#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)
void setup() {
Serial.begin(115200);
Serial.begin(9600);
while (!Serial);
GPSStartup();
pinMode(9, OUTPUT); //Buzzer
BMPInit();
SDInit();
delay(2000); // Delay start
}
const uint16_t line = 1;
uint32_t timer = millis();
void loop() {
//GPS
char c = GPS.read();
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
//BMP280 start
// Serial.println(F("BMP280 Sensor Readings:"));
//Finds all measurements and sets them
Serial.print(line);
Serial.print(FormatBMP());
//BMP280 END
//SD Card Reader
dataFile = SD.open(F("PMData.txt"), FILE_WRITE); // Opens the file
//Checks if file has opened
if (dataFile)
{
//Serial.println(F("File has been opened sucessfully :D. Writing..."));
//Write to file:
dataFile.print(line);
dataFile.print(FormatBMP());
//GPS
if (millis() - timer > 2000)
{
timer = millis();
if (GPS.fix)
{
//Location
Serial.print(FormatGPS());
dataFile.print(FormatGPS());
}
}
//Close File
dataFile.close();
//Serial.println("File closed successfully, data has been written(LETS GOOO).");
}
else
{
Serial.println(F("File failed to open :/"));
}
//Buzzer sounds every 5 seconds
tone(9, 1000);
delay(1000);
noTone(9);
delay(1000);
}
void GPSStartup()
{
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
// Ask for firmware version
mySerial.println(F(PMTK_Q_RELEASE));
}
void BMPInit()
{
if (!bmp.begin(0x76)) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
Serial.println(F("BMP280 Sensor Initiallized!:D"));
}
void SDInit()
{
if (!SD.begin(10))
{
Serial.println(F("SD Card Init Failed. Womp Womp D:."));
while(1);
}
Serial.println(F("SD card initialized:D"));
}
String FormatBMP()
{
String format = F("Temperature = ");
format.concat(String(bmp.readTemperature(), 2));
format.concat(F(" °C, Pressure = "));
format.concat(String((bmp.readPressure()/100.0), 2));
format.concat(F(" hPa, Altitude = "));
format.concat(F(" hPa, Altitude = "));
format.concat(String(bmp.readAltitude(1013.25), 2));
format.concat(F("m"));
return format;
}
String FormatGPS()
{
String format = F("Location(Lat.Lon.): ");
//Location
format.concat(String(GPS.latitude,4));
format.concat(String(GPS.lat));
format.concat(F(", "));
format.concat(String(GPS.longitude, 4));
format.concat(String(GPS.lon));
//Speed
format.concat(F("\nSpeed: "));
format.concat(String(GPS.speed, 1));
//Angle
format.concat(F(" | Angle: "));
format.concat(String(GPS.angle, 1));
return format;
}