Don't like ads? Help support the Mercs by becoming a Supporter or Auxiliary Member today!
Official Members also get to use the forum ad-free - so kit up and join us!

 electriFi tutorial: build your own OLED display

  • 64 Replies
  • 5818 Views

Fi-8015


    *
  • *
  • *
  • 2923
  • Awards 40% increase or more Award for 10 official invasions.
Re: electriFi tutorial: build your own OLED display
« Reply #60 on: Oct 05, 2020, 07:56 AM »
And do also please add a photo of your wiring.

Logged
Helmets for Sale in the Trading Station

electriFi - Mando Electronics English / German
Re: electriFi tutorial: build your own OLED display
« Reply #61 on: Oct 05, 2020, 11:27 PM »
Okay so I ran the address finder on a screen I know works, so I ran it on the smaller 1306 and it found this address.

Then I tried with the same setup on the 1106 one and got this.

Then, I was  moving the board around and the wires a bit and it actually found an address briefly, but I could not get it to do it again. And I did try using that 0x01 as the address, and still nothing.


I'm thinking to solder the wires on, what do you guys think?
Also, here's my current code.

{code}
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>

#include <Adafruit_SH1106.h>
#include <splash.h>

#include <Adafruit_GFX.h>




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


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

//I2C
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);


//software SPI:
//#define OLED_CLK    8       //SCL
//#define OLED_MOSI  9        //SDA
//#define OLED_RESET 10       //RES
//#define OLED_DC    11       //DC
//#define OLED_CS    12       //CS
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);


int xs = 64;  //x für Start
int ys = 32;  //y für Start
int xe = 64;  //x für Ende
int ye = 31;  //y für Ende

int xs1 = 64;  //x für Start
int ys1 = 32;  //y für Start
int xe1 = 64;  //x für Ende
int ye1 = 31;  //y für Ende

int xs2 = 64;  //x für Start
int ys2 = 32;  //y für Start
int xe2 = 64;  //x für Ende
int ye2 = 31;  //y für Ende

int xs3 = 64;  //x für Start
int ys3 = 32;  //y für Start
int xe3 = 64;  //x für Ende
int ye3 = 31;  //y für Ende

int i = 0;

int counter = 0;
int counter1 = 0;
int counter2 = 0;

int targetCounter = 0;
int flickerCounter= 0;

void setup() {
  Serial.begin(9600);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
  display.clearDisplay();

  display.drawRoundRect(0, 0, 128, 64, 6, WHITE);
  display.drawPixel(64,32, WHITE);
  display.drawPixel(63,32, WHITE);
  display.drawPixel(64,31, WHITE);
  display.drawPixel(63,31, WHITE);

  //4 Pixel in der Mitte: x=63, 64  und y = 31, 32

  display.display();

  delay(500);
 
  display.drawLine(33, 1, 94, 62, WHITE);
  display.drawLine(94, 1, 33, 62, WHITE);
 
  display.display();
  delay(500);

  display.drawLine(17, 1, 110, 62, WHITE);
  display.drawLine(110, 1, 17, 62, WHITE);
 
  display.display();
  delay(500);

  display.drawLine(1, 15, 126, 48, WHITE);
  display.drawLine(1, 48, 126, 15, WHITE);
 

  display.display();

  delay(1000);

}

