Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

by ThoSan on Mon Oct 11, 2021 12:11 pm

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!

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

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

by adafruit_support_bill on Mon Oct 11, 2021 3:01 pm

. . . 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

adafruit_support_bill
 
Posts: 82463
Joined: Sat Feb 07, 2009 10:11 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

by ThoSan on Fri Oct 15, 2021 10:42 pm

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

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

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

by adafruit_support_bill on Sat Oct 16, 2021 6:38 am

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

adafruit_support_bill
 
Posts: 82463
Joined: Sat Feb 07, 2009 10:11 am

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

by ThoSan on Sun Oct 17, 2021 10:16 am

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

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

Re: AdafruitPWM library and Adaftuit SSD1306/SH1106 conflict

by adafruit_support_bill on Sun Oct 17, 2021 10:37 am

Good to hear! Thanks for the update.

adafruit_support_bill
 
Posts: 82463
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.