element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Understanding "SSD1306 allocation failure" - Arduino Nano Old bootloader-Adafruit SSD1306 library
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 5 replies
  • Subscribers 388 subscribers
  • Views 1160 views
  • Users 0 members are here
  • ssd1306
  • arduino
Related

Understanding "SSD1306 allocation failure" - Arduino Nano Old bootloader-Adafruit SSD1306 library

robogary
robogary 5 months ago

Understanding "SSD1306 allocation failure" - Arduino Nano Old bootloader - using ADAfruit library 

My latest ongoing project uses a ssd1306 OLED as a message board to display values of temperature sensors, status messages, alarms, etc..

The project is going well, becoming an obsession, adding useful features and ideas, however I kept banging into times where the latest code additions wouldn't execute fully, some IO wouldn't update, and extreme cases where the SSD1306 totally stopped working after an upload of new code.

I'd have to go backward to the previous working code to fix.  The IDE compilation errors window had no errors.

I did eventually discover the "SSD1306 allocation failed " message in the serial monitor.

This is one section of the code that calls to display data to the SSD1306:

float DHT11_humidity= dht11.readHumidity();
// read temperature as Celsius
float DHT11tempC = dht11.readTemperature();
// read temperature as Fahrenheit
float DHT11tempF = dht11.readTemperature(true);

// check if any reads failed
if (isnan(DHT11_humidity) || isnan(DHT11tempC) || isnan(DHT11tempF)) {
Serial.println("Failed to read from DHT11 sensor!");
}

/// display readings to the SSD1306 OLED /////
display.clearDisplay();
delay(ScreenClearDelay);
display.setCursor(0, 10);
// Display static text
display.println("Humidity");
display.println(" %");
display.println(DHT11_humidity);
display.display();
delay(ScreenOnTime);// for reading display


display.clearDisplay();
delay(ScreenClearDelay);
display.setCursor(0, 10);
// Display static text
display.println(" DHT11");
display.println("temp F=");
display.println(DHT11tempF);
display.display();
delay(ScreenOnTime);// for reading display

ScreenOnTime is 3000msec. ScreenClearDelay is 250 msec. 

The program had  11 to 13 information screens like this printed to SSD1306 using more code just like this portion.  

After commenting out an extraneous SSD1306 screen prints, new code was able to be added and IO working. 

There is some limit to how many times the SSD1306 can be called upon to display info, or what can be displayed. 

The allocation message seems more of "can the SSD1306 talk to the address 0x3C" than not enough room for all this simple text. I did see one hint in the Arduino forum to suggest removing SSD1306 screens from the code to avoid this allocation message.

Looking for advice for understanding exactly what the library message is, quantify the number of text screens or memory needed ( which maybe can lead to me to make the code more efficient ), or understand if to change the platform from the old Nano to a newer Arduino with more memory.  

  • Sign in to reply
  • Cancel

Top Replies

  • hardip
    hardip 10 days ago +1
    I think you are using adafruit SSD306 library, in which this function return an error if the buffer memory allocation fails. bool Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset, bool periphBegin…
  • shabaz
    shabaz 5 months ago

    I wasn't really sure what you mean.

    By 'screens' do you mean some sort of windowing inside the physical display, or do you mean you've got multiple physical displays attached to the Arduino? If the latter, you're using multiple I2C interfaces (and if so, are these software I2C interfaces or something?).

    Also, if you can share your code, then maybe some opportunities for reducing resource usage can be identified (e.g. closing I2C interfaces if there is no display updating going on, if you're using many physical displays).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • robogary
    robogary 4 months ago in reply to shabaz

    Thanks, Altho I tried to be clear and succinct in posting the question, reading it again after your feedback, agree the question had vague babble to it  :-) The question has been edited to hopefully make it more intelligible..... maybe.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz 4 months ago in reply to robogary

    Unfortunately there's not enough info. Your code snippet is missing the function that could cause the allocation failed message (something like display.begin()), so I can't tell where and how many times it's called, to try to figure out why resources are not available.

    Also, regarding this part:

    "After commenting out an extraneous SSD1306 screens"

    By screens, are you referring to multiple physical SSD1306 display modules connected to the Arduino?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • robogary
    robogary 4 months ago in reply to shabaz

    My bad, I'm calling the print code snippet as a screen. 

    There is only one physical SSD1306 device. 

    Aw crap. The display.begin is in void setup. That little detail was provided in the original question, but somehow got deleted. I'll add it back in when I get my PC fired up again. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • hardip
    hardip 10 days ago

    I think you are using adafruit SSD306 library, in which this function return an error if the buffer memory allocation fails.

    bool Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, bool reset,
    bool periphBegin) {
    
    if ((!buffer) && !(buffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8))))
    return false;


    as you are using Arduino nano which has only 2Kb ram, which is not sufficient for multiple screens.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube