I am attempting use an Ethernet shield (Rev3, W5500), with an I2C display, using the Adafruit_SSD1306 library.
I call the display.begin() from from the Adafruit_SSD1306 library as the first line in my setup() function. However, if I call Ethernet.begin() anywhere else in setup (I'm calling it several lines later), the display.begin() call fails and returns false, and the display does not function.
Simply commenting out Ethernet.begin() will cause display.begin() to work correctly.
Has anyone else encountered this, and have any solutions?
Here is my test sketch:
#include <Adafruit_SSD1306.h>
#include <Ethernet.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_ADDR 0x3C // OLED display TWI address
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
bool displayEnabled = false;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
void setup() {
// initialize and clear display
displayEnabled = display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
Serial.begin(9600);
Serial.print("Display enabled? : ");
Serial.println(boolToString(displayEnabled));
display.clearDisplay();
display.display();
Ethernet.begin(mac);
// display a line of text
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("Hello, world!");
// update display with all of the above graphics
display.display();
}
char* boolToString(bool val) {
return val ? "true" : "false";
}
void loop() {
}