Arduino Nano HC 05 STOPS the other components from running

Hi! So I got:
x1 Nano
x1 RGB LED
x1 OLED 0.96 inch
x1 DS3231
x1 HC 05

But whenever I add the HC 05, the OLED freezes and fails at this loop:

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

And it returns:
SSD1306 allocation failed

Full Code:

#include <Wire.h>
#include <DS3231.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RGB_LED.h>
// BLUETOOTH
//#include <SoftwareSerial.h> 
//SoftwareSerial MyBlue(2, 3); // RX | TX 



int pause=1000;

DS3231 clock;
RTCDateTime dt;

RGB_LED LED(5,6,7);

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

//RGB
const int redPin = 7;
const int greenPin = 6;
const int bluePin = 5;

#define OLED_RESET     -1// Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
Serial.begin(9600);
    clock.begin();
 
   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.display(); //display initial Adafruit logo
    delay(2000); 

  Serial.println(F("Good!"));

// RGB
  pinMode(redPin,OUTPUT);
  pinMode(greenPin,OUTPUT);
  pinMode(bluePin,OUTPUT);

  LED.setFunction(Fade);
  // Clear the buffer
  display.clearDisplay(); 
  display.display();


}

 void primaryColors(int redValue, int greenValue, int blueValue)
  {
    digitalWrite(redPin, redValue);
    digitalWrite(greenPin, greenValue);
    digitalWrite(bluePin, blueValue);
  }

String DayOfTheWeek(uint8_t Day){
  String DayText;
  if (Day==1)  DayText="Monday";
  if (Day==2)  DayText="Tuesday";
  if (Day==3)  DayText="Wednesday";
  if (Day==4)  DayText="Thursday";
  if (Day==5)  DayText="Friday";
  if (Day==6)  DayText="Saturday";
  if (Day==7)  DayText="Sunday";
  return DayText;
}



String DayMonthYear(uint8_t Day,uint8_t Month,uint16_t Year){
  String DayMonthYearText;
  if (Month==1)  DayMonthYearText="JAN ";
  if (Month==2)  DayMonthYearText="FEB ";
  if (Month==3)  DayMonthYearText="MAR ";
  if (Month==4)  DayMonthYearText="APR ";
  if (Month==5)  DayMonthYearText="MAY ";
  if (Month==6)  DayMonthYearText="JUN ";
  if (Month==7)  DayMonthYearText="JUL ";
  if (Month==8)  DayMonthYearText="AUG ";
  if (Month==9)  DayMonthYearText="SEP ";
  if (Month==10)  DayMonthYearText="OCT ";
  if (Month==11)  DayMonthYearText="NOV ";
  if (Month==12)  DayMonthYearText="DEC ";

  DayMonthYearText=DayMonthYearText+Day;
  if (Day==1)DayMonthYearText=DayMonthYearText+"st ";
  if (Day==2)DayMonthYearText=DayMonthYearText+"nd ";
  if (Day>2)DayMonthYearText=DayMonthYearText+"th ";

  DayMonthYearText=DayMonthYearText+Year;
  
  return DayMonthYearText;
}

String AddLeadingZero(uint8_t x){
  String AddLeadingZeroText;
  if(x<10) AddLeadingZeroText="0"; 
  else AddLeadingZeroText=""; 
  AddLeadingZeroText=AddLeadingZeroText+x;
  return AddLeadingZeroText;
}

String CurrentTime(uint8_t h, uint8_t i ){
  String CurrentTimeText="";
  CurrentTimeText=CurrentTimeText + AddLeadingZero(h) +":"+AddLeadingZero(i);
  return CurrentTimeText;
}

