Go Down

Topic: how to connect SD card module to Nano with SSD1306 SPI (Read 371 times) previous topic - next topic

tvr4

I am using an Arduino Nano and am having a problem wiring a SD card module with an Adafruit SSD1306 Monochrome display by SPI.

The display works fine using the Adafruit Example ssd1306_128x64_spi.

But I can not get the SD card module to work.

The Wiring of the display was based on the pin assignments in the example
OLED_CLK   10     //SCK on display module
OLED_MOSI   9    //SDA on display module
OLED_RESET 13  //RES on display module
OLED_DC    11   //DC  on display module
OLED_CS     7   //CS  on display module


The SD card sketch from this web site returns "initialization failed".
https://create.arduino.cc/projecthub/electropeak/sd-card-module-with-arduino-how-to-read-write-data-37f390


Wiring is as follows:


Nano 5V to display and SD Module VCC
Nano GND to display and SD Module GND

Nano D13 - SSD1306 Reset
Nano D5   - SD card CS
Nano D7   - SSD1306 CS
Nano D9   - SD MOSI & SSD1306 SDA
Nano D10 - SD SCK & SSD1306 SCK
Nano D11 - SSD1306 DC
Nano D12 - SD MISO


Code: [Select]
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {

Serial.begin(9600);
while (!Serial) {;
}
Serial.print("Initializing SD card...");

if (!SD.begin(5)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");

myFile = SD.open("test.txt", FILE_WRITE);

if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("This is a test file :)");
myFile.println("testing 1, 2, 3.");
for (int i = 0; i < 20; i++) {
myFile.println(i);
}

myFile.close();
Serial.println("done.");
} else {

Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}




Any help is greatly appreciated

tvr4

Found the problem.  Changed wiring and all components work

Components are as follows
------------------------------
Arduino Nano
Adafruit SSD1306 Monochrome Display (SPI)
uBlox 6M GPS Module
MicroSD Module (unknown manufacturer)


Wiring is as follows
---------------------
Nano Pin 5V to all components VCC
Nano GND to all components GND

Nano D13 to OLED SCK & SD SCK
Nano D12 to SD MISO
Nano D11 to OLED SDA(MOSI)
Nano D10 to OLED CS
Nano D9   to OLED RES(RESET)
Nano D8   to OLED DC
Nano D6   to GPS RX
Nano D5   to GPS TX
Nano D4   to SD CS

tvr4

Changed code to reflect new SD CS pin

Orig line
if (!SD.begin(5)) {


New Line
if (!SD.begin(4)) {


Full new and working code to test SD Module
Code: [Select]
[code]#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {

Serial.begin(9600);
while (!Serial) {;
}
Serial.print("Initializing SD card...");

if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");

myFile = SD.open("test.txt", FILE_WRITE);

if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("This is a test file :)");
myFile.println("testing 1, 2, 3.");
for (int i = 0; i < 20; i++) {
myFile.println(i);
}

myFile.close();
Serial.println("done.");
} else {

Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}




Any help is greatly appreciated[/code]

Go Up