Go Down

Topic: 2 separate .96 oled displays. (Read 182 times) previous topic - next topic

urthlight

The grandchildren requested a face on one of the robots. i found these displays and thought they would be suitable for eyes. I got some rudimentary code going with one display mirroring the other. When i changed the address I can get one or the other to operate but not both. Looking for direction on how to proceed.
Code: [Select]

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>

#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);


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

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize left  eye
  // display.begin(SH1106_SWITCHCAPVCC, 0x3D);  // initialize right eye

  display.clearDisplay();


  // NOTE: You _must_ call display after making any drawing commands
  // to make them visible on the display hardware!
  display.display();
  delay(2000);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.print("Display");
  display.display();
  delay(50);
  display.setCursor(0, 15);
  display.print("Started");
  display.display();
  delay(1500);
  display.setCursor(0, 30);
  display.print("Init");
  display.display();
  delay(50);
  display.setCursor(0, 45);
  display.print("Finished");
  display.display();

  delay(1500);
  display.clearDisplay();
  display.display();
}

void loop() {

  display.clearDisplay();
  display.display();
  testfillroundrect();
  display.clearDisplay();
  display.display();

  scanlr();


}

void scanlr() {

  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(64, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(62, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(60, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(58, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(56, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(54, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(52, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(50, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(46, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(44, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(42, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(40, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(38, 30, 8, BLACK);
  display.display();
  delay(5);
  display.display();
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(36, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(34, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(32, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(30, 30, 8, BLACK);
  display.display();
  delay(5);



  delay(5);

  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(30, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(32, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(34, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(36, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(38, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(40, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(42, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(44, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(46, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(48, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(50, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(52, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(54, 30, 8, BLACK);
  display.display();
  delay(5);
  display.display();
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(58, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(60, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(62, 30, 8, BLACK);
  display.display();
  delay(5);
  display.fillCircle(display.width() / 2, display.height() / 2, 50, WHITE);
  display.fillCircle(64, 30, 8, BLACK);
  display.display();
  delay(2000);
}


void testfillroundrect(void) {
  uint8_t color = BLACK;
  for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
    display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);
    if (color == BLACK) color = BLACK;
    else color = BLACK;
    display.display();
  }
}


MAS3

#1
Aug 18, 2017, 02:04 am Last Edit: Aug 19, 2017, 01:35 am by MAS3
Hi, and welcome.

I'm not sure (and i really have to go get some sleep).
But isn't this where you tell the library about your display :?

Code: [Select]
 #define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);


So that is the 1st display.
Did you tell the library there are multiple displays ?

Perhaps by doing something along this line:

Code: [Select]

#define OLED_left_RESET 4
Adafruit_SH1106 display0(OLED_left_RESET);
#define OLED_right_RESET 4
Adafruit_SH1106 display1(OLED_right_RESET);



It has to be something like that, after which you can call the correct display to do whatever you like it to do:

Code: [Select]

  display0.display();
  delay(2000);                          // Yikes !
  display0.clearDisplay();
  display0.setTextSize(2);
  display0.setTextColor(WHITE);
  display0.setCursor(0, 0);
  display0.print("Display");
  display0.display();
  delay(50);                              // :(
  display1.clearDisplay();
  display1.setTextSize(2);
  display1.setTextColor(WHITE);
  display1.setCursor(0, 15);
  display1.print("Started");
  display1.display();


You should try to find out how this library works.
I'll be sleeping for the next 3 hours or so, then it's of to work again...
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

MAS3

#2
Aug 19, 2017, 01:30 am Last Edit: Aug 19, 2017, 04:09 pm by MAS3
I just edited my previous post, after reading up on how things are supposed to work while using libraries.


Of course you could also opt for an even more descriptive way of doing this:

Code: [Select]

#define OLED_RESET 4
Adafruit_SH1106 leftEye(OLED_RESET);
#define OLED_RESET 5
Adafruit_SH1106 rightEye(OLED_RESET);


In the rest of your sketch, you call the display by the name you gave it.
So not:

Code: [Select]

 display.clearDisplay();


But:

Code: [Select]

 leftEye.clearDisplay();


This should help you to keep an overview of what's going on, the IDE doesn't give a bit about what name you assign, as long as they are unique.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Go Up