void loop() {
  dt = clock.getDateTime();

  /*if(Serial.available() > 0){ // Checks whether data is comming from the serial port
    data = Serial.read(); // Reads the data from the serial port
    if (data == 0) {
      primaryColors(1,0,0); // White
    }
    else if (data == 1) {
      primaryColors(1,1,1); // White
               
    } 
  }*/
  primaryColors(1,1,1);

  display.fillRect(0,0,128,16,SSD1306_WHITE);
  display.fillRect(0,16,128,28,SSD1306_WHITE);
  display.fillRect(0,28,128,46,SSD1306_BLACK);
  display.fillRect(0,46,128,64,SSD1306_WHITE);

    display.setCursor(15,1); 
    display.setTextSize(2);
    display.setTextColor(SSD1306_BLACK); 
    display.println(DayOfTheWeek(dt.dayOfWeek));

  display.setCursor(1,18); 
  display.setTextSize(1);
  display.setTextColor(SSD1306_BLACK); 
  display.println(DayMonthYear(dt.day,dt.month,dt.year));

    display.setCursor(15,30); 
    display.setTextSize(2);  
    display.setTextColor(SSD1306_WHITE); 
    display.println(CurrentTime(dt.hour,dt.minute));

     display.setCursor(75,30); 
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE); 
  display.println(":");

  display.setCursor(87,30); 
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE); 
  display.println(AddLeadingZero(dt.second));

    display.setCursor(2,48); 
  display.setTextSize(2);
  display.setTextColor(SSD1306_BLACK); 
  display.println("Temp");

  clock.forceConversion();
  display.setCursor(55,48); 
  display.setTextSize(2);
display.setTextColor(SSD1306_BLACK); 
display.print(clock.readTemperature());
display.setCursor(116,46); 
display.setTextSize(1);
display.print("o");


  display.display();
  delay(1000);
}

And this happens whenever I uncomment these lines:

// BLUETOOTH
#include <SoftwareSerial.h> 
SoftwareSerial MyBlue(2, 3); // RX | TX 

Without them, the OLED still refreshes. But once I uncomment them, the screen just freezes. My guess is that, since the max current draw/pin for the Nano is 40mA/PIN, and:
OLED: 20 mA, 5V connected
DS3231: 100-170 uAmps, 5V connected
RGB LED: approx. 50 mA, 5V Connected

So it's a bit above the max current the 5V can supply, but here's the thing:
HC-05: <40 mA while not connected, and approx 20mA while connected to a device.

What causes this issue? I suppose these more amps get it too high for the board to handle and thus it can't provide enough power to the OLED anymore? Because as far as I know the error is because the module can't create 3.3V internally, so something must be stopping it?

Everything is soldered together so there aren't any bad pins; here are some images:




What is that supposed to tell? Adding where? In the code, physically, both or what?

In the code. I said above that it happens when I start adding code for it

Otherwise I see its lights flickering and I can see it on Bluetooth with my phone, but whenever I start adding code for it, the OLED freezes

Powering trouble is suspected.
Please post schematics.

The OLED I had in fritzing has the wrong pins. Mine has only GND,VCC, SDA,SCL

Forgot to tag, I posted the image above

That's not schematics, only a toy picture showing the physics of the devices. It's not useful for failt finding.

I suspect (but I'm only 99% sure) that you run out of memory; the error message indicates that.

128x64 equals 8.192. If that were bytes, you would be out of memory even without the software serial so it must be 8.192 bit which equals 1024 bytes; that is 50% of the available memory of the Nano.

There are other libraries but I'm not familiar with graphic screens to advice which one can do the trick. And else you will have to use an Arduino with more RAM.

Hello nitrosop

Keep it simple and stupid.
Run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.
Have a nice day and enjoy coding in C++.

I would have thought that Nano has sufficient memory to do what you propose, and I can't see the error message. You should get warning of sailing to close to the wind when you compile.

For all that, I don't think the code is anything you would want to show mother.

I believe all that day and month stuff should use case rather than a swag of ifs.

What are you using Serial for?

 if (data == 0) {
      primaryColors(1,0,0); // White
    }
    else if (data == 1) {
      primaryColors(1,1,1); // White

makes no sense to me, and I suspect there is other code referring to other displays that is therefore redundant.

If you are really only using text, I think you will find Adafruits ascii libraries a lot more efficient.
"SSD1306Ascii.h"
"SSD1306AsciiAvrI2c.h"

It is the only way I have used SSD1306.

Further, I suspect your intention is to have the time data transmitted only via Bluetooth and the data to serial monitor is temporary. I therefore don't think you have good reason to use software serial. If correct, you can put Bluetooth on hardware serial and dispense with the software serial library altogether.

The above should reduce your memory requirements.

There is nothing wrong with your fritz, every line seems right - if rather inelegant. Note that it is good practice to use a 1k/2k divider on Nano's Tx, as Bluetooth Rx should be 3.3v.

HC-06 Hw nano
Fritz by Martyn Currey

nano rgb_bb

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