Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

16-bit color 1.27" OLED crashes
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

16-bit color 1.27" OLED crashes

by ccshepherd on Tue Oct 06, 2020 12:12 pm

Hi, I bought an 'OLED Breakout Board - 16-bit Color 1.27" w/microSD holder' but the screen glitches and goes blank after a few seconds when running this simple code (running on an Adafruit Feather HUZZAH32 - ESP32):

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
#include <SPI.h>

// Screen dimensions
#define SCREEN_WIDTH  128
#define SCREEN_HEIGHT 96

// Color definitions
#define  BLACK           0x0000
#define WHITE           0xFFFF

//tft pins
#define DC_PIN   27
#define CS_PIN   33
#define RST_PIN  15

Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, RST_PIN);

void setup() {
  Serial.begin(115200);
 
  tft.begin();
  tft.setTextWrap(true);
  tft.setTextColor(WHITE);
}

int count = 0;
void loop() {
  tft.fillScreen(BLACK);

  tft.setCursor(0, 0);
  tft.print("Hello there everyone!\nHow are you?\n\nWhat is your name?");
     
 
  count++;
  Serial.print("Print #");
  Serial.println(count);

  delay(20);
}


If I put a bigger delay at the end of the loop function it fixes it; but I need the small delay (preferably no delay) in a bigger project I'm working on with this screen.
What causes it to crash and how can I fix it?
Attachments
esp32.jpg
Breadboard setup used for the test
esp32.jpg (62.25 KiB) Viewed 113 times

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Re: 16-bit color 1.27" OLED crashes

by ccshepherd on Tue Oct 06, 2020 1:37 pm

This is the function that's causing the problems in my big project:

Code: Select all | TOGGLE FULL SIZE
int drawTextBox(int x, int y, int w, int maxLines, int lineSpacing, const char *text) {
  int lineHeight = 7+lineSpacing;
  int letterWidth = 5;
 
  short int tx = 0;
  short int ty = 0;
  unsigned short int th = 0;
  unsigned short int tw = 0;

  int maxLineChars = w/6;

  int len = strlen(text)+1;
  char curWord[256];
  int drawPosX = 0;
  int drawPosY = 0;
  int wordIdx = 0;
  int curLineX = 0;
  int curNumLines = 0;
  for (int i = 0; i < len; i++) {
    char c = text[i];
    if (c == ' ' || c == '\n' || i == len-1 || wordIdx == maxLineChars) {
      if (curLineX + wordIdx > maxLineChars) {
        drawPosY += lineHeight;
        curLineX = 0;
        drawPosX = 0;
        curNumLines++;

        if (y+drawPosY > SCREEN_HEIGHT || (maxLines != 0 && curNumLines == maxLines)) {
          return drawPosY;
        }
      }
     
      tft.setCursor(x+drawPosX, y+drawPosY);
      tft.print(curWord);
     
      drawPosX += (wordIdx+1) * (letterWidth+1);
      curLineX += wordIdx+1;
      memset(curWord, 0, sizeof curWord);
      wordIdx = 0;

      if (c == '\n') {
        drawPosY += lineHeight;
        curLineX = 0;
        drawPosX = 0;
        curNumLines++;

        if (y+drawPosY > SCREEN_HEIGHT || (maxLines != 0 && curNumLines == maxLines)) {
          return drawPosY;
        }
      }
    } else {
      if (c > 31 && c < 127) { // only ascii
        curWord[wordIdx] = c;
        wordIdx++;
      }
    }
  }

  return drawPosY+lineHeight;
}


Is there a better way of drawing text boxes that would stop the screen from crashing?

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Re: 16-bit color 1.27" OLED crashes

by adafruit_support_carter on Wed Oct 07, 2020 4:32 pm

Just to be sure - the display is working in general? You have no issues running the example from the library?
https://learn.adafruit.com/adafruit-1-5 ... g-and-test

adafruit_support_carter
 
Posts: 17112
Joined: Tue Nov 29, 2016 2:45 pm

