Adafruit is open and shipping! Let's build back better, together!
0

Help with SSD1306 128x64 OLED
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Help with SSD1306 128x64 OLED

by Arduino714 on Thu Nov 05, 2020 5:45 pm

Hello, I have integrated both the SSD1306 and HTS221 demo sketches over i2C and able to display the data on the OLED display. When I use the sketch with my CPX, the OLED displays both sensor outputs as expected.

However, when I use my Arduino board to run the exact same sketch, I get gibberish pixels at the lower right hand corner of the display. See attached photo IMG_1075 from the CPX and IMG_1077 from my Arduino.

[img]
IMG_1075.jpg
[/img]
[img]
IMG_1077.jpg
[/img]

This is my code

Code: Select all | TOGGLE FULL SIZE
// Example of displaying HTS221 sensor data on SSD1306 OLED display
// integrating the adafruit_hts221 and adafruit_ssd1306 demo sketches

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

Adafruit_HTS221 hts;
Adafruit_Sensor *hts_humidity, *hts_temp;

#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);


void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);

while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit HTS221 test!");

  if (!hts.begin_I2C()) {
    Serial.println("Failed to find HTS221 chip");
    while (1) {
      delay(10);
    }
  }

  Serial.println("HTS221 Found!");
  hts_temp = hts.getTemperatureSensor();
  hts_temp->printSensorDetails();

  hts_humidity = hts.getHumiditySensor();
  hts_humidity->printSensorDetails();

  // 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();
  display.display();

}

void loop() {
  // put your main code here, to run repeatedly:

  //  /* Get a new normalized sensor event */
  sensors_event_t humidity;
  sensors_event_t temp;
  hts_humidity->getEvent(&humidity);
  hts_temp->getEvent(&temp);

  Serial.print("\t\tTemperature ");
  Serial.print(temp.temperature);
  Serial.println(" deg C");

  /* Display the results (humidity is measured in % relative humidity (% rH) */
  Serial.print("\t\tHumidity: ");Serial.print(humidity.relative_humidity);Serial.println(" % rH");
  Serial.print("\t\tTemperature: ");Serial.print(temp.temperature);Serial.println(" degrees C");


  delay(100);

  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("Temperature:"));
  display.setTextSize(2);              // Draw 2X-scale text
  display.println(temp.temperature);
  display.setCursor(50,8);
  display.println("  *C");

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

  display.setTextSize(1);             // Draw 1X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,30);
  display.println(F("Humidity:"));
  display.setTextSize(2);
  display.println(humidity.relative_humidity);
  display.setCursor(50,38);
  display.println("  %");

  display.display();
  delay(5000);
}


Any idea why the extra pixels are showing up with the Arduino hardware and not the CPX? And how to prevent the extra pixels from displaying.

Thanks
Attachments
IMG_1077.jpg
IMG_1077.jpg (201.26 KiB) Viewed 162 times
IMG_1075.jpg
IMG_1075.jpg (263.53 KiB) Viewed 162 times

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by adafruit_support_carter on Thu Nov 05, 2020 8:13 pm

Do you get the same thing running the example from the library?
https://github.com/adafruit/Adafruit_SS ... 64_i2c.ino

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with SSD1306 128x64 OLED

by Arduino714 on Thu Nov 05, 2020 8:40 pm

Hi, the SSD1306 128x64 i2c.ino example from the library runs without any display problems on both my CPX and Arduino.

Just to clarify, I wrote my new sketch using the CPX as the test platform. When the same code was uploaded to my Arduino, the extra pixels appeared.

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by adafruit_support_carter on Mon Nov 09, 2020 1:11 pm

So same code (your code) running on CPX does not have the extra pixels? What is the other Arduino board?

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with SSD1306 128x64 OLED

by Arduino714 on Tue Nov 10, 2020 12:04 am

Hi, I am using the Sparkfun Redboard.

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by adafruit_support_carter on Tue Nov 10, 2020 12:30 pm

OK. That's essentially an Arduino UNO, so should be fine.

Try running this and see if you get the same general behavior:
Code: Select all | TOGGLE FULL SIZE
#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);

float temperature = 22.86;
float humidity = 46.51;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Test!");

  // 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();
  display.display();
}

