Pin 4 being pulled high by SSD1306 library?

andnate

Member
I'm trying to use an encoder knob on pins 4 and 5, as well as an I2C OLED on pins 18 and 19. If I have the display in the code, pin 4 is pulled high and overpowers the 10k series resistor I have going to the signal from the knob. What causes this? Is it possible to fix this behavior? What other pins might be affected by this that I haven't ran into yet?

Below is code that demonstrates the issue, cobbled together from example files and the project where I found this.

C-like:
#include "QuadEncoder.h"
#include <Wire.h>

// Supported pins:  0, 1, 2, 3, 4, 5, 7, 8, 30, 31, 33, 36, 37
#define KNOB_CLK 4
#define KNOB_DT 5

#define KNOB_PULLUPS 0  // Onboard knob PCB, don't need
#define KNOB_PPR 20

// Display
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define W 6
#define H 8
#define SCREEN_WIDTH 128     // OLED display width, in pixels
#define SCREEN_HEIGHT 64     // OLED display height, in pixels
#define OLED_RESET 4         // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define I2C_SDA 18  // Teensy 4.1
#define I2C_SCL 19  // Teensy 4.1

QuadEncoder knob(2, KNOB_CLK, KNOB_DT, KNOB_PULLUPS);
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;  // CAN1

void setup() {
  Serial.begin(115200);
  // Setup display
  Wire.setSDA(I2C_SDA);  // Teensy 4.1
  Wire.setSCL(I2C_SCL);  // Teensy 4.1
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }
  display.ssd1306_command(SSD1306_SETCONTRAST);  // 0x81
  display.ssd1306_command(0x01);
  display.clearDisplay();
  display.setTextSize(0);               // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);  // Draw white text with black backgroud - changes a character
  display.cp437(true);                  // Use real 256 char 'Code Page 437' font
  display.setTextWrap(false);
  display.setTextSize(2);
  display.setCursor(0, 0);
  display.print("Loading...");
  display.display();

  Serial.println("Knob Encoder Test:");
  Wire.setSDA(18);  // Teensy 4.1
  Wire.setSCL(19);  // Teensy 4.1
  Wire.begin();

  knob.setInitConfig();
  //Optional filter setup
  knob.EncConfig.filterCount = 5;
  knob.EncConfig.filterSamplePeriod = 255;
  knob.init();
}

long position = -999;

void loop() {
  long newPos;
  newPos = knob.read();
  if (newPos != position) {
    Serial.print("Knob = ");
    Serial.print(newPos);
    Serial.println();
    position = newPos;
  }
  // if a character is sent from the serial monitor,
  // reset both back to zero.
  if (Serial.available()) {
    Serial.read();
    Serial.println("Reset knob to zero");
    knob.write(0);
  }
}
 
C-like:
#define OLED_RESET 4         // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
You are telling the display library that pin 4 is the display's reset signal.
 
You are telling the display library that pin 4 is the display's reset signal.
haha I just finally noticed that and came back here to clear that. That took me entirely too long to find. I've been copying that block of code across projects without really looking at it I guess!
 
Back
Top