nRF24L01 + OLED 128x64 i2c problem

So i’ve been playing with nRF’s and OLED for a while and decided to make a project connecting them together, tested the OLED with the

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

…etc Libraries working pretty good and tested the nRF as well.

So i decided to make a code combining them and while receiving the data to print them on
OLED but i got always a problem.

While i upload the code i wrote with only the nRF it’s working or only with OLED but if I put them together the OLED freez and the nRF as well, the Loop freez.

Code:

//-------------------------------------------------------------------OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 

static const unsigned char PROGMEM BMP_DEMO[] =
{};
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
//-------------------------------------------------------------------OLED
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>



RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

int dataReceived[6];
 
unsigned long pM = 0;
const long interval = 1000;
const int buzzer = 8;
int bS = 0;

void setup(){
  Serial.begin(9600);
  
   //-------------------------------------------------------------------OLED
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  display.clearDisplay();
 //-------------------------------------------------------------------OLED
 
  radio.begin();
//radio.setAutoAck(false);
  radio.setChannel(108); //108 - 2.508 Ghz //0-124 2.4gHz-2.5gHz
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  //Serial.println("Start");
  pinMode(buzzer,OUTPUT);
 // radio.printDetails();

}
 int x = 0;

void loop(){
  
    unsigned long cM = millis();
    
    
 if (radio.available()){
  radio.read(dataReceived, sizeof(dataReceived));
  x++; 
    bS = dataReceived[3];
    if(bS == HIGH){digitalWrite(buzzer, HIGH);}else{digitalWrite(buzzer, LOW);}
     
      if (cM - pM >= interval){
        pM = cM;  
           //  Serial.print("Data: ");
 //-------------------------------------------------------------------OLED
   
       display.clearDisplay();
       display.setTextColor(WHITE);
       display.setCursor(0,0);
       display.print("PotS: ");
       display.println(dataReceived[0]);
       
       display.print("PotY: ");
       display.println(dataReceived[1]);
       
       display.print("PotX: ");
       display.println(dataReceived[2]);
       
       display.print("S1: ");
       display.println(dataReceived[3]);
       
       display.print("S2: ");
       display.println(dataReceived[4]);
       
       display.print("S3: ");
       display.println(dataReceived[5]);
       
       display.print("Packets: ");
       display.println(x);
       display.display();
       
  
 //-------------------------------------------------------------------OLED 
 /*  Serial.print("D "); Serial.print(dataReceived[0]);
    Serial.print("D "); Serial.print(dataReceived[1]);
    Serial.print("D "); Serial.print(dataReceived[2]);   
    Serial.print("D "); Serial.print(dataReceived[3]); 
    Serial.print("D "); Serial.print(dataReceived[4]);
    Serial.print("D "); Serial.print(dataReceived[5]);
          Serial.print("P");Serial.println(x); */  
    
           
           x = 0;
         }
    }
  
}

/* Domino60 */

The OLED freeze at the adafruite logo.

Not really sure why, is this because I try to process many Bytes per sec?

I'm going to guess you're short of RAM.
Lose the logo entirely.
Make better use of the F() macro.

Make better use of the F() macro.

What do you mean?

As I know atmega328p got about 2kByte Ram, I got in my loop less than 1k.

What do I mean?

I mean you look to be quite profligate with respect to RAMdisplay.print("PotY: ");, and I imagine the OLED library uses quite a lot.

I mean you look to be quite profligate with respect to RAM
, and I imagine the OLED library uses quite a lot.

How much exactly the OLED uses? I mean in my loop i got about 54Bytes of characters, total Ram of atmega328 is 2KB and not being able to print on OLED kinda sucks. I used OLED in the past with a GPS module printing about 60+ characters and didn't had that kind of problem.

Is there a way to reduce the problem here? I know that nRF it's talking a lot of ram as well but dam it's once per sec.

should i create more millis() and put them each println in a 100ms~200~300..etc loop?

So i done some tests, got everything out of the loop and left only few lines
the OLED get’s many random pixels on the display and does noting, i got out the adafruit logo

code:

//-------------------------------------------------------------------OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

//-------------------------------------------------------------------OLED
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>



RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

int dataReceived[6];
 
unsigned long pM = 0;
const long interval = 1000;
const int buzzer = 8;
int bS = 0;

