Go Down

Topic: [Solved]OLED display hat for pi connection with arduino (Read 470 times) previous topic - next topic

casual_controller

Sep 10, 2020, 08:12 am Last Edit: Sep 24, 2020, 04:54 pm by casual_controller
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?


PaulRB

#2
Sep 10, 2020, 08:42 am Last Edit: Sep 10, 2020, 08:44 am by PaulRB
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.

casual_controller

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

PaulRB

the sketch is the: ssd1306_128x64_i2c
Your display has sh1106 controller, not ssd1306.

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.

casual_controller

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.

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,?

casual_controller

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

PaulRB

#8
Sep 10, 2020, 01:41 pm Last Edit: Sep 10, 2020, 01:43 pm by 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.

PaulRB

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

casual_controller

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.

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 :(
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.

Code: [Select]
// --------------------------------------
// 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)





casual_controller

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

Code: [Select]
void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}

PaulRB

#12
Sep 11, 2020, 08:49 am Last Edit: Sep 11, 2020, 08:51 am by PaulRB
Quote
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.

PaulRB

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

casual_controller

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


Go Up