jim lee
Well-known member
I have a setup, Adafruit 1.5" OLED screen (Adafruit_SSD1351), Teensy 3.2, and now a adafruit Music card (Adafruit_VS1053) Everything is running on the SPI bus. With this same hardware I can A) do a mp3 player with a Serial command line interface, or B) a breakout game running on the OLED. C) With a different display (Adafruit_ILI9341) I did the calculator & vacuum gauge. The vacuum gauge used the SD card to read in its .bmp file background image. It works with SD.
I can NOT get the OLED to work with the SD file library. If I start with SD.begin(SD_PIN) the screen won't work, If I start with OLED.begin() the SD card won't work. I suspect there's something that the OLED library is doing that the SD stuff doesn't like. But I'm too weak in the low level SPI stuff to understand what's going wrong. And by now my head hurts.
My SD select pin is 4, I can't find anywhere that the OLED could think that pin 4 is something it it uses. IS there something anyone knows about OLED & SD files stuff not working together that I missed?
The OLED begin() that "I think" is causing trouble.
The "other tft" screen that works fine has this at the top of the file.
And its begin..
Thanks for looking at this. I really appreciate it!
-jim lee
I can NOT get the OLED to work with the SD file library. If I start with SD.begin(SD_PIN) the screen won't work, If I start with OLED.begin() the SD card won't work. I suspect there's something that the OLED library is doing that the SD stuff doesn't like. But I'm too weak in the low level SPI stuff to understand what's going wrong. And by now my head hurts.
My SD select pin is 4, I can't find anywhere that the OLED could think that pin 4 is something it it uses. IS there something anyone knows about OLED & SD files stuff not working together that I missed?
The OLED begin() that "I think" is causing trouble.
Code:
void Adafruit_SSD1351::begin(void) {
// set pin directions
pinMode(_rs, OUTPUT);
if (_sclk) {
pinMode(_sclk, OUTPUT);
pinMode(_sid, OUTPUT);
} else {
// using the hardware SPI
SPI.begin();
SPI.setDataMode(SPI_MODE3);
}
// Toggle RST low to reset; CS low so it'll listen to us
pinMode(_cs, OUTPUT);
digitalWrite(_cs, LOW);
if (_rst) {
pinMode(_rst, OUTPUT);
digitalWrite(_rst, HIGH);
delay(500);
digitalWrite(_rst, LOW);
delay(500);
digitalWrite(_rst, HIGH);
delay(500);
}
// Initialization Sequence
writeCommand(SSD1351_CMD_COMMANDLOCK); // set command lock
writeData(0x12);
writeCommand(SSD1351_CMD_COMMANDLOCK); // set command lock
writeData(0xB1);
writeCommand(SSD1351_CMD_DISPLAYOFF); // 0xAE
writeCommand(SSD1351_CMD_CLOCKDIV); // 0xB3
writeCommand(0xF1); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
writeCommand(SSD1351_CMD_MUXRATIO);
writeData(127);
writeCommand(SSD1351_CMD_SETREMAP);
writeData(0x74);
writeCommand(SSD1351_CMD_SETCOLUMN);
writeData(0x00);
writeData(0x7F);
writeCommand(SSD1351_CMD_SETROW);
writeData(0x00);
writeData(0x7F);
writeCommand(SSD1351_CMD_STARTLINE); // 0xA1
if (SSD1351HEIGHT == 96) {
writeData(96);
} else {
writeData(0);
}
writeCommand(SSD1351_CMD_DISPLAYOFFSET); // 0xA2
writeData(0x0);
writeCommand(SSD1351_CMD_SETGPIO);
writeData(0x00);
writeCommand(SSD1351_CMD_FUNCTIONSELECT);
writeData(0x01); // internal (diode drop)
//writeData(0x01); // external bias
// writeCommand(SSSD1351_CMD_SETPHASELENGTH);
// writeData(0x32);
writeCommand(SSD1351_CMD_PRECHARGE); // 0xB1
writeCommand(0x32);
writeCommand(SSD1351_CMD_VCOMH); // 0xBE
writeCommand(0x05);
writeCommand(SSD1351_CMD_NORMALDISPLAY); // 0xA6
writeCommand(SSD1351_CMD_CONTRASTABC);
writeData(0xC8);
writeData(0x80);
writeData(0xC8);
writeCommand(SSD1351_CMD_CONTRASTMASTER);
writeData(0x0F);
writeCommand(SSD1351_CMD_SETVSL );
writeData(0xA0);
writeData(0xB5);
writeData(0x55);
writeCommand(SSD1351_CMD_PRECHARGE2);
writeData(0x01);
writeCommand(SSD1351_CMD_DISPLAYON); //--turn on oled panel
}
void Adafruit_SSD1351::invert(boolean v) {
if (v) {
writeCommand(SSD1351_CMD_INVERTDISPLAY);
} else {
writeCommand(SSD1351_CMD_NORMALDISPLAY);
}
}
The "other tft" screen that works fine has this at the top of the file.
Code:
// If the SPI library has transaction support, these functions
// establish settings and protect from interference from other
// libraries. Otherwise, they simply do nothing.
#ifdef SPI_HAS_TRANSACTION
static inline void spi_begin(void) __attribute__((always_inline));
static inline void spi_begin(void) {
#if defined (ARDUINO_ARCH_ARC32)
// max speed!
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
#else
// max speed!
SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
#endif
}
static inline void spi_end(void) __attribute__((always_inline));
static inline void spi_end(void) {
SPI.endTransaction();
}
#else
#define spi_begin()
#define spi_end()
#endif
And its begin..
Code:
void Adafruit_ILI9341::begin(void) {
if (_rst > 0) {
pinMode(_rst, OUTPUT);
digitalWrite(_rst, LOW);
}
pinMode(_dc, OUTPUT);
pinMode(_cs, OUTPUT);
#if defined (USE_FAST_PINIO)
csport = portOutputRegister(digitalPinToPort(_cs));
cspinmask = digitalPinToBitMask(_cs);
dcport = portOutputRegister(digitalPinToPort(_dc));
dcpinmask = digitalPinToBitMask(_dc);
#endif
if(hwSPI) { // Using hardware SPI
SPI.begin();
#ifndef SPI_HAS_TRANSACTION
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
#if defined (_AVR__)
SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!)
mySPCR = SPCR;
#elif defined(TEENSYDUINO)
SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!)
#elif defined (__arm__)
SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
#endif
#endif
} else {
pinMode(_sclk, OUTPUT);
pinMode(_mosi, OUTPUT);
pinMode(_miso, INPUT);
#if defined (USE_FAST_PINIO)
clkport = portOutputRegister(digitalPinToPort(_sclk));
clkpinmask = digitalPinToBitMask(_sclk);
mosiport = portOutputRegister(digitalPinToPort(_mosi));
mosipinmask = digitalPinToBitMask(_mosi);
*clkport &= ~clkpinmask;
*mosiport &= ~mosipinmask;
#endif
}
// toggle RST low to reset
if (_rst > 0) {
digitalWrite(_rst, HIGH);
delay(5);
digitalWrite(_rst, LOW);
delay(20);
digitalWrite(_rst, HIGH);
delay(150);
}
/*
uint8_t x = readcommand8(ILI9341_RDMODE);
Serial.print("\nDisplay Power Mode: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDMADCTL);
Serial.print("\nMADCTL Mode: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDPIXFMT);
Serial.print("\nPixel Format: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDIMGFMT);
Serial.print("\nImage Format: 0x"); Serial.println(x, HEX);
x = readcommand8(ILI9341_RDSELFDIAG);
Serial.print("\nSelf Diagnostic: 0x"); Serial.println(x, HEX);
*/
//if(cmdList) commandList(cmdList);
if (hwSPI) spi_begin();
writecommand(0xEF);
writedata(0x03);
writedata(0x80);
writedata(0x02);
writecommand(0xCF);
writedata(0x00);
writedata(0XC1);
writedata(0X30);
writecommand(0xED);
writedata(0x64);
writedata(0x03);
writedata(0X12);
writedata(0X81);
writecommand(0xE8);
writedata(0x85);
writedata(0x00);
writedata(0x78);
writecommand(0xCB);
writedata(0x39);
writedata(0x2C);
writedata(0x00);
writedata(0x34);
writedata(0x02);
writecommand(0xF7);
writedata(0x20);
writecommand(0xEA);
writedata(0x00);
writedata(0x00);
writecommand(ILI9341_PWCTR1); //Power control
writedata(0x23); //VRH[5:0]
writecommand(ILI9341_PWCTR2); //Power control
writedata(0x10); //SAP[2:0];BT[3:0]
writecommand(ILI9341_VMCTR1); //VCM control
writedata(0x3e); //¶Ô±È¶Èµ÷½Ú
writedata(0x28);
writecommand(ILI9341_VMCTR2); //VCM control2
writedata(0x86); //--
writecommand(ILI9341_MADCTL); // Memory Access Control
writedata(0x48);
writecommand(ILI9341_PIXFMT);
writedata(0x55);
writecommand(ILI9341_FRMCTR1);
writedata(0x00);
writedata(0x18);
writecommand(ILI9341_DFUNCTR); // Display Function Control
writedata(0x08);
writedata(0x82);
writedata(0x27);
writecommand(0xF2); // 3Gamma Function Disable
writedata(0x00);
writecommand(ILI9341_GAMMASET); //Gamma curve selected
writedata(0x01);
writecommand(ILI9341_GMCTRP1); //Set Gamma
writedata(0x0F);
writedata(0x31);
writedata(0x2B);
writedata(0x0C);
writedata(0x0E);
writedata(0x08);
writedata(0x4E);
writedata(0xF1);
writedata(0x37);
writedata(0x07);
writedata(0x10);
writedata(0x03);
writedata(0x0E);
writedata(0x09);
writedata(0x00);
writecommand(ILI9341_GMCTRN1); //Set Gamma
writedata(0x00);
writedata(0x0E);
writedata(0x14);
writedata(0x03);
writedata(0x11);
writedata(0x07);
writedata(0x31);
writedata(0xC1);
writedata(0x48);
writedata(0x08);
writedata(0x0F);
writedata(0x0C);
writedata(0x31);
writedata(0x36);
writedata(0x0F);
writecommand(ILI9341_SLPOUT); //Exit Sleep
if (hwSPI) spi_end();
delay(120);
if (hwSPI) spi_begin();
writecommand(ILI9341_DISPON); //Display on
if (hwSPI) spi_end();
}
Thanks for looking at this. I really appreciate it!
-jim lee
Last edited: