7Pin OLED Interfacing/Arbitrary Code Help

I wanted to kick things off by getting into PCB design by following someone's schematic and code. I guess I messed up by trusting the person that the code was correct and the most efficient way of doing things below I'll include the code and display+wiring diagram.

Display:
Amazon

Wiring Diagram:


open in new tap for higher res.
Code:

#include "U8glib.h"  //Library for display 
#define MOSFET_Pin 2
#define Bat_Pin A0
#define Res_Pin A1

U8GLIB_SH1106_128X64 u8g();  // I2C interface for OLED  
float Capacity = 0.0; 
float Res_Value = 5.0;  
float Vcc = 4.410; //Measure it and change  
float Current = 0.0; 
float mA=0;         
float Bat_Volt = 0.0;  
float Res_Volt = 0.0;  
unsigned long previousMillis = 0; 
unsigned long millisPassed = 0;  
float sample1 =0.000;
float sample2= 0.000;
int x = 0;
int row = 0;

void draw(void) {
   u8g.setFont(u8g_font_fub14r); 
   if ( Bat_Volt < 1){
    u8g.setPrintPos(10,40);      
    u8g.println("No Battrey"); 
   }
   else if ( Bat_Volt > 4.3){
    u8g.setPrintPos(3,40);       
    u8g.println("High Voltage"); 
   }
   else if(Bat_Volt < 2.9){
    u8g.setPrintPos(3,40);      
    u8g.println("Low Voltage"); 
   }
   else if(Bat_Volt >= 2.9 && Bat_Volt < 4.3  ){
      
   u8g.drawStr(0, 20, "V: ");  
   u8g.drawStr(0, 40, "I: ");
   u8g.drawStr(0, 60, "mAh: ");
   u8g.setPrintPos(58,20);       
   u8g.print( Bat_Volt,2);  
   u8g.println("V"); 
   u8g.setPrintPos(58,40);        
   u8g.print( mA,0);  
   u8g.println("mA"); 
   u8g.setPrintPos(58, 60);       
   u8g.print( Capacity ,1);    
  
}
}
  void buz()
  {
  digitalWrite(9, HIGH);
  delay(100);          
  digitalWrite(9, LOW);  
  delay(10);            

}   
  void setup() {
   buz();
   Serial.begin(9600);
   pinMode(A2,INPUT_PULLUP);
   pinMode(A3, INPUT_PULLUP);
   pinMode(MOSFET_Pin, OUTPUT);
   pinMode(9, OUTPUT);
   digitalWrite(MOSFET_Pin, LOW); 
  }
  
  void loop() {
  
  for(int i=0;i< 100;i++)
  {
   sample1=sample1+analogRead(Bat_Pin);
   delay (2);
  }
  sample1=sample1/100; 
  Bat_Volt = 2* sample1 *Vcc/ 1024.0; 

   for(int i=0;i< 100;i++)
  {
   sample2=sample2+analogRead(Res_Pin); 
   delay (2);
  }
  sample2=sample2/100;
  Res_Volt = 2* sample2 * Vcc/ 1024.0;
  
  if ( Bat_Volt > 4.3){
    digitalWrite(MOSFET_Pin, LOW); 
    buz();
    Serial.println( "Warning High-V! ");
    delay(1000);
   }
   
   else if(Bat_Volt < 2.9){
      digitalWrite(MOSFET_Pin, LOW);
      buz();
      Serial.println( "Warning Low-V! ");
      delay(1000);
  }
  else if(Bat_Volt > 2.9 && Bat_Volt < 4.3  ) { 
      digitalWrite(MOSFET_Pin, HIGH);
      millisPassed = millis() - previousMillis;
      Current = (Bat_Volt - Res_Volt) / Res_Value;
      mA = Current * 1000.0 ;
      Capacity = Capacity + mA * (millisPassed / 3600000.0);
      previousMillis = millis();
      row++;
      x++;
      delay(100); 
 
     }

  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
 }

PCB Printed by JCL follows the same schematic above. I ran this code on an "Arduino pro micro" Arduino mini knockoff. Therefore, the pinout might be different from the pro mini. The OLED stays dark and nothing is written to the screen. All I get in my serial is "Warning Low-V!" and I'm not sure how to diagnose this further as this is my first project including a display. I appreciate and help I am given! Let me know if you need anything else to help diagnose this.

Your link says 0.96 SSD1306 but your constructor says SH1106.

You should use U8g2lib instead of U8glib nowadays.

Regarding SPI or I2C. SPI is faster but it makes little difference for a 128x64 display.
If you want to use I2C, you can configure your 7-pin display for I2C
But it is a lot easier to just buy a 4-pin I2C SSD1306 in the first place.

The schematic is no good for a Pro_Micro anyway.
I strongly advise you to start with a known Arduino board e.g. Pro_Micro and an I2C SSD1306

Get your product working on breadboard or Protoboard before thinking about a pcb.
Copy an existing commercial board pcb design. Never copy a random pcb found on the Internet.

Yes, it does matter which controller chip and which interface.
Always post a link to the actual display that you have bought. e.g. Amazon sale page

David.

david_prentice:
Your link says 0.96 SSD1306 but your constructor says SH1106.

You should use U8g2lib instead of U8glib nowadays.

Regarding SPI or I2C. SPI is faster but it makes little difference for a 128x64 display.
If you want to use I2C, you can configure your 7-pin display for I2C
But it is a lot easier to just buy a 4-pin I2C SSD1306 in the first place.

