Oled 0.96 with pulse sensor fails to display properly

I started following this tutorial here:

which uses a pulse sensor, buzzer and a 0.96" oled display and SSD1306 drivers. Except their display is different. Im using this one:
SSD1306 based OLED connected to Arduino · jandelgado/arduino Wiki · GitHub.

I tried this sample sketch from that SSD1306 site: arduino/ssd1306_sample_adafruit.ino at master · jandelgado/arduino · GitHub

but I only get half of the message on the screen as seen in the image below.

When I upload my final code I get some garbled pixels as seen in the other image below.

Is it a library issue?

This is my code:

//added by me
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>

#define OLED_MOSI  11   //D1
#define OLED_CLK   12   //D0
#define OLED_DC    9
#define OLED_CS    8
#define OLED_RESET 10
//end

#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C // 0x3C device address of I2C OLED. Few other OLED has 0x3D
//Adafruit_SSD1306 oled(128, 64); // create our screen object setting resolution to 128x64

//added from (https://github.com/jandelgado/arduino/blob/master/ssd1306_sample_adafruit/ssd1306_sample_adafruit.ino)by me
Adafruit_SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
//

int a=0;
int lasta=0;
int lastb=0;
int LastTime=0;
int ThisTime;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 560
#define LowerThreshold 530

void setup() {
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  oled.clearDisplay();
  oled.setTextSize(2);
}

void loop(){
  if(a>127) {
    oled.clearDisplay();
    a=0;
    lasta=a;
  }

  ThisTime=millis();
  int value=analogRead(0);
  oled.setTextColor(WHITE);
  int b=60-(value/16);
  oled.writeLine(lasta,lastb,a,b,WHITE);
  lastb=b;
  lasta=a;

  if(value>UpperThreshold) {
    if(BeatComplete) {
      BPM=ThisTime-LastTime;
      BPM=int(60/(float(BPM)/1000));
      BPMTiming=false;
      BeatComplete=false;
      tone(8,1000,250);
      }
  if(BPMTiming==false)
  {
  LastTime=millis();
  BPMTiming=true;
  }
  }
  if((value<LowerThreshold)&(BPMTiming))
  BeatComplete=true;
  
  oled.writeFillRect(0,50,128,16,BLACK);
  oled.setCursor(0,50);
  oled.print("BPM:");
  oled.print(BPM);
  
  oled.display();
  a++;
}

ok i just made a change to the ssd1306 library. I had changed the parameter to #define SSD1306_96_16 but I changed it back to the original #define SSD1306_128_64 and it got way better. I do get the right screen now, somtimes. After a few touches it goes crazy:

you shoudt reset it in the loop cycle and display all again at the sensor catch althrou it sams like a power problem is there a 470uF in the circuit to get the signals stable

Do you mean using:

oled.clearDisplay();

Ill try the 470 uF cap and post back.

Thanks

hallo,
please can you explain your program i need it for my university project test on friday
please explain me theprogram (void loop …) and give me your whatsapp number to connect with you please

int a=0;
int lasta=0;
int lastb=0;
int LastTime=0;
int ThisTime;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 560
#define LowerThreshold 530

void setup() {
oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
oled.clearDisplay();
oled.setTextSize(2);
}

void loop()
{
if(a>127)
{
oled.clearDisplay();
a=0;
lasta=a;
}

ThisTime=millis();
int value=analogRead(0);
oled.setTextColor(WHITE);
int b=60-(value/16);
oled.writeLine(lasta,lastb,a,b,WHITE);
lastb=b;
lasta=a;

if(value>UpperThreshold)
{
if(BeatComplete)
{
BPM=ThisTime-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
tone(8,1000,250);
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
}
if((value<LowerThreshold)&(BPMTiming))
BeatComplete=true;

oled.writeFillRect(0,50,128,16,BLACK);
oled.setCursor(0,50);
oled.print(“BPM:”);
oled.print(BPM);

oled.display();
a++;
}