So I try to use a OLED in my project and display on my OLED some data but while working
on the code I found a problem and couldn't understand why it's happening what's happening.
So I got the OLED simple example code as well DHT lib and SD card library which looks
it's cause the problem.
Code:
// -----------------------------------------------SD_Card
#include <SD.h>
const int chipSelect = 10;
File dataFile;
// -----------------------------------------------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 logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
// -----------------------------------------------DHT11
#include <dht.h>
#define dht_pin A0
dht DHT;
unsigned long DHTCount = 0;
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.drawPixel(10, 10, WHITE);
display.display();
delay(2000);
display.clearDisplay();
}
int x1;
void loop() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(x1);
display.println("Hello, world!");
display.setTextColor(BLACK, WHITE); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.display();
delay(1000);
x1++;
}
The fun part is if I run the code as it's above the OLED will complitly freeze and will not display anything.
but if I get out the sd card part, delete it:
// -----------------------------------------------SD_Card
#include <SD.h>
const int chipSelect = 10;
File dataFile;
the OLED will work normally.
One note that the display will not work even if you put that part in comment /* */
you need to complitly cut it out or delete the SD_Card part so the OLED could work.
I tried even change position maybe the libs work in a order but that didn't helped.
Why this is happening?
I really don't understand, do I miss something?
Is it the sdcard lib processing something that lags all the chip(Ram)?
Thanks for your time,
D.60