Need help with SD card & OLED screen not working together.

Status
Not open for further replies.
Yeah, sorry about that. That's the main reason I said to "Hang on". I'd realized I hadn't done my part very well.

-jim lee
 
Ok. Finished up the hardware, sorted out all the wiring.

There are three things on the SPI bus. SD drive, Adafruit music card, and an adafruit 128x128 OLED display. The SD drive is sitting on the music card.

As it sits, it plays music. Comment out the music bit and uncomment the screen stuff and it will draw to the screen. I won't do both.
Code:
#include <SPI.h>
#include <SSD_13XX.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <timeObj.h>

// The four shared SPI pins..
// These pins are best choice for Arduino & Teensy.
#define LC_CLK  13  // Clock
#define LC_MISO 12  // Input data
#define LC_MOSI 11  // Output data
#define LC_DC    9  // Data/command

// The  four the sound card uses.
#define SOUND_CS    20
#define SOUND_SDCS  21
#define SOUND_DRQ   1
#define SOUND_RST   15

// The OLED is only using these two. screen & reset.
#define OLED_CS     10
#define OLED_RST    6
#define OLED_SDCS   -1    // Not wired

timeObj songTimer(40);  // 40ms song timer.
SSD_13XX tft(OLED_CS, LC_DC, OLED_RST, LC_MOSI, LC_CLK);

Adafruit_VS1053_FilePlayer musicPlayer =
  Adafruit_VS1053_FilePlayer
  (SOUND_RST, SOUND_CS, LC_DC, SOUND_DRQ, 0);


void setup() {
  Serial.begin(9600); while (!Serial);
  Serial.println(F("Serial's up."));

  SD.begin(SOUND_SDCS);


  if (!musicPlayer.begin()) { // initialise the music player
    Serial.println(F("Couldn't find VS1053"));
  } else {
    Serial.println(F("VS1053 found"));
    musicPlayer.startPlayingFile("Corvette.mp3");
    songTimer.start();
  }

  /*
    tft.begin(false);
    Serial.print("For error we got: ");Serial.println(tft.getErrorCode());
    tft.fillScreen(BLUE);
    tft.print("Ready, Sir!");
  */
}

void loop() {

  if (musicPlayer.playingMusic && songTimer.ding()) {
    noInterrupts();
    musicPlayer.feedBuffer();
    interrupts();
    songTimer.start();
  }
}

Using SUMOTOY's library for the OLED and Adafruit's Adafruit_VS1053_Library for the sound card. Both the sound card & the OLED work fine with the SD card. Doesn't matter which card it's on. Screen or sound work. They won't work together.

The only thing in there that's not right out of the box is my timeObj and that's just giving me a 40ms timer to feed the sound file into the music card.

To be complete, here's the timer code.

timeObj.h
Code:
#ifndef timeObj_h
#define timeObj_h

// Insainly handy for doing things in the background.
// Set the timer and wait 'till it goes "ding". 
// Great for blinking LEDs, updating readings, etc.
// Not fast & accurate enough for RC Servos.
// *** Takes care of roll over issues ***

enum timeType { zero, crossing, normal };

class timeObj {

public:
  timeObj(float inMs=10);

  void setTime(float inMs,bool startNow=true);    // Change the time duration for next start..
  virtual void start(void);                       // Start the timer "now".
  virtual void stepTime(void);                    // Restart the timer from last end time.
  bool ding(void);                                // Timer has expired.
  unsigned long getTime(void);                    // How long does this go for?
    
protected:
  unsigned long waitTime;
  unsigned long startTime;
  unsigned long endTime;
  timeType      config;
};

#endif

And timeObj.cpp
Code:
#include "timeObj.h"
#include <arduino.h>


timeObj::timeObj(float inMs) {

  startTime = 0;
  endTime = 0;
  setTime(inMs);        // This sets startTime and endTime. Best go here?
}


void timeObj::setTime(float inMs,bool startNow) {

  if (inMs>0)
    waitTime = round(1000*inMs);
  else
    waitTime = 0;
  if (startNow) start();
}


void timeObj::start(void) {

    if (waitTime==0) {
        config = zero;
    } else {
        startTime = micros();
        endTime = startTime + waitTime;
        if (endTime < startTime) {
            config = crossing;
        } else {
            config = normal;
        }
    }
}


void timeObj::stepTime(void) {

    if (config!=zero) {
        startTime = endTime;
        endTime = startTime + waitTime;
        if (endTime < startTime) {
            config = crossing;
        } else {
            config = normal;
        }
    }
}


bool timeObj::ding(void) {
  
  unsigned long now;
    
    now = micros();
    switch (config) {
        case zero : return true;
        case crossing :
            if (now >= startTime || now < endTime)
                return false;
            else
                return true;
        break;
        case normal :
            if (now >= startTime && now < endTime)
                return false;
            else
                return true;
        break;
    }
    return true;    // To shut up compiler and shut down an broken timer.
}


unsigned long timeObj::getTime(void) { return waitTime; }

Thank you for your patience.

-jim lee
 
Last edited:
To put this on my to-investigate list, I need a link to the SSD_13XX.h library? My guess is this is Sumotoy's lib, but it's not clear.

Please be very specific. If I can't find this file, or if there are multiple versions and it's not clear which to use, odds are slim I'll go any further.
 
Opps sorry, I was shown the link here so I thought it was well known in these parts. Here is the URL to the library I linked to.

The SUMOTOY library I used.

Now here's something else that came up. To get this far, I went back and cleaned up all my code and wiring. After the cleanup I found the SOMOTOY Library still didn't work. Hence the post above. Since I posted that, I went back and cleaned up the code I use to link to the Original Adafruit library Adafrit SSD-1351 that I used on this OLED. This is where the problem originally started.

After the cleanup, it now works.

So, I have a workaround. The SUMOTOY stuff still won't work with the Sound card. But the Adafruit version is doing the job for now.

-jim lee
 
Nice you got it working jim. Bummer the Sumotoy library isn't working in combination - he's been offline since late summer.

Would be interesting to note what you cleaned up to make the difference if you could spot it.
 
I'm pretty sure there were little issues all over. I'd been building, coding & 3D modeling days and nights for awhile. I understood the high level stuff and tried to wing it on the low level SPI stuff that I didn't really understand. My development system had grown to about a 3 foot long bundle of wire with hardware bits hanging off of it here and there.

After Paul thwacked me one. I stopped, went back and redid everything from the ground up. One issue was that the SPI pin addresses needed to be brought into a common area. Each library has the "do it this way." thing going on. I put the kebash on that. I now have 4 common wires and each bit of hardware. I also have common ways to set up each piece, passing in just the differences.

At the same time I modeled the section of the case that held all the electronics and printed it. I was able to mount all the hardware as it will be mounted in the "real" case and wire up everything to match the code. This made a HUGE difference having something physical to build while writing the code. Now I can be sure all the code matches with the wiring harness. And its going to fit together when this is all complete.

It was last night at sometime past 3AM when I got the original library re-installed and everything started running. I was like "Oh my lord! I think I'm going to pass out!

As for the two libraries SUMOTOY & The music card. I think they each take some liberty with the SPI buss that disallows the other to talk. I still don't know enough about SPI to know what looks like trouble and what looks ok.

Anyway, that's what's going on.

-jim lee
 
Last edited:
Status
Not open for further replies.
Back
Top