[Solved]OLED display hat for pi connection with arduino

I was hoping to use this board with my arduino as it is compact with a screen and buttons, however I am having difficulty getting it to work.
https://www.waveshare.com/wiki/1.3inch_OLED_HAT

I looked at the pi board and found the specific pins for SCL, SDA as the default for the board is I2C and wired those to my arduino along with the different combinations of ground and 3.3V and 5V but the screen would not turn on.

Do I need to connect all the pins on the hat to something? If so how will I know what to connect to which pins?

How to post a link:
https://www.waveshare.com/wiki/1.3inch_OLED_HAT

Without a suitable sketch running on the Arduino, the screen will not turn on. You need to install a library that is compatible with sh1106 oled displays and upload an example sketch that comes with the library to the arduino.

I am using the Adafruit library with and their example sketch to test, mainly using this video as a reference:

OLED Displays with Arduino

Specifically the sketch is the: ssd1306_128x64_i2c

casual_controller:
the sketch is the: ssd1306_128x64_i2c

Your display has sh1106 controller, not ssd1306.

You say you tried 5V and 3.3V. The module seems only to use 3.3V from the pi header. Did you try connecting 5V from the Arduino to the 3.3V pin on the pi header? Do not do that, it could damage the display.

The pi header has several ground connectors. You may need to connect the right one, maybe more than one. Check the schematic on the link you posted.

PaulRB:
Your display has sh1106 controller, not ssd1306.

Thanks for pointing this out
There seems to be some resolution in this thread that I will try look into.

PaulRB:
You say you tried 5V and 3.3V. The module seems only to use 3.3V from the pi header. Did you try connecting 5V from the Arduino to the 3.3V pin on the pi header? Do not do that, it could damage the display.

The pi header has several ground connectors. You may need to connect the right one, maybe more than one. Check the schematic on the link you posted.

I connected the respective Voltages together (3.3->3.3 & 5->5), but only one at a time.
Would you recommend connecting all the relevant voltage pins and all the grounds, from the arduino to the board, at the same time,?

I did find this library for the sh1106 which I will be using going forward. but still nothing displayed on the screen

As I said, reading the schematic, 5V is not used/relevant, only 3.3V. The schematic seems to imply that all 8 ground pins are connected together on the module's pcb, but it's not 100% clear. The GND pins on the pi connector are not shown connected to the ground symbols used elsewhere in the schematic. But I think the fact that they are all labelled "GND" may imply that they are. After all, one of them must be, or the module could not work at all, even with a pi!

Suggest you post one or more photos of the circuit, well lit and focused, so we can see where all connections join. Also post the code you tried. Please read the forum guide so you know how to include those things correctly in your post.

Try running the i2c scanner sketch to check that the display is detected on the i2c bus, and at what address.

PaulRB:
As I said, reading the schematic, 5V is not used/relevant, only 3.3V. The schematic seems to imply that all 8 ground pins are connected together on the module’s pcb, but it’s not 100% clear. The GND pins on the pi connector are not shown connected to the ground symbols used elsewhere in the schematic. But I think the fact that they are all labelled “GND” may imply that they are. After all, one of them must be, or the module could not work at all, even with a pi!

Suggest you post one or more photos of the circuit, well lit and focused, so we can see where all connections join. Also post the code you tried. Please read the forum guide so you know how to include those things correctly in your post.

The grounds are all connected! I tried them with the buttons.

PaulRB:
Try running the i2c scanner sketch to check that the display is detected on the i2c bus, and at what address.

Hmmm there is no device found :frowning:
Is there a way to confirm the code can detect something, by putting something to the i2c ports?

I used the i2c scanner example from the wire class.

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial); // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop() {
  int nDevices = 0;

  Serial.println("Scanning...");

  for (byte address = 1; address < 127; ++address) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address, HEX);
      Serial.println("  !");

      ++nDevices;
    } else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  } else {
    Serial.println("done\n");
  }
  delay(5000); // Wait 5 seconds for next scan
}

