Arduino Uno Wifi running out of memory. Help!

Hello!

I'm working on a project where I have an Adafruit Ultimate GPS breakout module connected to an Arduino Uno Wifi board. I have followed the guide here: Ciao Rest Client Guide to connect my board to ThingSpeak using the Ciao library. This works fine for me, and I am able to get a separate program to pull GPS data from the module connected to the board.

When I put these two programs together, I run out of global memory space. I have trimmed my program considerably to the bare bones, and I am still running into problems because 80% of the space is still being taken up by global variables. Here is my very sparse and trimmed code:
I am using fake data to send to ThingSpeak in this example

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Ciao.h>

SoftwareSerial mySerial(3, 2);

Adafruit_GPS GPS(&mySerial);

void setup()  
{

  Ciao.begin();
    
  //Serial.begin(9600);
  GPS.begin(9600);
  
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
  GPS.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);
 
  delay(1000);
 
}

void loop()                    
{

  //Code to parse GPS data goes here, but takes up a lot of memory

  Ciao.write( "rest" , "api.thingspeak.com",  "/update?api_key=Q6SB31YSY9352OW6&field1=29&field2=19");
 
  delay(30000); // Thinkspeak policy
  
}

Is there a more 'memory cheap' way of connecting to a web server?
The Ciao library and the Adafruit GPS library take up a considerable amount of space. I know there is the Ethernet library, and I have imported it in my project to use instead of Ciao, but I can't figure out how to get it to work with my board. I don't even know if it can work with this board.

connected to an Arduino Uno Wifi board.

There being no such thing as an "Arduino Uno Wifi" board, you MUST post a link to the hardware you REALLY have.

PaulS:
There being no such thing as an "Arduino Uno Wifi" board, you MUST post a link to the hardware you REALLY have.

This is what I'm using:
Arduino Uno Wifi board
Link to startup tutorial

Looks like it exists to me

It exists but not here. That is arduino.org, not arduino.cc.

Sounds like you need a board with more memory.

SurferTim:
It exists but not here. That is arduino.org, not arduino.cc.

Sounds like you need a board with more memory.

Ah, I see.
Thank you. I thought that was what I would have to do, but was posting as a last resort!

You can typically save several thousand bytes of program space and several hundred bytes of RAM if you use NeoGPS instead of Adafruit_GPS. You can configure it to parse only the fields you need, saving even more.

The sketch you posted above uses 15222 bytes of program space and 1518 bytes of RAM (I added Serial.begin and a print to your example)

The following NeoGPS version uses 17080 bytes of program space and 1546 bytes of RAM:

#include "NMEAGPS.h"
#define PMTK_SET_NMEA_OUTPUT_RMCGGA \
          "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
#define PMTK_API_SET_FIX_CTL_5HZ  "$PMTK300,200,0,0,0,0*2F"
#define PMTK_SET_NMEA_UPDATE_5HZ  "$PMTK220,200*2C"

#include <SoftwareSerial.h>
#include <Wire.h>
#include <Ciao.h>

const uint32_t THINGSPEAK_INTERVAL = 30000UL;
      uint32_t thingspeakTime      = 0;

SoftwareSerial gps_port(3, 2);

NMEAGPS GPS;
gps_fix fix; // latest info from GPS

void setup()
{

  Ciao.begin();

  Serial.begin(9600);
  gps_port.begin(9600);

  gps_port.println(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  gps_port.println(PMTK_SET_NMEA_UPDATE_5HZ);
  gps_port.println(PMTK_API_SET_FIX_CTL_5HZ);

  delay(1000);
}

void loop()
{
  //Code to parse GPS data goes here, but takes up a lot of memory
  while (GPS.available( gps_port )) {
    fix = GPS.read();
    Serial.println( fix.spd.whole ); // knots
  }

  if (millis() - thingspeakTime > THINGSPEAK_INTERVAL) {
    Ciao.write( "rest" , "api.thingspeak.com",  "/update?api_key=Q6SB31YSY9352OW6&field1=29&field2=19");
  }

}

It was configured to only parse speed from the RMC message, so it only adds 1858 bytes of program space and 28 bytes of RAM. :smiley: I could not test the above sketch, but it will probably work.

There are many opportunities to reduce RAM usage in the Ciao library. Every place the library has a "double-quoted" string uses RAM. :stuck_out_tongue:

You should also consider using pins 8 & 9 for the GPS device. That would let you use AltSoftSerial, which is much more efficient than SoftwareSerial. SoftwareSerial blocks interrupts for long periods of time, possibly interfering with other libraries.

If you can't move the GPS to pins 8 & 9, another library I maintain is almost as good as AltSoftSerial: NeoSWSerial. It is also much more efficient than SoftwareSerial, and it will work on any two pins.

It is also IMPORTANT to note that the above sketch does not block for 30 seconds. Instead, it uses the "Blink without delay" technique (here) to keep running all the time. If you block at a delay(30000), the GPS characters do not get handled, and you will not get a good fix. This also allows other parts of your sketch to keep working.

Cheers,
/dev