Re: 16-bit color 1.27" OLED crashes

by ccshepherd on Thu Oct 08, 2020 2:26 am

adafruit_support_carter wrote:Just to be sure - the display is working in general? You have no issues running the example from the library?
https://learn.adafruit.com/adafruit-1-5 ... g-and-test


Ah, it looks like it works fine with software SPI, but crashes with hardware SPI (I recently switch to hardware SPI and started experiencing issues then) - does running with hardware SPI just require me to change the MOSI and SCK connections to the esp's MOSI (GPIO 18) and SCK (GPIO 5), which is what i did, or do I have to do more?

I detached all the other pins and only had the screen connected to rule out any kind of interference and tested on 2 seperate adafruit huzzah32 feathers. Does this mean the screen is defective?

Thanks,
Chris

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Re: 16-bit color 1.27" OLED crashes

by adafruit_support_carter on Thu Oct 08, 2020 11:38 am

If software SPI is working, then the display is fine. So it's a matter of why hardware SPI is not working. Those seem like the correct pins for hardware SPI.

Since SCK is GPIO 5, you may need to change up the pins in the example sketch:
https://github.com/adafruit/Adafruit-SS ... t/test.ino
since it tries to use 5 for CS.

What pins are you using here?
Code: Select all | TOGGLE FULL SIZE
#define DC_PIN   4
#define CS_PIN   5
#define RST_PIN  6

adafruit_support_carter
 
Posts: 17112
Joined: Tue Nov 29, 2016 2:45 pm

Re: 16-bit color 1.27" OLED crashes

by ccshepherd on Thu Oct 08, 2020 4:04 pm

I'm using the following pins:

Code: Select all | TOGGLE FULL SIZE
#define DC_PIN   27
#define CS_PIN   33
#define RST_PIN  15

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Re: 16-bit color 1.27" OLED crashes

by adafruit_support_carter on Thu Oct 08, 2020 4:21 pm

Yah, that seems fine. Just to make sure - all of your libraries are up to date?

adafruit_support_carter
 
Posts: 17112
Joined: Tue Nov 29, 2016 2:45 pm

Re: 16-bit color 1.27" OLED crashes

by ccshepherd on Thu Oct 08, 2020 5:44 pm

Yeah, I believe so

Arduino IDE @ Version 1.8.13
Adafruit GFX Library @ Version 1.10.1
Adafruit SSD1351 Library @ Version 1.2.5

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Re: 16-bit color 1.27" OLED crashes

by adafruit_support_carter on Thu Oct 08, 2020 5:48 pm

Those look good. Also check Adafruit BusIO.

adafruit_support_carter
 
Posts: 17112
Joined: Tue Nov 29, 2016 2:45 pm

Re: 16-bit color 1.27" OLED crashes

by ccshepherd on Thu Oct 08, 2020 6:06 pm

Yep

Adafruit BusIO @ Version 1.5.0

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Re: 16-bit color 1.27" OLED crashes

by MakerMelissa on Tue Oct 13, 2020 5:45 pm

Hi,

I have wired up the display as you have and run your test code and have the same results, so it's definitely not a hardware issue. I believe the issue is caused by a combination of the ESP32 being fast and this OLED not liking super fast updates. In the library, for the ESP32 the SPI bus is running at 24MHz. I tried slowing it down to 16MHz and that seems to stabilize it and ran it for a few minutes without problems. In regards to it looking glitchy, that my be that your test script is filling the entire screen black and then redrawing text over and over. I'll go ahead and update the library to slow it down for stability purposes as I've noticed problems over 16MHz myself.

Melissa

MakerMelissa
 
Posts: 184
Joined: Wed Jun 05, 2013 2:10 am

Re: 16-bit color 1.27" OLED crashes

by ccshepherd on Wed Oct 14, 2020 6:30 pm

Cool, thanks!
I've switched to an LCD screen for now which is working fine

ccshepherd
 
Posts: 7
Joined: Tue Oct 06, 2020 11:46 am

Please be positive and constructive with your questions and comments.