AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ThoSan
 
Posts: 3
Joined: Mon Oct 11, 2021 11:43 am

AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

Post by ThoSan »

Hello everyone!
I have a project that uses both of the above libraries concurrently. However, when I combine the 2 libraries into the code, my program doesn't run and it seems the microcontroller hangs (sometimes it keeps resetting). I tried running each library independently with the same hardware and it worked perfectly.
Then I added code line by line until the problem occurred. I found the problem with adding the following statements:
1. display.begin();
display.setTextColor(SH110X_WHITE); //SH1106 library
display.setTextColor(WHITE); //or SSD1306 library
display.display();
2. pwm.setPWM(channel, on, off);

The program will crash when both 1 and 2 appear. Just 1 or 2, it will run normally but will lack the function, or the screen will not display, or the servo will not run.
I have looked at the code in the library but there are no suggestions. In addition, the BH1750 library (part of the project) works well with both libraries (in case of trying each library PCA9685 or SSD1306/SH1106).
I use Arduino IDE 1.8.12 and arduino NANO (clone).
Anyone have any solution?
Thanks!

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

Post by adafruit_support_bill »

. . . when I combine the 2 libraries into the code, my program doesn't run and it seems the microcontroller hangs (sometimes it keeps resetting). I tried running each library independently with the same hardware and it worked perfectly. . . .
Sounds like a possible memory problem. Most likely insufficient SRAM. The Atmega 328 processor only has 2K to work with. https://learn.adafruit.com/memories-of- ... ot-dot-dot

See this page for tips on diagnosing: https://learn.adafruit.com/memories-of- ... m-370031-5

User avatar
ThoSan
 
Posts: 3
Joined: Mon Oct 11, 2021 11:43 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

Post by ThoSan »

adafruit_support_bill wrote:
. . . when I combine the 2 libraries into the code, my program doesn't run and it seems the microcontroller hangs (sometimes it keeps resetting). I tried running each library independently with the same hardware and it worked perfectly. . . .
Sounds like a possible memory problem. Most likely insufficient SRAM. The Atmega 328 processor only has 2K to work with. https://learn.adafruit.com/memories-of- ... ot-dot-dot

See this page for tips on diagnosing: https://learn.adafruit.com/memories-of- ... m-370031-5
Thank! I will try it later. I'm so busy this week.
I have a question. If it's a memory issue, why does the IDE still compile successfully? During program execution, is it possible for the processor to request an additional amount of memory that the compiler did not predict or calculate. I mean the compiler can only know how much memory is used through the variable declarations in the program.
I'm a beginner so I don't fully understand the memory problem you just mentioned

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

Post by adafruit_support_bill »

The compiler knows the size of the code and all of the statically allocated variables. Stack and Heap usage change dynamically during execution and in most cases are impossible to reliably predict. This guide explains it in detail
https://learn.adafruit.com/memories-of- ... o-memories

Image

User avatar
ThoSan
 
Posts: 3
Joined: Mon Oct 11, 2021 11:43 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

Post by ThoSan »

Thank you!
My project worked. But still need to optimize more memory.

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

Post by adafruit_support_bill »

Good to hear! Thanks for the update.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”