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: