I am still trying to get two displays to work properly. Steps taken and things learned so far:
Devices:
Particle Photon
0.91 in 128x64 I2C OLED displays (2x)
-
I bought two new displays and, on one, moved the resistor on the back to change its address.
-
I run I2C scanner and see:
I2C device found at address 0x3C !
I2C device found at address 0x3D !
- I am running my sketch on a Particle Photon, which should have enough memory to handle two displays using the Adafruit SSD1306 library.
#include <Adafruit_SSD1306.h>
// LEFT DISPLAY WITH I2C
// Display SDA -> Photon D0
// Display SLC -> Photon D1
#define OLED_RESET_left -1
#define OLED_RESET_right -1
Adafruit_SSD1306 display_left(OLED_RESET_left);
Adafruit_SSD1306 display_right(OLED_RESET_right);
void setup() {
Serial.begin(9600);
//Serial.println("Start setup");
// Start the displays, show a confirmation text.
display_left.begin(SSD1306_SWITCHCAPVCC, 0x3C); // I2C
display_right.begin(SSD1306_SWITCHCAPVCC, 0x3D); // I2C
display_left.clearDisplay();
display_left.setRotation(0);
display_left.setCursor(0, 20);
display_left.setTextSize(2);
display_left.setTextColor(WHITE);
display_left.println("Setup:");
display_left.println("LEFT");
display_left.display();
display_right.clearDisplay();
display_right.setRotation(0);
display_right.setCursor(0, 20);
display_right.setTextSize(2);
display_right.setTextColor(WHITE);
display_right.println("Setup:");
display_right.println("RIGHT");
display_right.display();
delay(2000);
display_left.clearDisplay();
display_left.display();
display_right.clearDisplay();
display_right.display();
}
void loop() {
// -------- LEFT DISPLAY ----------- //
display_left.setCursor(0, 20);
display_left.setTextSize(1);
display_left.setTextColor(WHITE);
display_left.print("Loop: LEFT.");
display_left.display();
// -------- RIGHT DISPLAY ---------- //
display_right.setCursor(0, 30);
display_right.setTextSize(1);
display_right.setTextColor(WHITE);
display_right.print("Loop: RIGHT.");
display_right.display();
}
- When I upload the sketch, the displays correctly show “Setup: LEFT” on the left, and “Setup: RIGHT” on the right. Good.
Setup code running:
- When it gets to the loop, however, both “Loop: LEFT” and “Loop: RIGHT” display on both displays.
Loop code running:
I don’t understand what the difference is - why the code in the Setup works as expected, but the code in the loop doesn’t.
-FWIW, I had been experimenting with different mixes of SPI and I2C, before the newest displays arrived, and had the same problem. Seems like I’m missing / misunderstanding something basic.
Thanks for any help!