I'm making something on a Pro Micro and decided to include a small 128x64 display in the project. I tested the display on the Uno first, and using the Adafruit_SSD1306 and Wire libraries, everything worked fine. So I decided to move it to the pro micro, however I have an issue. The default pins for SDA and SCL are D2 and D3 (according to this: https://www.arduino.cc/reference/en/language/functions/communication/wire/)

The problem is, all my digital pins are taken. In fact, the only two available pins I have left are A2 and A3 (there is no way for me to free the others, since there are multiplexers there). And since the display used analog pins on the Uno, I figured it should work on the Pro micro if I just use the SoftWire Library, however it doesn't seem to be working and I have no idea what the issue is. Here's my code:

SoftWire wire(A2,A3);

Adafruit_SSD1306 display(128, 64, &wire);

void setup() {
  Serial.begin(9600);
  wire.begin();

  if (!display.begin()) {
    Serial.println("Display init failed.");
    while(true) {}
  }

  Serial.println("Display init successful");
}

This compiles for me, but nothing is ever displayed on the Serial monitor. Also I'm really new to all that, so if I'm trying to do something really stupid please let me know. Thanks.

1

There are 1 best solutions below

0
tuyau2poil On

I suggest starting with an I2C bus scan to check the basic connections and operation. Avoid using the name 'Wire' to separate things well. start with this sketch (from https://github.com/stevemarple/SoftWire/tree/master) and gives us result :

#include <SoftWire.h>
#include <AsyncDelay.h>

SoftWire sw(A2, A3);


void setup(void)
{
#if F_CPU >= 12000000UL
  Serial.begin(115200);
#else
  Serial.begin(9600);
#endif

  sw.setTimeout_ms(40);
  sw.begin();

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  // Set how long we are willing to wait for a device to respond
  sw.setTimeout_ms(200);

  const uint8_t firstAddr = 1;
  const uint8_t lastAddr = 0x7F;
  Serial.println();
  Serial.print("Interrogating all addresses in range 0x");
  Serial.print(firstAddr, HEX);
  Serial.print(" - 0x");
  Serial.print(lastAddr, HEX);
  Serial.println(" (inclusive) ...");

  for (uint8_t addr = firstAddr; addr <= lastAddr; addr++) {
    digitalWrite(LED_BUILTIN, HIGH);
    delayMicroseconds(50);

    uint8_t startResult = sw.llStart((addr << 1) + 1); // Signal a read
    sw.stop();

    if (startResult == 0) {
      Serial.print("\rDevice found at 0x");
      Serial.println(addr, HEX);
      Serial.flush();
    }
    digitalWrite(LED_BUILTIN, LOW);

    delay(50);
  }
  Serial.println("Finished");

}


void loop(void)
{
  ;
}

note1 : it seems asyncdelay library is mandatory : don't forget to install it.

note2 : ensure softWire is last version.