32u4 Adalogger not working with 128x64 OLED

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ddodd
 
Posts: 18
Joined: Wed Jan 12, 2022 9:07 pm

32u4 Adalogger not working with 128x64 OLED

Post by ddodd »

I have the OLED (Product ID: 4650) stacked on top of the 32u4 Adalogger (Product ID: 2795). The ReadWrite example works fine. The display sample code also runs without a problem (https://learn.adafruit.com/adafruit-128 ... duino-code). They don't work together. The code either hangs at sd.open() or at display.begin(), depending on which code you put first. Everything compiles and uploads fine, but the stack hangs and doesn't even print everything to the serial port.
I'll post the code below. Thank you for your help.

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <SD.h>

File myFile;

Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

// OLED FeatherWing buttons map to different pins depending on board:
#if defined(ESP8266)
  #define BUTTON_A  0
  #define BUTTON_B 16
  #define BUTTON_C  2
#elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
#elif defined(ARDUINO_STM32_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
#elif defined(TEENSYDUINO)
  #define BUTTON_A  4
  #define BUTTON_B  3
  #define BUTTON_C  8
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
#else // 32u4, M0, M4, nrf52840, esp32-s2 and 328p
  #define BUTTON_A  9
  #define BUTTON_B  6
  #define BUTTON_C  5
#endif

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  Serial.println("128x64 OLED FeatherWing test");
  display.begin(0x3C, true); // Address 0x3C default

  Serial.println("OLED begun");

  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(1000);

  // Clear the buffer.
  display.clearDisplay();
  display.display();

  display.setRotation(1);
  Serial.println("Button test");

  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);

  // text display tests
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0,0);
  display.print("Connecting to SSID\n'adafruit':");
  display.print("connected!");
  display.println("IP: 10.0.1.23");
  display.println("Sending val #0");
  display.display(); // actually display all of the above
}

void loop() {
  if(!digitalRead(BUTTON_A)) display.print("A");
  if(!digitalRead(BUTTON_B)) display.print("B");
  if(!digitalRead(BUTTON_C)) display.print("C");
  delay(10);
  yield();
  display.display();
}
Last edited by adafruit_support_bill on Mon Jan 17, 2022 12:18 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: 32u4 Adalogger not working with 128x64 OLED

Post by adafruit_support_bill »

Most likely, you are running into a memory problem. The OLED display and the SD card both require sizeable chunks of RAM.

See this guide for an explanation - as well as some tips on optimizing memory.
https://learn.adafruit.com/memories-of- ... o-memories

User avatar
ddodd
 
Posts: 18
Joined: Wed Jan 12, 2022 9:07 pm

Re: 32u4 Adalogger not working with 128x64 OLED

Post by ddodd »

Thanks for your quick reply. This is really basic stuff though. If they don't work together out of the box, you figure someone else must have run into it, but I don't see anything. The problem will only get worse as I add code. I've ordered an M0 Adalogger and will try that with the OLED.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: 32u4 Adalogger not working with 128x64 OLED

Post by adafruit_support_bill »

The older Atmega processors like the 328P and the 32U4 don't have a lot of RAM to work with. If you search the forums you will find lots of people running into the same problem. It is especially common when trying to use memory intensive things like displays and SD cards. There is substantial room for optimization in your code that might reclaim enough for you to run. But the M0 has a lot more RAM to work with.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”