void loop() {
  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("Temperature:"));
  display.setTextSize(2);              // Draw 2X-scale text
  display.println(temperature);
  display.setCursor(50,8);
  display.println("  *C");

  display.setTextSize(1);             // Draw 1X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,30);
  display.println(F("Humidity:"));
  display.setTextSize(2);
  display.println(humidity);
  display.setCursor(50,38);
  display.println("  %");

  display.display();
  delay(5000);
}

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with SSD1306 128x64 OLED

by Arduino714 on Tue Nov 10, 2020 11:25 pm

Running the sketch on the Red Board cleaned up the extra pixels.
IMG_1124.jpg
IMG_1124.jpg (151.31 KiB) Viewed 119 times

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by Arduino714 on Thu Nov 12, 2020 10:45 pm

Extra pixels still showing up on the right lower corner running my original sketch.

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by adafruit_support_carter on Fri Nov 13, 2020 1:36 pm

OK, now try this sketch:
Code: Select all | TOGGLE FULL SIZE
    // Example of displaying HTS221 sensor data on SSD1306 OLED display
    // integrating the adafruit_hts221 and adafruit_ssd1306 demo sketches

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

    Adafruit_HTS221 hts;
    Adafruit_Sensor *hts_humidity, *hts_temp;

    #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);


    void setup() {
      // put your setup code here, to run once:
    Serial.begin(115200);

    while (!Serial)
        delay(10); // will pause Zero, Leonardo, etc until serial console opens

      Serial.println("Adafruit HTS221 test!");

      if (!hts.begin_I2C()) {
        Serial.println("Failed to find HTS221 chip");
        while (1) {
          delay(10);
        }
      }

      Serial.println("HTS221 Found!");
      hts_temp = hts.getTemperatureSensor();
      hts_temp->printSensorDetails();

      hts_humidity = hts.getHumiditySensor();
      hts_humidity->printSensorDetails();

      // 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();
      display.display();

    }

    void loop() {
      // put your main code here, to run repeatedly:

      //  /* Get a new normalized sensor event */
      sensors_event_t humidity;
      sensors_event_t temp;
      hts_humidity->getEvent(&humidity);
      hts_temp->getEvent(&temp);

      Serial.print("\t\tTemperature ");
      Serial.print(temp.temperature);
      Serial.println(" deg C");

      /* Display the results (humidity is measured in % relative humidity (% rH) */
      Serial.print("\t\tHumidity: ");Serial.print(humidity.relative_humidity);Serial.println(" % rH");
      Serial.print("\t\tTemperature: ");Serial.print(temp.temperature);Serial.println(" degrees C");


      delay(100);

      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("Temperature:"));
      display.setTextSize(2);              // Draw 2X-scale text
      display.println(temperature);
      display.setCursor(50,8);
      display.println("  *C");

      display.setTextSize(1);             // Draw 1X-scale text
      display.setTextColor(SSD1306_WHITE);
      display.setCursor(0,30);
      display.println(F("Humidity:"));
      display.setTextSize(2);
      display.println(humidity);
      display.setCursor(50,38);
      display.println("  %");

      display.display();
      delay(5000);
    }

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with SSD1306 128x64 OLED

by Arduino714 on Fri Nov 13, 2020 10:06 pm

Hi, I uploaded the new sketch that you provide and modified the variables on lines 88 and 97--due to variables not declared