The schematic is no good for a Pro_Micro anyway.
I strongly advise you to start with a known Arduino board e.g. Pro_Micro and an I2C SSD1306

Get your product working on breadboard or Protoboard before thinking about a pcb.
Copy an existing commercial board pcb design. Never copy a random pcb found on the Internet.

Yes, it does matter which controller chip and which interface.
Always post a link to the actual display that you have bought. e.g. Amazon sale page

David.

I did buy an SSD1306, the Amazon link is for the OLED I bought. As for the Arduino here's a link to the board I purchased. Is there any way, with the current schematic I have, to modify the code make this work?

Hi Gmanc2,
The Amazon OLED is 5V compatible, they say.
Applying Occam's Razor I suggest to first concentrate entirely to get the OLED running, and once that has happened, add the instructions to let the goodies dance.

U8glib.h requires some effort from the programmer.
Here is a sample 'bare' SSD1306 OLED sketch for the 7-pin display:

// OLED_128x64_nano_bare.ino

// for use with SSD1306 Monochrome OLEDs
// essential fragments found on Henry's Bench - 
// sketch by Photoncatcher
// august 13, 2019
// public domain

// libraries
   #include "U8glib.h"

// pins on the Arduino 
   #define OLED_SCK  13   
   #define OLED_MOSI 11
   #define OLED_CS   10    
   #define OLED_DC    9  
   #define OLED_RES   8 
   int j = 0;

// U8glib constructor OLED display
  U8GLIB_SSD1306_128X64 u8g(OLED_SCK, OLED_MOSI, OLED_CS, OLED_DC, OLED_RES);


void draw(void) {

// led control
   digitalWrite (3, HIGH); 
   delay (500);  
   digitalWrite (3, LOW); 
  
// yellow rings in upper strip
  for (j=28; j<109;j= j+10){
   u8g.drawCircle( j,7,7);
  }

// smiley
  u8g.drawCircle(110, 50, 12);       // contour
  u8g.drawDisc  (105, 50, 2);        // eye
  u8g.drawDisc  (115, 50, 2);        // eye
  u8g.drawLine  (106, 56, 108, 56);  // mouth
  u8g.drawLine  (113, 56, 115, 56);  // mouth
  u8g.drawLine  (107, 57, 114, 57);  // mouth
  u8g.drawPixel (105, 55);           // mouth  
  u8g.drawPixel (116, 55);           // mouth  
 
//text 
  u8g.setFont (u8g_font_unifont);    // select font
  u8g.drawStr (0, 55, "Hello World"); 
  }


void setup(void) {  
   pinMode (3, OUTPUT);
   u8g.setFont(u8g_font_unifont);
   u8g.setColorIndex(1); // Instructs the display to draw with a pixel on. 0 = OFF, 1 = ON
}

void loop(void) {  
    u8g.firstPage ();
    do {  
      draw ();
       } while( u8g.nextPage() );
    delay (500);   
}

Success, Photoncatcher

photoncatcher:
Hi Gmanc2,
The Amazon OLED is 5V compatible, they say.
Applying Occam's Razor I suggest to first concentrate entirely to get the OLED running, and once that has happened, add the instructions to let the goodies dance.

U8glib.h requires some effort from the programmer.
Here is a sample 'bare' SSD1306 OLED sketch for the 7-pin display:

// OLED_128x64_nano_bare.ino

// for use with SSD1306 Monochrome OLEDs
// essential fragments found on Henry's Bench -
// sketch by Photoncatcher
// august 13, 2019
// public domain

// libraries
  #include "U8glib.h"

// pins on the Arduino
  #define OLED_SCK  13  
  #define OLED_MOSI 11
  #define OLED_CS   10    
  #define OLED_DC    9  
  #define OLED_RES   8
  int j = 0;

// U8glib constructor OLED display
 U8GLIB_SSD1306_128X64 u8g(OLED_SCK, OLED_MOSI, OLED_CS, OLED_DC, OLED_RES);

void draw(void) {

// led control
  digitalWrite (3, HIGH);
  delay (500);  
  digitalWrite (3, LOW);
 
// yellow rings in upper strip
 for (j=28; j<109;j= j+10){
  u8g.drawCircle( j,7,7);
 }

// smiley
 u8g.drawCircle(110, 50, 12);       // contour
 u8g.drawDisc  (105, 50, 2);        // eye
 u8g.drawDisc  (115, 50, 2);        // eye
 u8g.drawLine  (106, 56, 108, 56);  // mouth
 u8g.drawLine  (113, 56, 115, 56);  // mouth
 u8g.drawLine  (107, 57, 114, 57);  // mouth
 u8g.drawPixel (105, 55);           // mouth  
 u8g.drawPixel (116, 55);           // mouth

//text
 u8g.setFont (u8g_font_unifont);    // select font
 u8g.drawStr (0, 55, "Hello World");
 }

void setup(void) {  
  pinMode (3, OUTPUT);
  u8g.setFont(u8g_font_unifont);
  u8g.setColorIndex(1); // Instructs the display to draw with a pixel on. 0 = OFF, 1 = ON
}

void loop(void) {  
   u8g.firstPage ();
   do {  
     draw ();
      } while( u8g.nextPage() );
   delay (500);  
}




Success, Photoncatcher

Thank you for this, I was able to create a working breadboard layout for what you listed above! I don't know why I found this information so hard to find but I appreciate your effort to help! Smooth sailing from here :slight_smile: