Go Down

Topic: Running a 7 pin OLED with 4 pins (I2C) (Read 577 times) previous topic - next topic

nikolakos

I have an OLED with this 7 pin pinout:



I want to use an existing code i found that makes use of U8Glib. But in the example, use uses 4 pins to control the OLED via I2C. This is the pinout he uses:



Is it possible to control my OLED via 4 pins and use U8Glib to simplify my project by making use of the example code i found?

david_prentice

Yes,  you can reconfigure your OLED module for I2C.   The back of the pcb has the necessary information.

But quite honestly,  you might just as well change u8glib constructor from I2C to SPI.   i.e.  one statement.

Code: [Select]

//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC


Depending on the actual OLED that you have,  the early ones could not do an I2C ACK.   Post a photo of your pcb.
So they are far better to use as SPI.

David.

olikraus


nikolakos

David! Thanks a lot!

I prefer to use I2C because of code examples i found. They fit perfectly in my project and i don't want to waste time figuring out how to use displays. Plus I2C works for my project. SPI .. i don't know...

I hadn't seen this information in the back of the PCB! Though i don't understand it. It says 'IIC: R1, R4, R6, R7, R8 '

I don't know what to do to use IIC...  Here is the pic of the back of the pcb


david_prentice

Go on.  You just use the 4SPI setting.   Which is how your display arrived when you opened the box.

use the relevant constructor and everything works.
Likewise with the Adafruit_SSD1306 library.

When you have used the appropriate one line constructor statement, everything works.
Yes that means you have to learn that MOSI is digital#11 on a Uno.

David.

olikraus

One problem (i guess) could be the pin labels. But for this display: D0 is the clock line and D1 is the data line, which is true for SPI and I2C.

Quote
Though i don't understand it. It says 'IIC: R1, R4, R6, R7, R8
it means that the corresponding solder bridges have to be closed.
Actually the SMD resistors should have 0 Ohm values. In your case to change from SPI configuration:
Unsolder R3, Solder R8 and R1
You do not need to use zero ohm resistors, just connect the two pads.

Since soldering is always a little bit critical, I personally would test the OLED with the current SPI configuration first, just to ensure, that id did work before staring with the soldering.

Oliver

nikolakos

#6
Jul 10, 2017, 10:03 am Last Edit: Jul 10, 2017, 10:14 am by nikolakos
Why do i use 4 SPI? R6 and R8 resistors are there too?
Does the info means i wil have to have resistors only at R1,R4,R6,R7,R8 in order to ude IIC?
That means i will have to do SMD desoldering, soldering to use it?

And how do i use it? Besides Vcc, Gnd, this device has 5 pins. Which one is SCL, SDA?

Quote
You do not need to use zero ohm resistors, just connect the two pads.
That means that even wire to the two pads will do the job?

BTW, i am using Arduino DUE.
Also in the code i found, he uses this constructor:

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);

And he connects SCL and SDA to equivalent pins on the DUE (the DUE labels them as SCL and SDA). But what pins of the OLED do i connect to these two pins on my DUE?

david_prentice

#7
Jul 10, 2017, 11:16 am Last Edit: Jul 10, 2017, 11:25 am by david_prentice
Yes  I could tell you which SMD resistors to move.   And how to connect to the Due.

But first off,   I would try all the examples for a SPI OLED.  e.g. from Adafruit_SSD1306 and u8glib.

As I showed in #1,  it is easy to select the constructor and pins for SPI.
You do not need to do any SMD soldering.   You can see exactly what your OLED can do.   You have a comfortable smug feeling when you see that your OLED hardware is working ok.

The default hardware SPI pins for your Due are on the 3x2 header.   You can choose any GPIO pins for CS, DC, RST.
But you can also do everything in software SPI e.g.
Code: [Select]

//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9

As Oliver said in #5.   the DO pin is SCK.   The DI pin is MOSI.   The example constructors don't seem to have a RST argument.  But actually they accept an extra RST argument e.g.
Code: [Select]

//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST  = 8
//i.e. using your pcb markings
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: DO = 13, DI = 11, CS = 10, DC = 9, RST  = 8


Personally,   I find it very confusing when examples omit the RST argument.   
Most Ebay boards have a RST pin.   If you don't control it,  your display does NOT work.
Adafruit boards mostly have a RST pin.   They have an onboard pullup resistor.    So if you do not connect the RST pin it is in a known state.

Adafruit examples are notorious for omitting the RST argument.    But just like u8glib,  Adafruit_SSD1306 accepts the extra RST argument in the constructor.

David.

nikolakos

Hey guys!
I have to rebury this post with an extra question

I want to use hardware SPI.
But my OLED has two pins where i don't know where to connect them.

They are labeled CS and DC.
Maybe one of these go to the pin labeled as SCK on the DUE SPI pins?

david_prentice

Look at Oliver's reply in #5.
DO =  SCK
DI = MOSI
CS = any GPIO pin
DC = any
RST = any

You find SCK,  MOSI on the 3x2.   You can choose ANY other pins for CS, DC, RST.   (except for MISO on the 3x2)

David.

nikolakos

But the constructor for the HW SPI has only two pin declarations:

// HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
U8GLIB_SSD1306_128X64 u8g(10, 9);


So how do i tell it, which are the other pins?

david_prentice

You have 7 pins.   VCC, GND are self explanatory.

DO =  SCK
DI = MOSI
CS = any GPIO pin
DC = any
RST = any

The terms DC, RS, A0 are equivalent names for the same pin.
Note that Adafruit constructors and u8glib constructors all accept an extra RST argument.   
e.g. if you have RST on digital#8
Code: [Select]

// HW SPI Com: CS = 10, A0 = 9, RST = 8 (Hardware Pins are  SCK = 13 and MOSI = 11)
U8GLIB_SSD1306_128X64 u8g(10, 9, 8);


Most Ebay modules do not have pullups on the RST pin.   So you should always use the RST argument.

David.

nikolakos

Thank you sooo much for all the support!

One last thing...
You mentioned this:
Quote
(Hardware Pins are  SCK = 13 and MOSI = 11)
So instead of using the 3X2 SPI pinout, i can just hook it up on 11 and 13?

Thanks a lot!

olikraus

But the constructor for the HW SPI has only two pin declarations:

// HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are  SCK = 13 and MOSI = 11)
U8GLIB_SSD1306_128X64 u8g(10, 9);


So how do i tell it, which are the other pins?
Hardware SPI means, that the library will use the SPI subsystem of your uC. The output of this SPI subsystem (SCK and MOSI) is connected to specific fixed pins. Because these pins are fixed, they do not need to be provided as arguments to the constructor, but of course you need to know the pin numbers for your wiring.

Yet, these pin numbers depend on your Board and uC. An overview is given here: https://www.arduino.cc/en/Reference/SPI

Oliver



nikolakos

Thanks a TON!
But, if the hardware SPI pins are located on the 3X2 ICSP pins, then what is the 3X2 SPI pins used for?

Go Up