So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Chachigo
#69788 I want to Read file from SD (SPI) on my oled display (SSD1306 i2c 128X32) and i have succeeded to print to my diplay also print file name on serial but i never succeeded to print file name on oled

i search for interupt SPI and if i2c and SPi at the same time is possible but i found nothing usefull :/

i use the Arduino IDE so if you think lua is easier to make this tell me (i have never used lua but why not ^^ )

so if you have some tips or a solution i'll take it :)

thanks for your time and your help ;)

PS: I'm french so if my English is too bad for being read tell me and i'll try to explain with other words ^^
User avatar
By QuickFix
#69820 SPI is on GPIO12, 13, 14 & 15 and I2C is (generally) on GPIO4 & 5.
There should be no problem using both of them at the same time.
Just use the SPI-, SD- and SSD1306-libraries and create their objects correctly (set the used GPIO-pins, for the SD-card and the display and I2C address of the OLED, => 0x3c).

Please note that the 128*32 pixel displays are actually 128*64 OLED electronics using only the odds (or even, can't remember) lines. :idea:
User avatar
By rudy
#69822
There should be no problem using both of them at the same time.

I agree.

Post a simple sketch showing what you are doing. Indicate what libraries you are using.

Your English is more than good enough. A thousand times better than my French.
User avatar
By Chachigo
#69829 if spi and i2c may working in the same time i don' understand why it's not working -_-'
currently i try to print the number of file on the oled

Code: Select all#include <SPI.h>
#include <SD.h>
#include <Wire.h>

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

#define OLED_RESET LED_BUILTIN  //4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

File root;
int nbrOfFiles = 0;

void setup() {
 Serial.begin(9600);
 
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 display.display();//work
 delay(1000);
 display.clearDisplay();
 display.setTextColor(WHITE);
 display.setCursor(0,0);
 display.setTextSize(2);
 display.println("Va2.03");//work
 display.display();
 delay(1000);
 display.clearDisplay();
 
 //initialisation carte sd
 display.setCursor(0,0);
 display.setTextSize(1);
 display.display();
 if (!SD.begin(4)) {
    display.clearDisplay();
    display.println("init fail!");
    display.display();
    return;
  }
 display.clearDisplay();
 display.println("init done");//not working
 display.display();
 delay(500);
 display.clearDisplay();
 display.display();

 //ouverture carte sd
 root = SD.open("/ROOT/");
  //comptage des fichiers
 
  nbrOfFiles = CountFiles(root);
  Serial.println("");//work
  Serial.println("DEBUG: ");//work
  Serial.print("Nombre de fichiers : ");//work
  Serial.println(nbrOfFiles);//work
//  CountFiles(root);
 
  display.print("il y a ");//not working
  display.print(nbrOfFiles);//not working
  display.println(" fichiers");//not working
  display.display();
  Serial.println("test 1");//work
}

void loop() {

}

int CountFiles(File dir) {
   int X = 0;
   while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      return X;
    }
    //Serial.print(entry.name());
    if (entry.isDirectory()) {
    } else {
      // files have sizes, directories do not
      X ++;
      //Serial.print("\t\t");
      //Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}