Adafruit SSD1306 Display & Data Logger Shield

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tomked
 
Posts: 4
Joined: Sun Sep 04, 2022 4:46 pm

Adafruit SSD1306 Display & Data Logger Shield

Post by tomked »

Cannot get these devices to co-exist on Arduino Uno R3.

Both work fine individually with the example sketches.

When the SD card setup is included in the sketch using the SSD1306 the SSD1306 display allocation fails.

Thanks for any help...

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit SSD1306 Display & Data Logger Shield

Post by dastels »

Please post your code that tries to use both. My first thought is that the UNO may not have enough RAM to support both.

Dave

User avatar
tomked
 
Posts: 4
Joined: Sun Sep 04, 2022 4:46 pm

Re: Adafruit SSD1306 Display & Data Logger Shield

Post by tomked »

Here is is:

Code: Select all

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

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
  0b00000001, 0b11000000,
  0b00000001, 0b11000000,
  0b00000011, 0b11100000,
  0b11110011, 0b11100000,
  0b11111110, 0b11111000,
  0b01111110, 0b11111111,
  0b00110011, 0b10011111,
  0b00011111, 0b11111100,
  0b00001101, 0b01110000,
  0b00011011, 0b10100000,
  0b00111111, 0b11100000,
  0b00111111, 0b11110000,
  0b01111100, 0b11110000,
  0b01110000, 0b01110000,
  0b00000000, 0b00110000 };

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));  // always displayed
    for(;;); // Don't proceed, loop forever
  }

  Serial.println("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(SS, OUTPUT);
  
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    display.clearDisplay();
    loadMsg(14, 12, 2, "Failed to");
    loadMsg(6, 30, 2, "initialize");
    loadMsg(28, 48, 2, "SD card");
    display.display();
    Serial.println("SD card initialization failed");
    while (1);
  }
  else {
    Serial.println("SD card initialization OK");
  }

  // show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen
  display.display();
  delay(2000); // pause for 2 seconds
} // setup

void loop() {
} // loop()

void loadMsg(int x, int y, int textSize, String msg) {
  display.setTextSize(textSize);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(x, y);
  display.print(msg);
}

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit SSD1306 Display & Data Logger Shield

Post by dastels »

The only time display.begin() will return false if it can't allocate the display buffer (in RAM) which means it's out of memory. It's all just too much for the ATmega328P to handle as it only has 2K. My guess is that the GFX library takes up quite a bit. It looks like you'll need a more powerful (roomy) MCU to do what you want.

If you want to keep the same physical format https://www.adafruit.com/product/3505 is a good choice. For a few $ more you can get https://www.adafruit.com/product/3382 which is significantly more capable. Either will be a direct physical swap. Some coding tweaks may be required, but only if you're using fairly processor specific things (generally unlikely) And newer boards use 3.3v logic rather than 5v. Adafruit addon boards tend to work with both... you just power it with the appropriate voltage: 5v for the '328 on the UNO or 3.3v for a board with, in this case, the SAMD21 (aka M0) or SAMD51 (aka M4).

Dave

User avatar
tomked
 
Posts: 4
Joined: Sun Sep 04, 2022 4:46 pm

Re: Adafruit SSD1306 Display & Data Logger Shield

Post by tomked »

I must stick with 5V as I use a relay with this requirement.

Also, any board I use must be pin-compatible with the Uno R3 since I use a Grove shield in addtion to the Data Logger Shield.

Thanks...

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit SSD1306 Display & Data Logger Shield

Post by dastels »

You can use a level shifter or transistor to drive the relay, that isn't a problem. What could be a problem is if the grove and data logger shield aren't 3.3v compatible.

Dave

User avatar
tomked
 
Posts: 4
Joined: Sun Sep 04, 2022 4:46 pm

Re: Adafruit SSD1306 Display & Data Logger Shield

Post by tomked »

I switched over to a MKR WiFi 1010 to provide more memory space as I was running low on the Uno.

I pulled out a cable that has a Grove compatible connector on one end and 4 male pins on the other and connected it to the Grove relay. Three of the male pins I connected as follows:
- Power lead to 5V supply on the MKR WiFi 1010
- GND to MKR GND
- Signal to MKR D3 (in my case)
Setting D3 to HIGH in my sketch activates the relay with no problem.

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

Return to “Arduino”