Here is the wiring for the hat (2 different 3.3v connections)


This is the library that I originally used to test Adafruit SH1106

I did have to add a function to the cpp file as it was missing

void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}

Is there a way to confirm the code can detect something, by putting something to the i2c ports?

Yes, another i2c device! Perhaps an rtc or sensor for example.

Try adding 2K2 pullup resistors between the i2c lines and 3.3V.

Did you get SDA & SCL the right way around? Try swapping them, it is safe to do that.

I wouldn't trust stranded cables pushed into the sockets to make good connections. I would use solid core cable or male-to-male dupont cables.

Also +1 karma for posting code, pictures and links correctly.

PaulRB:
Yes, another i2c device! Perhaps an rtc or sensor for example.

Try adding 2K2 pullup resistors between the i2c lines and 3.3V.

Did you get SDA & SCL the right way around? Try swapping them, it is safe to do that.

I wouldn’t trust stranded cables pushed into the sockets to make good connections. I would use solid core cable or male-to-male dupont cables.

I do plan on buying some, just holding off incase I have to get a seperate oled. I have tinned the end of the wires though.

I have tried to connect the 2 arduinos together (see pic) unfortunately it still says “no device found”, no matter the combination of mega->nano, nano->mega, mega->hat, nano->hat (all with and without pullup resistors)
So I’m not sure even getting a new oled is going to work at this point either.

Is it worth trying to flash some firmware or something like that (the nano I had to upload with old bootloader selected)

I also found this video that spoke about having issues if the device you are trying to communicate with is not on the same voltage level.
He also mentioned a max cable length of 2m(?) so I did shorten all my cable to try mitigate any issue there

PaulRB:
Also +1 karma for posting code, pictures and links correctly.

Thanks :smiley:

I have tried to connect the 2 arduinos together

That would only work if you uploaded a sketch to the second arduino to make it behave as an i2c slave.

having issues if the device you are trying to communicate with is not on the same voltage level

That could be the problem, yes. You could try connecting the pull-up resistors to 5V, but it could in theory damage the display, so do it at your own risk. Otherwise you could try an i2c level converter module. I've connected similar displays to 5V arduino before with no problem. In think my displays have a regulator built in, so can be powered by 5V, yours may not because it sold for use with pi, which is 3.3V. But I'm pretty sure my modules don't have built-in level converters, and they have always worked fine with 5V arduino and 3.3V arduino.

PaulRB:
That would only work if you uploaded a sketch to the second arduino to make it behave as an i2c slave.That could be the problem, yes.
You could try connecting the pull-up resistors to 5V, but it could in theory damage the display, so do it at your own risk. Otherwise you could try an i2c level converter module. I've connected similar displays to 5V arduino before with no problem. In think my displays have a regulator built in, so can be powered by 5V, yours may not because it sold for use with pi, which is 3.3V. But I'm pretty sure my modules don't have built-in level converters, and they have always worked fine with 5V arduino and 3.3V arduino.

I definitely am going to try the 5V if I can't get it working, but I think step 1 is to get the I2C working? Maybe I'll try it anyway though

Even with the slave sketch on the arduino nano, the mega still doesnt find a device with the i2 scanner. There is also no output from the serial monitor on either the mega or the nano.

casual_controller:
Even with the slave sketch on the arduino nano, the mega still doesnt find a device with the i2 scanner. There is also no output from the serial monitor on either the mega or the nano.

If there is no serial output, how do you know the mega is not finding a device?

UPDATE

I managed to get some more time for this project. I tried a couple more things (not worth mentioning)

I then went back and reread the datasheets and it turns out the default is SPI and not I2C

So after rewiring and using the correct library Adafruit_SH1106 with the display as SPI (from example sketch) everything is working!!!!!

I consider this one solved :smiley: !

Much thanks @PaulRB for the assistance