MCP45HVX1 Digital POT and SH1106 OLED Display both on I2C

Hello,

I am having a problem using an MCP45HVX1 digital pot and a common SH1106 OLED display together on the same bus.

Using an Arduino; If I talk to the display, sometimes the POT will glitch, and if I talk to the POT, the screen gets messed up.

Below is a simple sketch which should slowly turn up the pot resistance value, and display the value on the OLED display.

#include <Arduino.h>

#include <U8g2lib.h>

#include <Wire.h>



U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0,  U8X8_PIN_NONE);

int value = 0;

char displayStr[25];    // Text output buffer



void setup(void) {

  u8g2.begin();

  u8g2.clearBuffer();

  u8g2.setFont(u8g2_font_5x8_tf);

 

  Wire.begin();

  pinMode(42, OUTPUT);

  digitalWrite(42, HIGH); // Connect Wiper

}



void loop(void) {



  sprintf(displayStr, " Value %i ", value);

  u8g2.drawStr(0, 8, displayStr); // Display Text: X(pixels[0-127]), Y(lines[0-7)

  u8g2.sendBuffer();          // transfer internal memory to the display



  delay(100);



  Wire.beginTransmission(0x3C); // transmit to POT_ADDRESS

  delayMicroseconds(10);

  Wire.write(0x00);           // Select wiper register

  delayMicroseconds(10);

  Wire.write(value);          // sends POT value bytes

  delayMicroseconds(10);

  Wire.endTransmission();         // stop transmitting

  value++;

  delay(100); 

}

As it is, the screen shows the incrementing number up until about 60 when it starts bouncing around and eventually becomes just a line and goes blank. THe POT resistance remains at the minimum apart from a few small glitches.

If i comment out the just POT related code, I get the same result.

If i comment out the just Screen related code, the pot resistance changes just fine, but occasionally the display will go all white, or staart flashing.

Apart from physically disconnecting one device from the bus while the other is written, Is there a way to have these two items working together on the same bus?

It's probably because they both are using the same address (default for the SH1106 is usually 0x3C as well). you would need to change one of them (I would suggest the pot since you are not using a lib with that one! :wink: ). from MCP45HVX1 datasheet:

"The state of the A0 and A1 pins should be static, that isthey should be tied High or tied Low."

Untitled.png

so for the address, 0x3C, you used for your pot assumes that 'A0' and 'A1' are held LOW.

Untitled.png

The display is at 0x78, so must be some other reason.