void setup(){
  Serial.begin(9600);
  
   //-------------------------------------------------------------------OLED
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 // display.display();
  display.clearDisplay();
 //-------------------------------------------------------------------OLED
 
  radio.begin();
//radio.setAutoAck(false);
  radio.setChannel(108); //108 - 2.508 Ghz //0-124 2.4gHz-2.5gHz
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  //Serial.println("Start");
  pinMode(buzzer,OUTPUT);
 // radio.printDetails();

}
 int x = 0;

void loop(){
  
    unsigned long cM = millis();
    
    
 if (radio.available()){
  radio.read(dataReceived, sizeof(dataReceived));
  x++; 
    bS = dataReceived[3];
    if(bS == HIGH){digitalWrite(buzzer, HIGH);}else{digitalWrite(buzzer, LOW);}
     
       
           //  Serial.print("Data: ");
 //-------------------------------------------------------------------OLED
   if (cM - pM >= interval){
        pM = cM; 
       display.clearDisplay();
       display.setTextColor(WHITE);
       display.setCursor(0,0);
       
  /*   //  display.print("P1:");
       display.println(dataReceived[0]);
    
       
//display.print("P2:");
       display.println(dataReceived[1]);
      
       
     //  display.print("P3:");
       display.println(dataReceived[2]);
     
       
     //  display.print("S1:");
       display.println(dataReceived[3]);
     
       
     //  display.print("S2:");
       display.println(dataReceived[4]);
 
       
      // display.print("S3:");
       display.println(dataReceived[5]);

       
       */
    //   display.print("Packets: ");
       display.println(x);
       display.display();          
           x = 0;
         }
    }
  
}

/* Domino60 */

If i plug out the nRF and do a reset the OLED starts printing.
It’s not a Ram problem anymore, not sure what exactly is the problem, does the nRF code affect the display?

So I done small updated on the code and modifications OLED is working now but there is another problem
there is no radio available kinda strange, tested same code without OLED and it’s working but with the OLED it’s not.

Code:

//-------------------------------------------------------------------OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
//-------------------------------------------------------------------OLED
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>



RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

int dataReceived[6];
 
unsigned long pM = 0;
const long interval = 1000;
const int buzzer = 8;
int bS = 0;

void setup(){
  Serial.begin(9600);
    radio.begin();
  radio.setAutoAck(false);
  radio.setChannel(108); //108 - 2.508 Ghz //0-124 2.4gHz-2.5gHz
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.openReadingPipe(1,pipe);
  radio.startListening();
   //-------------------------------------------------------------------OLED
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
       display.setTextColor(WHITE);
       display.setCursor(0,0);
       display.println("D60");
       display.display();
 //-------------------------------------------------------------------OLED
}
 int x = 0;

void loop(){
  
    unsigned long cM = millis();
    
        
    
 if (radio.available()){
  radio.read(dataReceived, sizeof(dataReceived));
  x++; 
    bS = dataReceived[3];
    if(bS == HIGH){digitalWrite(buzzer, HIGH);}else{digitalWrite(buzzer, LOW);}
     
       
           //  Serial.print("Data: ");
 //-------------------------------------------------------------------OLED
   if (cM - pM >= interval){
        pM = cM; 
       display.clearDisplay();
       display.setTextColor(WHITE);
       display.setCursor(0,0);
       display.println("D60");
       
     //  display.print("P1:");
       display.println(dataReceived[0]);

       
//display.print("P2:");
       display.println(dataReceived[1]);
      
       
     //  display.print("P3:");
       display.println(dataReceived[2]);
     
       
     //  display.print("S1:");
       display.println(dataReceived[3]);
     
       
     //  display.print("S2:");
       display.println(dataReceived[4]);
 
       
      // display.print("S3:");
       display.println(dataReceived[5]);

       

    //   display.print("Packets: ");
       display.println(x);
       // Serial.println(x);         
           x = 0;
           display.display();
         }
    } else {
      display.clearDisplay();
       display.setTextColor(WHITE);
       display.setCursor(0,0);
       display.println("NO SIGNAL");
       display.display();
    }
}

/* Domino60 */

After I done modifications, everything is working but I get always “NO SIGNAL” not sure why the nRF code is not working…