I'm out of memory? Is the next thing up the Mega644P?

Sounds reasonable, especially if you have a lot of additional features you want to add. It might be worth posting your code though to see if anyone can suggest ways to save space, even if it just helps you avoid the problem on your new hardware.

The mega1284p, (same packages as the 644) may be interesting as well, it has 4 times as much flash and 8 times as much ram as the 328-chip.

Thanks to both of you! Is the Arduino IDE support for the 1284 the same as for the 644?

WildBill, the code is fairly convoluted (as stated before, I don't know what I am doing), but I have posted it up on Github (mainly as a back up for me in case my macbook craps out). It would be great if you would care to work your way through it to see if there are any major savings to be had. Memory wise I am fine until I add the SD library. I know there are some trimmed down versions but it would still be close and I would just like a bigger pool to swim in so that I can add more features.

It is located here:

jerseyguy1996:
Thanks to both of you! Is the Arduino IDE support for the 1284 the same as for the 644?

Yes, even slightly better, the latest sanguino-code at Google Code Archive - Long-term storage for Google Code Project Hosting. supports the 1284p at two speeds (8,16 MHz) and the 644p at 16 MHz.

jerseyguy1996:
Thanks to both of you! Is the Arduino IDE support for the 1284 the same as for the 644?
............
GitHub - jerseyguy1996/Leslie_GPS_Breadboard: Breadboarded 328, GPS, and OLED Display

Unless changed in the most recent versions, the standard IDE libraries don't have direct support
for 1284 chips [or 644 ???], nor probably do several of the header files in the relevant libraries,

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
#include <avr/sleep.h>
#include <avr/power.h>

In general, you need to make changes such as the following for this to work, find the lines in
all of the library source and header files that say something like this,

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };

and add the 1284P extension:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };

There are also a host of other issues with 1284 chips, which were discussed in long threads
in Feb 2013 in the Microcontrollers section.

Oy......who's right? Simpson_jr says yes and Oric_dan says maybe if I am willing to do some extra stuff. I guess either way it can work....it may just not be a turn key solution. I'll pick up the PDIP version of the 644 and 1284 and breadboard it. Maybe it will work out of the box and if not perhaps it presents a good learning experience for me on some of the behind the scenes stuff in the libraries. Thanks guys!

You can figure it out for yourself. Look in the libraries and various include files, and see if
they say this:

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)

or this:

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560) || defined(AVR_ATmega1284P)

Then you'll know. What you're gonna find is sometimes fixed, sometimes not.

Here's a clue, in the very latest of version of the IDE, the Arduino.h file [hidden many
levels deep in the IDE directory] says:

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560) || defined(AVR_ATmega1284) || defined(AVR_ATmega1284P) || defined(AVR_ATmega644) || defined(AVR_ATmega644A) || defined(AVR_ATmega644P) || defined(AVR_ATmega644PA)

whereas it previously said:

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560) || defined(AVR_ATmega1284P) || defined(AVR_ATmega644P)

and before that:

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)

However, in w500.h in the standard Ethernet library in the very latest version of the
IDE, it still says

#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)

so your Ethernet board won't work with 1284 chips.

The point is, 1284 support has only recently been started to be included in the IDE
AT ALL, and still hasn't been completely wrung out. The reason I know this is because
I've had to fix these things myself to get my 1284 boards to work.

If you really want an education, go read some of those interminable threads, where people
were scratching their heads for weeks, trying to get this stuff to work,
http://forum.arduino.cc/index.php?topic=139671.0
http://forum.arduino.cc/index.php/topic,146773.msg1102743.html
http://forum.arduino.cc/index.php/topic,144165.msg1082609.html
http://forum.arduino.cc/index.php?topic=80483.0
http://forum.arduino.cc/index.php/topic,109550.msg822612.html

jerseyguy1996:
Well I've come to the sad realization that my code is just too long for the Mega328. I am positive that part of this is just that I don't code very efficiently (because I don't know what the heck I am doing) but going through all of my variables, even if I put some of the constant data (strings and such) in progmem I am still going to be constrained and it won't allow for any additional features on my program. I'm thinking the Mega644P may be a good next step up since it appears that the good folks at Sanguino have added support for this uC in the arduino IDE. It doubles the amount of flash and sram relative to the 328. It also comes in a fairly reasonably sized package (I don't need something in a massive 100 pin package). Any thoughts on using the 644P as a reasonable next step up from the 328?

I am not sure what you are trying to do but I think better coding would allow you to have all the features you want and keep using the atmega328. Also you only want strings and constant arrays in PROGMEM if it is just one varible you don't want that in PROGMEM. If it turns out that it is impossible to get the code to fit on an atmega328 then I would get something with more flash. Would you be able to post your code? It would help me evaluate if you really need to upgrade or this could be optimized to fit on an atmega328.

Mr_arduino:

jerseyguy1996:
Well I've come to the sad realization that my code is just too long for the Mega328. I am positive that part of this is just that I don't code very efficiently (because I don't know what the heck I am doing) but going through all of my variables, even if I put some of the constant data (strings and such) in progmem I am still going to be constrained and it won't allow for any additional features on my program. I'm thinking the Mega644P may be a good next step up since it appears that the good folks at Sanguino have added support for this uC in the arduino IDE. It doubles the amount of flash and sram relative to the 328. It also comes in a fairly reasonably sized package (I don't need something in a massive 100 pin package). Any thoughts on using the 644P as a reasonable next step up from the 328?

I am not sure what you are trying to do but I think better coding would allow you to have all the features you want and keep using the atmega328. Also you only want strings and constant arrays in PROGMEM if it is just one varible you don't want that in PROGMEM. If it turns out that it is impossible to get the code to fit on an atmega328 then I would get something with more flash. Would you be able to post your code? It would help me evaluate if you really need to upgrade or this could be optimized to fit on an atmega328.

Sure! There is a link on reply #3 that has the code.

oric_dan:
You can figure it out for yourself. Look in the libraries and various include files.......

If you really want education, go read some of those interminable threads, where people
were scratching their heads for weeks, trying to get this stuff to work,
Help in programming the Atmega1284 with maniacbug-mighty-1284p. - Microcontrollers - Arduino Forum
Boards with 1284p - full swing oscillator setting - solving upload issues? - Microcontrollers - Arduino Forum
funny A/D channel readings with Bobuino-1284 ??? - Microcontrollers - Arduino Forum
ATmega1284P: End to End using 1.0 IDE - Microcontrollers - Arduino Forum
Issue with Mighty 1284P Optiboot bootloader on STK500 - Microcontrollers - Arduino Forum

This is fantastic information! Thanks!

jerseyguy1996:
Well I've come to the sad realization that my code is just too long for the Mega328.

From your comment about code length I guess you're talking about program memory. How much is your sketch taking currently? You've only got a few hundred lines of code there so I wouldn't have thought that your own code would be using up a lot of it and probably the libraries you're using are responsible for most of it.

By the way, your implementation of timer() does not handler millis() overflow correctly. To handle overflow, you can code it like this:

if(millis() - lastTime > interval)
{
    // interval has expired
    ....

PeterH:
By the way, your implementation of timer() does not handler millis() overflow correctly. To handle overflow, you can code it like this:

if(millis() - lastTime > interval)

{
    // interval has expired
    ....

Mine should do the same thing. My code is:

//keep track of time and handle millis() rollover
boolean timer(unsigned long timeout)
  {
    return (long)(millis() - timeout) >= 0;
  }

and then when I need to time something I do something like this:

last_valid_data = millis() + 2000;

and then I can just call timer like this:

if(timer(last_valid_data))

which I believe mathematically is equivalent to your code. I could be wrong though. I took calculus twice in college and still only squeaked out a "C" grade so my math may not be up to snuff.

jerseyguy1996:
I believe mathematically is equivalent to your code. I could be wrong though.

It is equivalent, except that your version doesn't handle counter rollover correctly.

jerseyguy1996:

oric_dan:
You can figure it out for yourself. Look in the libraries and various include files.......

If you really want education, go read some of those interminable threads, where people
were scratching their heads for weeks, trying to get this stuff to work,
Help in programming the Atmega1284 with maniacbug-mighty-1284p. - Microcontrollers - Arduino Forum
Boards with 1284p - full swing oscillator setting - solving upload issues? - Microcontrollers - Arduino Forum
funny A/D channel readings with Bobuino-1284 ??? - Microcontrollers - Arduino Forum
ATmega1284P: End to End using 1.0 IDE - Microcontrollers - Arduino Forum
Issue with Mighty 1284P Optiboot bootloader on STK500 - Microcontrollers - Arduino Forum

This is fantastic information! Thanks!

I also wrote up a page discussing my fixes and experiences,
http://www.ot-hobbies.com/resource/ard-1284.htm

//keep track of time and handle millis() rollover

boolean timer(unsigned long timeout)
  {
    return (long)(millis() - timeout) >= 0;
  }

The rollover business is fairly subtle. As I recall, the code in the BlinkWithoutDelay example
works correctly [although it does look like they declared previousMillis poorly]. Other forms
may look correct, but will give incorrect results. It pays to feed in a few values near the
rollover value and test the different forms.

long previousMillis = 0;        // will store last time LED was updated

void loop()
{
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

oric_dan:
I also wrote up a page discussing my fixes and experiences,
http://www.ot-hobbies.com/resource/ard-1284.htm

I just read through your link and it is fantastic! I am wondering though, does any of this matter with regards to the package that I choose? I am trying to fit this all onto a fairly small board so I probably won't use the pdip version of the 1284P. If I am feeling brave I may go for something as small as the QFN package as I have had a lot of success hand soldering a 4mmx4mm QFN10 package and I think I may be okay soldering something that is materially bigger than that.

I think most of those items will still be applicable, except possibly the RX0
problem. Depends on whether the RX0 pin is located adjacent to the
Oscillator-in pin on the chip you use. Also, maniac bug still hasn't fixed
the Bobuino variant file. And you will still need to check all of the
library files for proper 1284 support.

oric_dan:
I think most of those items will still be applicable, except possibly the RX0
problem. Depends on whether the RX0 pin is located adjacent to the
Oscillator-in pin on the chip you use. Also, maniac bug still hasn't fixed
the Bobuino variant file. And you will still need to check all of the
library files for proper 1284 support.

Excellent! Thanks!

I believe this file has the Bobuino issues fixed - its the one I use with my boards.
I have comments in to show the two lines that were changed.

pins_arduino.h (6.26 KB)

Good to hear, Bob. But will the github library files ever get fixed? $64 question.