Why A program which was working in Arduino 1.0.5 Version is not working in Arduino 1.8.9 Version

Hi Forum,

I'm having ATMEGA328P,

Issue: A working code in Arduino V1.0.5 is not working in Arduino V1.8.9

There is no warning in V1.0.5 but, there is a Warning in V1.8.9:
Sketch uses 19492 bytes (63%) of program storage space. Maximum is 30720 bytes,
Global variables use 1598 bytes (78%) of dynamic memory, leaving 450 bytes for local variables, Maximum is 2048 bytes,
Low memory available, Stability problems may occur.

Controller : ATMEGA328P

I'm able to understand that because of the new version, the memory is getting full..

Is there any way to make it work with the latest IDE Just as working in the V1.0.5 ?

Kind regards,
Dinesh

Please post your sketch, using code tags when you do

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Are you using exactly the same AVR board package (version) and exactly the same libraries in both environments?

Yes! I'm using the same AVR Board and same libraries in both the IDEs

Oh! I'm curious to know the reason that code which is working in V1.0.5 is not working in V1.8.9

Kind regards,
Dinesh

Are the two IDEs on the same PC ?
If not then are the library versions and board files the same on both ?

Two IDEs are in the same PC and using the same library versions!

Memory usage in V1.0.5 = 18654 bytes of 30720
Memory usage in V1.8.9 = 19492 bytes of 32256

The below mentioned code is part of the code which is given by the manufacturer
even this also working in V1.0.5 and not working in V1.8.9

#include <Wire.h>
#include <SPI.h>
#include <TinyScreen.h>

//Library must be passed the board type
//TinyScreenDefault for TinyScreen shields
//TinyScreenAlternate for alternate address TinyScreen shields
//TinyScreenPlus for TinyScreen+
TinyScreen display = TinyScreen(TinyScreenPlus);

//This is an example 17x12 pixel bitmap using TS library color definitions
const unsigned char flappyBirdBitmap[204]={
  TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Blue,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_White,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_White,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Black,TS_8b_Yellow,TS_8b_White,TS_8b_White,TS_8b_White,TS_8b_Yellow,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Blue,
  TS_8b_Blue,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Black,
  TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_Red,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,
  TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Red,TS_8b_Black,TS_8b_Blue,
  TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_Black,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Yellow,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,
  TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Black,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue,TS_8b_Blue
};

void setup(void) {
  Wire.begin();//initialize I2C before we can initialize TinyScreen- not needed for TinyScreen+
  display.begin();
  //setBrightness(brightness);//sets main current level, valid levels are 0-15
  display.setBrightness(10);
}

void loop() {
  hardwareDrawCommands();
  drawPixels();
  drawBitmap();
  //setFlip(boolean);//done in hardware on the SSD1331
  display.setFlip(true);
  delay(1000);
  display.setFlip(false);
  delay(1000);
  writeText();
  delay(1000);
  readInput();
}

void hardwareDrawCommands(){
  //Accelerated drawing commands are executed by the display controller
  //clearScreen();//clears entire display- the same as clearWindow(0,0,96,64)
  display.clearScreen();
  //drawRect(x stary, y start, width, height, fill, 8bitcolor);//sets specified OLED controller memory to an 8 bit color, fill is a boolean- TSRectangleFilled or TSRectangleNoFill
  display.drawRect(10,10,76,44,TSRectangleFilled,TS_8b_Red);
  //drawRect(x stary, y start, width, height, fill, red, green, blue);//like above, but uses 6 bit color values. Red and blue ignore the LSB.
  display.drawRect(15,15,66,34,TSRectangleFilled,20,30,60);
  //clearWindow(x start, y start, width, height);//clears specified OLED controller memory
  display.clearWindow(20,20,56,24);
  //drawLine(x1, y1, x2, y2, 8bitcolor);//draw a line from (x1,y1) to (x2,y2) with an 8 bit color
  display.drawLine(0,0,95,63,TS_8b_Green);
  //drawLine(x1, y1, x2, y2, red, green, blue);//like above, but uses 6 bit color values. Red and blue ignore the LSB.
  display.drawLine(0,63,95,0,0,63,0);
  delay(1000);
  //use 16 bit version of drawLine to fade a rectangle from blue to green:
  for(int i=0;i<64;i++){
    display.drawLine(0,i,95,i,0,i,63-i);
  }
  delay(1000);
}

void drawPixels(){
  //writing pixels one by one is slow, but neccessary for drawing shapes other than lines and rectangles
  //we'll implement a simple circle drawing algorithm from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
  drawCircle(40,30,30,TS_8b_Red);
  drawCircle(45,30,25,TS_8b_Yellow);
  drawCircle(50,30,20,TS_8b_Blue);
  drawCircle(55,30,15,TS_8b_Brown);
  drawCircle(60,30,10,TS_8b_Green);
  drawCircle(65,30,5,TS_8b_Black);
  delay(1000);
}

void drawCircle(int x0, int y0, int radius, uint8_t color)
{
  int x = radius;
  int y = 0;
  int radiusError = 1-x;
 
  while(x >= y)
  {
    //drawPixel(x,y,color);//set pixel (x,y) to specified color. This is slow because we need to send commands setting the x and y, then send the pixel data.
    display.drawPixel(x + x0, y + y0, color);
    display.drawPixel(y + x0, x + y0, color);
    display.drawPixel(-x + x0, y + y0, color);
    display.drawPixel(-y + x0, x + y0, color);
    display.drawPixel(-x + x0, -y + y0, color);
    display.drawPixel(-y + x0, -x + y0, color);
    display.drawPixel(x + x0, -y + y0, color);
    display.drawPixel(y + x0, -x + y0, color);
    y++;
    if (radiusError<0)
    {
      radiusError += 2 * y + 1;
    }
    else
    {
      x--;
      radiusError += 2 * (y - x) + 1;
    }
  }
}

void drawBitmap(){
  //set a background that matches
  display.drawRect(0,0,96,64,TSRectangleFilled,TS_8b_Blue);
  //let's set up for a bitmap at (40,30) that is 17 pixels wide and 12 pixels tall:
  //setX(x start, x end);//set OLED RAM to x start, wrap around at x end
  display.setX(40,40+17-1);
  //setY(y start, y end);//set OLED RAM to y start, wrap around at y end
  display.setY(30,30+12-1);
  //now start a data transfer
  display.startData();
  //writeBuffer(buffer,count);//optimized write of a large buffer of 8 bit data.
  display.writeBuffer(flappyBirdBitmap,17*12);
  display.endTransfer();
  delay(1000);
  
}

void writeText(){
  display.clearScreen();
  //setFont sets a font info header from font.h
  //information for generating new fonts is included in font.h
  display.setFont(thinPixel7_10ptFontInfo);
  //getPrintWidth(character array);//get the pixel print width of a string
  int width=display.getPrintWidth("Example Text!");
  //setCursor(x,y);//set text cursor position to (x,y)- in this example, the example string is centered
  display.setCursor(48-(width/2),10);
  //fontColor(text color, background color);//sets text and background color
  display.fontColor(TS_8b_Green,TS_8b_Black);
  display.print("Example Text!");
  display.setCursor(15,25);
  display.fontColor(TS_8b_Blue,TS_8b_Black);
  display.print("More example Text!");
  display.setCursor(3,40);
  display.fontColor(TS_8b_Red,TS_8b_Black);
  display.print("(Does not wrap)");
  delay(1000);
}

void readInput() {
  display.fontColor(TS_8b_White,TS_8b_Black);
  display.clearScreen();
  display.setCursor(48 - (display.getPrintWidth("Press a Button!") / 2), 32 - (display.getFontHeight() / 2));
  display.print("Press a Button!");
  unsigned long startTime = millis();
  while (millis() - startTime < 3000)buttonLoop();
  display.clearScreen();
  display.setFlip(true);
  display.setCursor(48 - (display.getPrintWidth("Press a Button!") / 2), 32 - (display.getFontHeight() / 2));
  display.print("Press a Button!");
  startTime = millis();
  while (millis() - startTime < 3000)buttonLoop();
  display.clearScreen();
  display.setFlip(false);
}

void buttonLoop() {
  display.setCursor(0, 0);
  //getButtons() function can be used to test if any button is pressed, or used like:
  //getButtons(TSButtonUpperLeft) to test a particular button, or even like:
  //getButtons(TSButtonUpperLeft|TSButtonUpperRight) to test multiple buttons
  //results are flipped as you would expect when setFlip(true)
  if (display.getButtons(TSButtonUpperLeft)) {
    display.println("Pressed!");
  } else {
    display.println("          ");
  }
  display.setCursor(0, 54);
  if (display.getButtons(TSButtonLowerLeft)) {
    display.println("Pressed!");
  } else {
    display.println("          ");
  }
  display.setCursor(95 - display.getPrintWidth("Pressed!"), 0);
  if (display.getButtons(TSButtonUpperRight)) {
    display.println("Pressed!");
  } else {
    display.println("          ");
  }
  display.setCursor(95 - display.getPrintWidth("Pressed!"), 54);
  if (display.getButtons(TSButtonLowerRight)) {
    display.println("Pressed!");
  } else {
    display.println("          ");
  }
}

We're interested in the dynamic memory report, not in the program memory.

Note:
I'm absolutely not familiar with version 1.0.5 (or anything before 1.6.6).

V1.8.9 = 1598bytes (78%) of dynamic memory leaving 450 bytes for local variables

Understood!

I'm not sure if we're on the same track :wink:

On a portable install of 1.8.9 (AVR board package 1.6.23), the code from post #9 compiles to

Sketch uses 8056 bytes (24%) of program storage space. Maximum is 32256 bytes.
Global variables use 582 bytes (28%) of dynamic memory, leaving 1466 bytes for local variables. Maximum is 2048 bytes.

Far from what you got.

Using a standard IDE2.3.3 installation (AVR board package 1.8.6) I get

Sketch uses 8590 bytes (26%) of program storage space. Maximum is 32256 bytes.
Global variables use 588 bytes (28%) of dynamic memory, leaving 1460 bytes for local variables. Maximum is 2048 bytes.

It looks like 1.0.5-r2 does not support a portable install so I can't test.

If you can tell me the version of the AVR board package that you're using, I can downgrade that in the IDEs that I mentioned.

PS
The TinyScreen library is the latest version.

@dinesh_bylu

There were changes, fixes and features, since 1.0.5. You can check them in the release notes.

So there are probably many many causes for the additional memory usage.
Fixes and changes will almost always increase the footprint of the software.

There is probably a law for that

You still not answered us what is working and what not in 1.8.9 IDE

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.