The OLED shown just half bitmap

Hi,
I am testing a code from:
Build a Smart Watch by Interfacing OLED Display with Android Phone using Arduino
The graphics shown just half, why?
Thanks
Adam

#include<SoftwareSerial.h>
SoftwareSerial Serial1(10, 11);

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

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
String str = "";
byte h = 0;
byte m = 0;
byte S = 0;
String dmy, time, network, battery, inNumber, s;
byte centerX = 24;
byte centerY = 39;
byte Radius = 24;

double RAD = 3.141592 / 180;
double LR = 89.99;

void showTimeAnalog(int center_x, int center_y, double pl1, double pl2, double pl3)
{
  double x1, x2, y1, y2;
  x1 = center_x + (Radius * pl1) * cos((6 * pl3 + LR) * RAD);
  y1 = center_y + (Radius * pl1) * sin((6 * pl3 + LR) * RAD);
  x2 = center_x + (Radius * pl2) * cos((6 * pl3 - LR) * RAD);
  y2 = center_y + (Radius * pl2) * sin((6 * pl3 - LR) * RAD);
  display.drawLine((int)x1, (int)y1, (int)x2, (int)y2, WHITE);
}

void digitalClock()
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(60, 20);
  display.println(dmy);
  display.setTextSize(2);
  display.setCursor(60, 30);
  display.println(time);
  display.display();
  delay(2000);
}

void Battery()
{
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(20, 0); //// was(20,0)
  display.print("Bat:");
  display.print(battery);
  display.print("%");
  display.drawRect(14, 20, 80, 40, WHITE); //// display.drawRect(14, 20, 80, 40, WHITE);
  display.drawRect(94, 30, 10, 20, WHITE);
  display.fillRect(14, 20, (int)(8 * (battery.toInt()) / 10), 40, WHITE);
  display.display();
  delay(2000);
}

void Network()
{
  display.clearDisplay();
  display.drawLine(5, 15, 25, 15, WHITE);
  display.drawLine(5, 15, 14, 30, WHITE);
  display.drawLine(25, 15, 17, 30, WHITE);
  display.fillRect(14, 15, 4, 40, WHITE);
  int net = network.toInt() / 20;
  int x1 = 24, y1 = 50, x2 = 4, y2 = 5;
  for (int i = 1; i <= net; i++)
  {
    display.fillRect(x1, y1, x2, y2, WHITE);
    x1 += 10;
    y1 -= 5;
    y2 += 10;
    y2 -= 5;
  }
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(80, 34);
  display.print(network);
  display.setTextSize(1);
  display.setCursor(117, 44);
  display.println("%");
  display.display();
  delay(2000);
}

void setup()
{
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.clearDisplay();
  Serial1.begin(9600);
  Serial1.println("System Ready");
}

void loop(){
  Serial1.println("1234");
  delay(1000);
  while (Serial1.available() > 0){
    char ch = Serial1.read();
    str += ch;
    if (ch == '$'){
      dmy = str.substring(str.indexOf("#") + 1, str.indexOf(" "));
      time = str.substring(str.indexOf(" ") + 1, str.indexOf(",") - 3);
      network = str.substring(str.indexOf(",") + 1, str.indexOf(",,"));
      battery = str.substring(str.indexOf(",,") + 2, str.indexOf(",,,"));
      inNumber = str.substring(str.indexOf(",,,") + 3, str.indexOf("$"));
      s = time.substring(time.indexOf(" ") + 1, time.indexOf(" ") + 3);
      h = s.toInt();
      s = time.substring(time.indexOf(" ") + 4, time.indexOf(" ") + 6);
      m = s.toInt();
      s = time.substring(time.indexOf(" ") + 7, time.indexOf(" ") + 9);
      S = s.toInt();
      str = "";}
  }
  display.clearDisplay();
  display.drawCircle(centerX, centerY, Radius, WHITE);
  showTimeAnalog(centerX, centerY, 0.1, 0.5, h * 5 + (int)(m * 5 / 60));
  showTimeAnalog(centerX, centerY, 0.1, 0.78, m);
  // showTimePin(centerX, centerY, 0.1, 0.9, S);
  digitalClock();
  delay(2000);
  Battery();
  delay(2000);
  Network();
  delay(2000);
}

pp11.PNG

The display is probably different dimensions from the one in the instructions. Do you think you have exactly the display they are using?

Typically you can say more about the attached display, here’s the constructor from an example in the library you using:

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

which allows overrides to the default settings, which settings are wrong for you display.

a7

1 Like

Height and width both =16? That doesn't sound right. Find the specs for this particular display.

1 Like

Thanks.
I am using ssd1306 12864 0.96inch Oled.
What else to check?

I got nothing, other than to observe this is a deprecated constructor.

I suggest you find the simplest example program that pretends to mate with this display and get it to work, it can be a slog but I think it will come down to using a modern constructor with the correct parameters.

You may have to run through a few examples, ultimately you may have to get it working in the demo tiny sketch, then figure out how to,modify the real program if necessary, naturally hoping to not need to make wholesale changes.

Once you have the correct library and constructor settings, Keep. Track. Of. Them.

Someone I know has some displays that he got working once, but didn't, and is not gonna go through all that again. :wink:

a7

1 Like

Thank you.
I guess the example from SSD1306 for 128*64 is no good.
Its OK now.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.