Ok everyone thanks for the help. The OLED and SD-Card now work.
My next issue is the DFPlayer, again worked before on the UNO but now this fails to initialise.
Here is the first part of the code:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
#include <SPI.h>
#include <SdFat.h> // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions
#include "SoftwareSerial.h" //DFPLAYER
#include "DFRobotDFPlayerMini.h" //DFPLAYER
// You can use any (4 or) 5 pins
#define sclk 52 //13 SCK (CK) //12 SO //52
#define mosi 51 //11 SI //51
#define cs 53 //10 OCS (OC) //53
#define rst 9 //R
#define dc 8 //DC
#define SD_CS 4 //SC SD card select pin
// Rotary Encoder Inputs
#define CLK 6
#define DT 5
#define SW 3 //SWITCH BUTTON
// Color definitions
#define BLACK 0x0000
SdFat SD; // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
//DFPlayer Pins
SoftwareSerial mySoftwareSerial(19, 18); // RX, TX
// Create the Player object
DFRobotDFPlayerMini player;
// Option 1: use any pins but a little slower
//Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);
// Option 2: must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_SSD1331 display = Adafruit_SSD1331(&SPI, cs, dc, rst);
int button = 7;
int press = 0;
int toggle = 0;
int firstTime = true;
//ROTARY VARIABLES
int currentStateCLK;
int lastStateCLK;
String currentDir ="";
void setup(void) {
pinMode(button, INPUT);
digitalWrite(7, HIGH);
// Set encoder pins as inputs
pinMode(CLK,INPUT);
pinMode(DT,INPUT);
pinMode(SW, INPUT_PULLUP);
// Init USB serial port for debugging
Serial.begin(9600);
// Init serial port for DFPlayer Mini
mySoftwareSerial.begin(9600);
if (player.begin(mySoftwareSerial)) {
Serial.println("DFPLayer OK");
// Set volume to maximum (0 to 30).
player.volume(30);
} else {
Serial.println("Connecting to DFPlayer Mini failed!");
}
// Read the initial state of CLK
lastStateCLK = digitalRead(CLK);
// SD card is pretty straightforward, a single call...
if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
Serial.println(F("SD begin() failed"));
for(;;); // Fatal error, do not continue
}
char bmpFile[14]; //buffer for file name
//store repetitive file names in PROGMEM to prevent redundent copies
static const char bmpIntro00[] PROGMEM = "/Intro_00.bmp";
static const char bmpIntro01[] PROGMEM = "/Intro_01.bmp";
static const char bmpIntro02[] PROGMEM = "/Intro_02.bmp";
static const char bmpIntro03[] PROGMEM = "/Intro_03.bmp";
display.begin();
display.fillScreen(BLACK);
//SHOW INITIALISING SCREEN
//reader.drawBMP("/Intro_00.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro00);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_01.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro01);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_02.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro02);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_03.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro03);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_00.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro00);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_01.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro01);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_02.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro02);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_03.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro03);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_00.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro00);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_01.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro01);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_02.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro02);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_03.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro03);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_00.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro00);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_01.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro01);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_02.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro02);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_03.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro03);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_00.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro00);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_01.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro01);
reader.drawBMP(bmpFile, display, 0, 0);;
delay(50);
//reader.drawBMP("/Intro_02.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro02);
reader.drawBMP(bmpFile, display, 0, 0);
delay(50);
//reader.drawBMP("/Intro_03.bmp", display, 0, 0);
strcpy_P(bmpFile, bmpIntro03);
reader.drawBMP(bmpFile, display, 0, 0);
//PLAY ZF-1 ANIM
display.fillScreen(BLACK);
reader.drawBMP("/Zf1_00.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_01.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_02.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_03.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_04.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_05.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_06.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_07.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_08.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_09.bmp", display, 0, 0);
delay(0);
reader.drawBMP("/Zf1_10.bmp", display, 0, 0);
delay(1500);
reader.drawBMP("/Zf1_11.bmp", display, 0, 0);
}
void loop() {
//ButtonPressCode
press = digitalRead(button);
if (press == LOW){
playSound();
}
// Read the current state of CLK
currentStateCLK = digitalRead(CLK);
// If last and current state of CLK are different, then pulse occurred
// React to only 1 state change to avoid double count
if (currentStateCLK != lastStateCLK && currentStateCLK == 1){
// If the DT state is different than the CLK state then
// the encoder is rotating CCW so decrement
if (digitalRead(DT) != currentStateCLK) {
if(firstTime == true){
firstTime = false;
}else{
if(toggle != -5){
toggle --;
}else{
toggle = 0;
}
}
currentDir ="CCW";
//RUN IMAGE FUNCTION
showImage();
} else {
if(firstTime == true){
firstTime = false;
}else{
if(toggle != 5){
// Encoder is rotating CW so increment
toggle ++;
}else{
toggle = 0;
}
}
currentDir ="CW";
//RUN IMAGE FUNCTION
showImage();
}
}
// Remember last CLK state
lastStateCLK = currentStateCLK;
}