void loop() {

if (targetCounter < 4)
{
while(i<64)
{
  if(i == 16)
  {
    counter = 1;
  }

  if(i == 15)
  {
    counter = 0;
  }

  if(i == 32)
  {
    counter1 = 1;
  }

  if(i == 31)
  {
    counter1 = 0;
  }
 
  if(i == 48)
  {
    counter2 = 1;
  }

  if(i == 47)
  {
    counter2 = 0;
  }
  display.drawLine(xs-1, ys-1, xs-1, ye+1, BLACK);
  display.drawLine(127-xs+1, ys-1, 127-xs+1, ye+1, BLACK);
  display.drawLine(xs-1, ys-1, 127-xs+1, ys-1, BLACK);

  display.drawLine(xs1-1, ys1-1, xs1-1, ye1+1, BLACK);
  display.drawLine(127-xs1+1, ys1-1, 127-xs1+1, ye1+1, BLACK);
  display.drawLine(xs1-1, ys1-1, 127-xs1+1, ys1-1, BLACK);

  display.drawLine(xs2-1, ys2-1, xs2-1, ye2+1, BLACK);
  display.drawLine(127-xs2+1, ys2-1, 127-xs2+1, ye2+1, BLACK);
  display.drawLine(xs2-1, ys2-1, 127-xs2+1, ys2-1, BLACK);

  display.drawLine(xs3-1, ys3-1, xs3-1, ye3+1, BLACK);
  display.drawLine(127-xs3+1, ys3-1, 127-xs3+1, ye3+1, BLACK);
  display.drawLine(xs3-1, ys3-1, 127-xs3+1, ys3-1, BLACK);
 
  if(counter == 1)
  {
    display.drawLine(xs1, ys1, xs1, ye1, WHITE);
    display.drawLine(127-xs1, ys1, 127-xs1, ye1, WHITE);
    display.drawLine(xs1, ys1, 127-xs1, ys1, WHITE);
  }

  if(counter1 == 1)
  {
    display.drawLine(xs2, ys2, xs2, ye2, WHITE);
    display.drawLine(127-xs2, ys2, 127-xs2, ye2, WHITE);
    display.drawLine(xs2, ys2, 127-xs2, ys2, WHITE);
  }

  if(counter2 == 1)
  {
    display.drawLine(xs3, ys3, xs3, ye3, WHITE);
    display.drawLine(127-xs3, ys3, 127-xs3, ye3, WHITE);
    display.drawLine(xs3, ys3, 127-xs3, ys3, WHITE);
  }
 
  if(counter == 0)
  {
    ye1 = 31;
    xe1 = 64;
    ys1 = 32;
    xs1 = 64;
  }

  if(counter1 == 0)
  {
    ye2 = 31;
    xe2 = 64;
    ys2 = 32;
    xs2 = 64;
  }

  if(counter2 == 0)
  {
    ye3 = 31;
    xe3 = 64;
    ys3 = 32;
    xs3 = 64;
  }

  display.drawRoundRect(0, 0, 128, 64, 6, WHITE);
  display.drawLine(33, 1, 94, 62, WHITE);
  display.drawLine(94, 1, 33, 62, WHITE);
 
 
  display.drawLine(17, 1, 110, 62, WHITE);
  display.drawLine(110, 1, 17, 62, WHITE);
 
  display.drawLine(1, 15, 126, 48, WHITE);
  display.drawLine(1, 48, 126, 15, WHITE);


  display.drawLine(xs, ys, xs, ye, WHITE);
  display.drawLine(127-xs, ys, 127-xs, ye, WHITE);
  display.drawLine(xs, ys, 127-xs, ys, WHITE);

  display.fillTriangle(0, 0, 0, 3, 3, 0, BLACK); //Ecken übermalen
  display.fillTriangle(0, 63, 0, 60, 3, 63, BLACK);
  display.fillTriangle(127, 0, 124, 0, 127, 3, BLACK);
  display.fillTriangle(127, 63, 127, 60, 124, 63, BLACK);
 
  display.display();

 
   

   xs ++;
   xe --;
   ys ++;
   ye --;
   i ++;

   if(counter == 1)
   {
   xs1 ++;
   xe1 --;
   ys1 ++;
   ye1 --;
   }

   if(counter1 == 1)
   {
   xs2 ++;
   xe2 --;
   ys2 ++;
   ye2 --;
   }

   if(counter2 == 1)
   {
   xs3 ++;
   xe3 --;
   ys3 ++;
   ye3 --;
   }
}
i = 0;
ye = 31;
xe = 64;
ys = 32;
xs = 64;

targetCounter ++;
}

if (targetCounter == 4)
{
  if(flickerCounter < 24)
  {
display.fillRect(49,17, 30, 30, BLACK);
display.drawLine(48,15, 80, 15, WHITE);
display.drawRoundRect(53, 21, 22,22, 11, WHITE);

display.drawLine(49, 31, 78, 31, WHITE);
display.drawLine(49, 32, 78, 32, WHITE);

display.drawLine(63, 16, 63, 46, WHITE);
display.drawLine(64, 16, 64, 46, WHITE);

display.display();
delay(100);

display.drawLine(49, 31, 78, 31, BLACK);
display.drawLine(49, 32, 78, 32, BLACK);

display.drawLine(63, 16, 63, 46, BLACK);
display.drawLine(64, 16, 64, 46, BLACK);
display.drawRoundRect(53, 21, 22,22, 11, WHITE);
display.display();
delay(100);
flickerCounter ++;
  }

  if(flickerCounter == 24)
  {
    targetCounter = 0;
    flickerCounter = 0;

    display.drawRoundRect(53, 21, 22,22, 11, BLACK);
    display.drawLine(48,15, 80, 15, BLACK);     
  }
}
}
{/code}

