Help with simple rgb/oled display arduino project issue

I'm in the process of taking a very simple project using the oled display and expanding on it. there are 2 main problems I'm encountering that doesn't seem to be any hardware/wiring mistake. whenever i use the input to add to the blue variable, it freezes my oled screen and also wont show any color on the rgb. the other problem is that at times the bar will stay filled on the highest value achieved, and will not update until a higher value is inputted. my initial reaction is that an arduino uno may not have enough computing power to run an oled screen in pair with an ir sensor and multiple changing values, though although i may be wrong, any ideas on how to fix the current problem would be amazing, I'm also generally new to programming in general so feel free to give tips.

if its anything to do with the micro controller itself i can switch to raspberry pi or esp32.

code below:

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Wire.h>

#define IR_RECEIVER_PIN 7
#include <DIYables_IRcontroller.h> 
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

DIYables_IRcontroller_21 irController(IR_RECEIVER_PIN, 200); 
int Red = 9;
int Green = 10;
int BLUE = 11;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;

void setup() {
  irController.begin();
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
  display.display();
  delay(2000);
 
   display.clearDisplay();
  display.setTextSize(1.7);
  display.setTextColor(WHITE);
   display.setCursor(1,9);
  pinMode(Red, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(BLUE, OUTPUT);
}
void myFun(){
  analogWrite(Red, redValue);
  analogWrite(Green, greenValue);
  analogWrite(BLUE, blueValue);
}

void display_RGB(){
  display.setCursor (1, 1);
        display.print("RED");
        display.fillRect(25, 5, redValue /2, 4, WHITE);
  display.setCursor(1, 25);
      display.print("GREEN");
        display.fillRect(25, 27, greenValue /2, 4, WHITE);

        display.setCursor(1,15);
        display.print("BLUE");
        display.fillRect(25, 18, blueValue /2, 4, WHITE);
   
        display.display();
        
}
void loop() {
  ;
    
  Key21 command = irController.getKey();
  if (command != Key21::NONE) {
    switch (command) {
      case Key21::KEY_CH_MINUS:
      
        break;

      case Key21::KEY_CH:
        break;

      case Key21::KEY_CH_PLUS:
        break;

      case Key21::KEY_PREV:
        break;

      case Key21::KEY_NEXT:
        break;

      case Key21::KEY_PLAY_PAUSE:
        break;

      case Key21::KEY_VOL_MINUS:
        break;

      case Key21::KEY_VOL_PLUS:
        redValue = redValue +10 ;
      
        
        myFun();
        display_RGB();
        break;

      case Key21::KEY_EQ:
        

        break;

      case Key21::KEY_100_PLUS:
        
        break;

      case Key21::KEY_200_PLUS:

        break;

      case Key21::KEY_0:
        blueValue = blueValue +10 ;
        myFun();
        display_RGB();
        break;

      case Key21::KEY_1:
        greenValue = greenValue +10 ;
        myFun();
        display_RGB();
        break;

      case Key21::KEY_2:
        blueValue = 0 ;
        redValue = 0 ;
        greenValue = 0 ;
        myFun();
        display_RGB();
        break;

      case Key21::KEY_3:
        break;

      case Key21::KEY_4:

        break;

      case Key21::KEY_5:
        break;

      case Key21::KEY_6:
        break;

      case Key21::KEY_7:
        break;

      case Key21::KEY_8:
        break;

      case Key21::KEY_9:
        break;

      default:
        break;
    }
  }
}

You forgot to mention the board that you're using. If it's an Uno or a Nano, you're running out of memory.

Sketch uses 20292 bytes (62%) of program storage space. Maximum is 32256 bytes.
Global variables use 997 bytes (48%) of dynamic memory, leaving 1051 bytes for local variables. Maximum is 2048 bytes.

You have to add 1k to the global variables for the SSD1306 because the Adafruit library uses dynamic memory allocation. That does not leave enough space for dynamic stuff like the stack.

There is another library that uses a different approach (I think it's U2g2) and is more efficient. And else a different board with more RAM.

1 Like

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