Code: Select all | TOGGLE FULL SIZE
    // Example of displaying HTS221 sensor data on SSD1306 OLED display
    // integrating the adafruit_hts221 and adafruit_ssd1306 demo sketches

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

    Adafruit_HTS221 hts;
    Adafruit_Sensor *hts_humidity, *hts_temp;

    #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);


    void setup() {
      // put your setup code here, to run once:
    Serial.begin(115200);

    while (!Serial)
        delay(10); // will pause Zero, Leonardo, etc until serial console opens

      Serial.println("Adafruit HTS221 test!");

      if (!hts.begin_I2C()) {
        Serial.println("Failed to find HTS221 chip");
        while (1) {
          delay(10);
        }
      }

      Serial.println("HTS221 Found!");
      hts_temp = hts.getTemperatureSensor();
      hts_temp->printSensorDetails();

      hts_humidity = hts.getHumiditySensor();
      hts_humidity->printSensorDetails();

      // 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();
      display.display();

    }

    void loop() {
      // put your main code here, to run repeatedly:

      //  /* Get a new normalized sensor event */
      sensors_event_t humidity;
      sensors_event_t temp;
      hts_humidity->getEvent(&humidity);
      hts_temp->getEvent(&temp);

      Serial.print("\t\tTemperature ");
      Serial.print(temp.temperature);
      Serial.println(" deg C");

      /* Display the results (humidity is measured in % relative humidity (% rH) */
      Serial.print("\t\tHumidity: ");Serial.print(humidity.relative_humidity);Serial.println(" % rH");
      Serial.print("\t\tTemperature: ");Serial.print(temp.temperature);Serial.println(" degrees C");


      delay(100);

      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("Temperature:"));
      display.setTextSize(2);              // Draw 2X-scale text
      display.println(temp.temperature);     //*this line was modified as the variable was not declared
      display.setCursor(50,8);
      display.println("  *C");

      display.setTextSize(1);             // Draw 1X-scale text
      display.setTextColor(SSD1306_WHITE);
      display.setCursor(0,30);
      display.println(F("Humidity:"));
      display.setTextSize(2);
      display.println(humidity.relative_humidity);    //*this line was modified as the variable was not declared
      display.setCursor(50,38);
      display.println("  %");

      display.display();
      delay(5000);
    }


The extra pixels are still appearing at the lower right corner of the OLED display.
IMG_1129.jpg
IMG_1129.jpg (118.06 KiB) Viewed 83 times

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by adafruit_support_carter on Sat Nov 14, 2020 12:10 pm

Oops. Sorry. I was mashing up two sketches and looks like I missed some lines. I've re-worked it. Please try this one:
Code: Select all | TOGGLE FULL SIZE
// Example of displaying HTS221 sensor data on SSD1306 OLED display
// integrating the adafruit_hts221 and adafruit_ssd1306 demo sketches

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

Adafruit_HTS221 hts;
Adafruit_Sensor *hts_humidity, *hts_temp;

#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);


float TEMPERATURE = 22.86;
float HUMIDITY = 46.51;

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);

while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit HTS221 test!");

  if (!hts.begin_I2C()) {
    Serial.println("Failed to find HTS221 chip");
    while (1) {
      delay(10);
    }
  }

  Serial.println("HTS221 Found!");
  hts_temp = hts.getTemperatureSensor();
  hts_temp->printSensorDetails();

  hts_humidity = hts.getHumiditySensor();
  hts_humidity->printSensorDetails();

  // 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();
  display.display();

}

void loop() {
  // put your main code here, to run repeatedly:

  //  /* Get a new normalized sensor event */
  sensors_event_t humidity;
  sensors_event_t temp;
  hts_humidity->getEvent(&humidity);
  hts_temp->getEvent(&temp);

  Serial.print("\t\tTemperature ");
  Serial.print(temp.temperature);
  Serial.println(" deg C");

  /* Display the results (humidity is measured in % relative humidity (% rH) */
  Serial.print("\t\tHumidity: ");Serial.print(humidity.relative_humidity);Serial.println(" % rH");
  Serial.print("\t\tTemperature: ");Serial.print(temp.temperature);Serial.println(" degrees C");


  delay(100);

  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("Temperature:"));
  display.setTextSize(2);              // Draw 2X-scale text
  display.println(TEMPERATURE);
  display.setCursor(50,8);
  display.println("  *C");

  display.setTextSize(1);             // Draw 1X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,30);
  display.println(F("Humidity:"));
  display.setTextSize(2);
  display.println(HUMIDITY);
  display.setCursor(50,38);
  display.println("  %");

  display.display();
  delay(5000);
}

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with SSD1306 128x64 OLED

by Arduino714 on Mon Nov 16, 2020 11:12 pm

No problem! Thanks for troubleshooting this with me.

The extra pixels have reappeared with this version of the sketch.
IMG_1150.jpg
IMG_1150.jpg (109.98 KiB) Viewed 57 times

Arduino714
 
Posts: 14
Joined: Mon Jul 27, 2020 9:34 am

Re: Help with SSD1306 128x64 OLED

by adafruit_support_carter on Tue Nov 17, 2020 1:44 pm

Weird. So it's something related to the sensor readings. That sketch writes static information to the display, same as the sketch that works. The only addition is the readings of the sensors, which aren't used for anything.

Hmm...Will need to look into this a little further.

adafruit_support_carter
 
Posts: 17777
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.