EDIT: 10/8/2020
I received in a new display with the 1306 drivers, but I'm confused on where to wire it to the OLED.
https://www.adafruit.com/product/938
I got the example code to work, but the targeting computer does not work. Here is code that works.
Does anyone know what is going on? Btw the pins that work are A4 to DATA, and A5 to C1k.
{code}
/**************************************************************************
 This is an example for our Monochrome OLEDs based on SSD1306 drivers
 Pick one up today in the adafruit shop!
 ------> http://www.adafruit.com/category/63_98
 This example is for a 128x64 pixel display using I2C to communicate
 3 pins are required to interface (two I2C and one reset).
 Adafruit invests time and resources providing this open
 source code, please support Adafruit and open-source
 hardware by purchasing products from Adafruit!
 Written by Limor Fried/Ladyada for Adafruit Industries,
 with contributions from the open source community.
 BSD license, check license.txt for more information
 All text above, and the splash screen below must be
 included in any redistribution.
 **************************************************************************/

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

#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)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

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

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

  // 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

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  testdrawline();      // Draw many lines

  testdrawrect();      // Draw rectangles (outlines)

  testfillrect();      // Draw rectangles (filled)

  testdrawcircle();    // Draw circles (outlines)

  testfillcircle();    // Draw circles (filled)

  testdrawroundrect(); // Draw rounded rectangles (outlines)

  testfillroundrect(); // Draw rounded rectangles (filled)

  testdrawtriangle();  // Draw triangles (outlines)

  testfilltriangle();  // Draw triangles (filled)

  testdrawchar();      // Draw characters of the default font

  testdrawstyles();    // Draw 'stylized' characters

  testscrolltext();    // Draw scrolling text

  testdrawbitmap();    // Draw a small bitmap image

  // Invert and restore display, pausing in-between
  display.invertDisplay(true);
  delay(1000);
  display.invertDisplay(false);
  delay(1000);

  testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
}

void loop() {
}

void testdrawline() {
  int16_t i;

  display.clearDisplay(); // Clear display buffer

  for(i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, SSD1306_WHITE);
    display.display(); // Update screen with each newly-drawn line
    delay(1);
  }
  for(i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, SSD1306_WHITE);
    display.display();
    delay(1);
  }

  delay(2000); // Pause for 2 seconds
}

void testdrawrect(void) {
  display.clearDisplay();

  for(int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, SSD1306_WHITE);
    display.display(); // Update screen with each newly-drawn rectangle
    delay(1);
  }

  delay(2000);
}

void testfillrect(void) {
  display.clearDisplay();

  for(int16_t i=0; i<display.height()/2; i+=3) {
    // The INVERSE color is used so rectangles alternate white/black
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, SSD1306_INVERSE);
    display.display(); // Update screen with each newly-drawn rectangle
    delay(1);
  }

  delay(2000);
}

void testdrawcircle(void) {
  display.clearDisplay();

  for(int16_t i=0; i<max(display.width(),display.height())/2; i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }

  delay(2000);
}

void testfillcircle(void) {
  display.clearDisplay();

  for(int16_t i=max(display.width(),display.height())/2; i>0; i-=3) {
    // The INVERSE color is used so circles alternate white/black
    display.fillCircle(display.width() / 2, display.height() / 2, i, SSD1306_INVERSE);
    display.display(); // Update screen with each newly-drawn circle
    delay(1);
  }

  delay(2000);
}

void testdrawroundrect(void) {
  display.clearDisplay();

  for(int16_t i=0; i<display.height()/2-2; i+=2) {
    display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i,
      display.height()/4, SSD1306_WHITE);
    display.display();
    delay(1);
  }

  delay(2000);
}

void testfillroundrect(void) {
  display.clearDisplay();

  for(int16_t i=0; i<display.height()/2-2; i+=2) {
    // The INVERSE color is used so round-rects alternate white/black
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i,
      display.height()/4, SSD1306_INVERSE);
    display.display();
    delay(1);
  }

  delay(2000);
}

