Hello.
I have atmega644 with sanguino bootloader. I programming it using USBasp. All peripherals like OLED and RTC works only the SD card doesen't work. I connect it as shown below:
SD --- ATMEGA
mosi--5
miso--6
sck--7
cs--4
When it starts it display cant initialize sd card (in english because i'm polish)
Here is code (with english version of text)
const int buttonPin = 8;
int buttonState = 0;
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Rtc_Pcf8563.h>
#include <SD.h>
#include <Wire.h>
#define OLED_DC A3 //OLED -- D/C
#define OLED_CS 0 //Not connect
#define OLED_CLK A4 //OLED -- SCL
#define OLED_MOSI A1 //OLED -- SDA
#define OLED_RESET A2//OLED -- RST
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
Rtc_Pcf8563 rtc;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC);
display.setTextSize(1);
display.setTextColor(WHITE);
display.clearDisplay();
display.display();
rtc.initClock();
//day, weekday, month, century, year
rtc.setDate(26, 1, 5, 0, 14);
//hr, min, sec
rtc.setTime(20, 05, 20);
pinMode(buttonPin, INPUT);
display.setCursor(0,0);
display.println("Loading SD card");
display.display();
pinMode(10, OUTPUT);
delay(500);
display.clearDisplay();
if (!SD.begin(4)) {
display.setCursor(0,0);
display.println("Can't Initialize SD card");
display.display();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
display.setCursor(0,0);
display.println("SD card loaded");
display.display();
delay(500);
}
void loop()
{
// ---------clock--------
display.setTextSize(2);
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
display.clearDisplay(); // Clear OLED
display.setCursor(20,20);
display.print(rtc.formatTime());
display.display();
delay(1000);
}
delay(500);
buttonState = 0;
// ------file #1-------
display.setTextSize(1);
display.setCursor(0,0);
File dataFile = SD.open("datalog.txt");
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
display.clearDisplay();
display.write(dataFile.read());
display.display();
}
dataFile.close();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
// if the file isn't open, pop up an error:
else {
display.clearDisplay();
display.println("Problem with datalog.txt");
display.display();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
// ---------file #2------------
display.setCursor(0,0);
File dataFile2 = SD.open("datalog2.txt");
// if the file is available, write to it:
if (dataFile2) {
while (dataFile2.available()) {
display.clearDisplay();
display.write(dataFile2.read());
display.display();
}
dataFile2.close();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
// if the file isn't open, pop up an error:
else {
display.clearDisplay();
display.println("Problem with datalog2.txt");
display.display();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
//----------file #3-----------
display.setCursor(0,0);
File dataFile3 = SD.open("datalog3.txt");
// if the file is available, write to it:
if (dataFile3) {
while (dataFile3.available()) {
display.clearDisplay();
display.write(dataFile3.read());
display.display();
}
dataFile3.close();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
// if the file isn't open, pop up an error:
else {
display.clearDisplay();
display.println("Problem with datalog3.txt");
display.display();
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
}
delay(500);
buttonState = 0;
}
}
i tried everything please help