void testdrawtriangle(void) {
  display.clearDisplay();

  for(int16_t i=0; i<max(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(
      display.width()/2  , display.height()/2-i,
      display.width()/2-i, display.height()/2+i,
      display.width()/2+i, display.height()/2+i, SSD1306_WHITE);
    display.display();
    delay(1);
  }

  delay(2000);
}

void testfilltriangle(void) {
  display.clearDisplay();

  for(int16_t i=max(display.width(),display.height())/2; i>0; i-=5) {
    // The INVERSE color is used so triangles alternate white/black
    display.fillTriangle(
      display.width()/2  , display.height()/2-i,
      display.width()/2-i, display.height()/2+i,
      display.width()/2+i, display.height()/2+i, SSD1306_INVERSE);
    display.display();
    delay(1);
  }

  delay(2000);
}

void testdrawchar(void) {
  display.clearDisplay();

  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.setCursor(0, 0);     // Start at top-left corner
  display.cp437(true);         // Use full 256 char 'Code Page 437' font

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  for(int16_t i=0; i<256; i++) {
    if(i == '\n') display.write(' ');
    else          display.write(i);
  }

  display.display();
  delay(2000);
}

void testdrawstyles(void) {
  display.clearDisplay();

  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0,0);             // Start at top-left corner
  display.println(F("Hello, world!"));

  display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
  display.println(3.141592);

  display.setTextSize(2);             // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.print(F("0x")); display.println(0xDEADBEEF, HEX);

  display.display();
  delay(2000);
}

void testscrolltext(void) {
  display.clearDisplay();

  display.setTextSize(2); // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10, 0);
  display.println(F("scroll"));
  display.display();      // Show initial text
  delay(100);

  // Scroll in various directions, pausing in-between:
  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrolldiagright(0x00, 0x07);
  delay(2000);
  display.startscrolldiagleft(0x00, 0x07);
  delay(2000);
  display.stopscroll();
  delay(1000);
}

void testdrawbitmap(void) {
  display.clearDisplay();

  display.drawBitmap(
    (display.width()  - LOGO_WIDTH ) / 2,
    (display.height() - LOGO_HEIGHT) / 2,
    logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
  display.display();
  delay(1000);
}

#define XPOS   0 // Indexes into the 'icons' array in function below
#define YPOS   1
#define DELTAY 2

void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  int8_t f, icons[NUMFLAKES][3];

  // Initialize 'snowflake' positions
  for(f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
    icons[f][YPOS]   = -LOGO_HEIGHT;
    icons[f][DELTAY] = random(1, 6);
    Serial.print(F("x: "));
    Serial.print(icons[f][XPOS], DEC);
    Serial.print(F(" y: "));
    Serial.print(icons[f][YPOS], DEC);
    Serial.print(F(" dy: "));
    Serial.println(icons[f][DELTAY], DEC);
  }

  for(;;) { // Loop forever...
    display.clearDisplay(); // Clear the display buffer

    // Draw each snowflake:
    for(f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SSD1306_WHITE);
    }

    display.display(); // Show the display buffer on the screen
    delay(200);        // Pause for 1/10 second

    // Then update coordinates of each flake...
    for(f=0; f< NUMFLAKES; f++) {
      icons[f][YPOS] += icons[f][DELTAY];
      // If snowflake is off the bottom of the screen...
      if (icons[f][YPOS] >= display.height()) {
        // Reinitialize to a random position, just off the top
        icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
        icons[f][YPOS]   = -LOGO_HEIGHT;
        icons[f][DELTAY] = random(1, 6);
      }
    }
  }
}
{/code}

EDIT: 10/09/2020
I GOT IT!
Let me just say thank you guys so much for your help, I couldn't have done it without both of you.
So the address on this Adafruit 1.3in SSD1306 OLED is 0x3D. So that address finder did the trick! Now it works with the standard I2C code!
Thank you guys so much.  :like: ;D

« Last Edit: Oct 09, 2020, 11:09 PM by mikehall419 » Logged

LightningLion


    *
  • 159
  • Electronics are my thing
Re: electriFi tutorial: build your own OLED display
« Reply #62 on: Oct 13, 2020, 01:29 PM »
But did you get the 1106 to work?

Logged
Lion's electronics corner

Rionu Custom Electronics for your Mandos
--->> Sales thread

WIPs: Nite Owl helmet. Modern era helmet.

Mundo Airsofter - Airsoft news & reviews
Re: electriFi tutorial: build your own OLED display
« Reply #63 on: Oct 13, 2020, 03:25 PM »
Still no, it is possible the screen is broken. The address finder can’t really seem to find it.

Logged
Re: electriFi tutorial: build your own OLED display
« Reply #64 on: Nov 27, 2020, 10:37 AM »
Hello...I needed to feature the text style tone to understand it.

I understand that little OLED shows are utilized in some PDAs, PDAs, camcorders, and so on, however I comprehend that lifetime for the blue organics is pretty short (~1000 hrs). I think OLED presentations would create a definitive TV or screen on the off chance that they can beat that issue and the significant expense of production.

Logged
 


Don't like ads? Help support the Mercs by becoming a Supporter or Auxiliary Member today!
Official Members also get to use the forum ad-free - so kit up and join us!




Powered by EzPortal
anything