Trouble connecting to SPI display sh1106

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
dakschnitzer
Posts: 5
Joined: Wed Aug 07, 2019 10:52 pm

Trouble connecting to SPI display sh1106

Post by dakschnitzer » Thu Aug 08, 2019 12:58 am

I was able to get external OLED displays working with a Heltec wifi ESP8266 over SPI with SH1106 as follows:

from machine import I2C, Pin, SPI

oled_reset_pin = Pin(16, Pin.OUT)
spi = SPI(1, baudrate=800000)
display = sh1106.SH1106_SPI(128, 64, spi, dc=Pin(0), res=oled_reset_pin, cs=Pin(15))
display2 = sh1106.SH1106_SPI(128, 64, spi, dc=Pin(2), res=oled_reset_pin, cs=Pin(1))


I've been trying to get it work with the Heltec wifi ESP32 and have not been able to figure it out! The pinout diagram is here: https://github.com/dakschnitzer/time-gu ... t%2032.pdf

I have the SPI display connected to the ESP32 as follows, but I get nothing on the display:

CLK -> GPIO18 (SCK / V_SPI_CLK)
MOSI -> GPIO23 (MOSI / V_SPI_D)
RES -> GPIO16 (OLED_RST)
DC -> GPIO26 (no idea where this should go)
CS -> GPIO5 (V_SPI_CSO)


Please let me know if I am doing something wrong here. The code I'm trying to run on the esp32 to goet this to work is:

import sh1106
from machine import I2C, Pin, SPI

oled_reset_pin = Pin(16, Pin.OUT)
oled_reset_pin.value(1)

spi = SPI(1, baudrate=8000000)
display = sh1106.SH1106_SPI(128, 64, spi, dc=Pin(26), res=oled_reset_pin, cs=Pin(5))


I'm using this sh1106 driver: https://github.com/robert-hh/SH1106/blo ... /sh1106.py

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Trouble connecting to SPI display sh1106

Post by jimmo » Thu Aug 08, 2019 11:29 am

dakschnitzer wrote:
Thu Aug 08, 2019 12:58 am
DC -> GPIO26 (no idea where this should go)
Can you clarify what you mean by "(no idea where this should go)"
dakschnitzer wrote:
Thu Aug 08, 2019 12:58 am
I've been trying to get it work with the Heltec wifi ESP32 and have not been able to figure it out! The pinout diagram is here: https://github.com/dakschnitzer/time-gu ... t%2032.pdf
By the looks of that diagram, the OLED is connected by I2C, not SPI?

So instead:

Code: Select all

import sh1106
from machine import I2C, Pin
i2c = I2C(sda=Pin(4), scl=Pin(15))
display = sh1106.SH1106_I2C(128, 64, i2c, res=Pin(16)) 

dakschnitzer
Posts: 5
Joined: Wed Aug 07, 2019 10:52 pm

Re: Trouble connecting to SPI display sh1106

Post by dakschnitzer » Sun Aug 11, 2019 8:53 pm

Thanks for the reply.

As mentioned, I've gotten the external displays to work with an esp8266 using the code I pasted in. They are SPI displays, not I2C. The OLED display that is internal to the Heltec ESP32 board is I2C, and that works fine.

Here's the external SPI display I'm using: https://www.amazon.com/dp/B07QD4JWCN/re ... 6Cb749ZDMW

The comment I wrote about the DC pin on the SPI display is that I do not understand which pinout of the Heltec ESP32 I should be using for DC. I was guessing that perhaps GPIO26 would work. I was fairly confident that I had selected the correct GPIO pins for the other pins necessary for SPI displays as follows:

CLK -> GPIO18 (SCK / V_SPI_CLK)
MOSI -> GPIO23 (MOSI / V_SPI_D)
RES -> GPIO16 (OLED_RST)
CS -> GPIO5 (V_SPI_CSO)

So my questions are:
1. Have I selected the correct GPIO pins for the CLK, MOSI, RES, and CS pin on the SPI display?
2. What GPIO pin should I select on the ESP32 for the DC pin on the SPI display? I'm guessing GPIO26 should work but the display isn't showing anything.
3. Am I doing something else wrong?

As mentioned, I've gotten these SPI displays to work on the Heltec wifi ESP8266.

rpr
Posts: 99
Joined: Sat Oct 27, 2018 5:17 pm

Re: Trouble connecting to SPI display sh1106

Post by rpr » Sun Aug 11, 2019 11:31 pm

I don't have this board and have not used the SPI as well so my response may be naive. From the docs it appears that VSPI is at SPI(2).

http://docs.micropython.org/en/latest/e ... re-spi-bus

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Trouble connecting to SPI display sh1106

Post by OutoftheBOTS_ » Mon Aug 12, 2019 6:39 am

The on board OLED on the Heltec wifi ESP32 appear to be connect via I2C. https://github.com/dakschnitzer/time-gu ... t%2032.pdf

These little OLED can be wired many ways: I2C, SPI 3 wire, SPI 4, 8 bit parallel or even 16 bit parallel.

The low res of the OLED coupled with the fact it is only 1 bit colour means the speed of coms isn't an issue so it isn't uncommon to connect via I2C for these to save on pins used

dakschnitzer
Posts: 5
Joined: Wed Aug 07, 2019 10:52 pm

Re: Trouble connecting to SPI display sh1106

Post by dakschnitzer » Mon Aug 12, 2019 5:00 pm

Yes, the i2C OLED on the board itself is working fine. I'm not asking about how this works.

My question here is about getting this external SPI display working with the Heltec esp32: https://www.amazon.com/dp/B07QD4JWCN/re ... 6Cb749ZDMW

As you can see, this is a SPI display. As mentioned, I got these SPI displays to work fine over SPI using the aformentioned sh1106 SPI driver on the Heltec esp8266 board.

I'm now trying to get them to work on the esp32 board and am having trouble.

If anyone has successfully gotten external SPI displays to work on the Heltec esp32, I'd love to know what pins they're using. Especially for DC. As previously linked, the Heltec esp32 pinout pretty clearly shows what pins should be used for the other SPI pins - CLK, MOSI, RES, and CS.

I'm confused about which pin to use for DC.

Thanks,
Dan

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Trouble connecting to SPI display sh1106

Post by Roberthh » Mon Aug 12, 2019 5:22 pm

You can use any pin which is not used otherwise and that can be used in output mode. So do NOT use for thatGPIO0, GPIO1, GPIO3, GPIO34-39, and GPIO19. The latter is used for the hardware SPI 2 MISO, which you seem to use. For SPI 2, you have to chage you code into:

spi = SPI(2, baudrate=8000000)

see: http://docs.micropython.org/en/latest/e ... re-spi-bus

dakschnitzer
Posts: 5
Joined: Wed Aug 07, 2019 10:52 pm

Re: Trouble connecting to SPI display sh1106

Post by dakschnitzer » Tue Aug 13, 2019 3:53 pm

Thanks for following up! I'll give this a try.

Can you clarify what baudrate to use? I'd been using 800,000; you wrote 8,000,000; and in the documentation you linked to it's 80,000,000!

Thanks,
Dan

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Trouble connecting to SPI display sh1106

Post by Roberthh » Tue Aug 13, 2019 4:13 pm

The data sheet of the SH1106 talks a minimum clock cycle of 250 ns. That's a 4 MHz clock.
In a ESP8266 script I used 10 MHz. But the final clock rate was lower. The hardware SPI should make a more precise clock, so better do not use values beyond 4 MHz. In the samples of my driver I use 1 MHz.

P.S.: I copied the line from your script w/o checking, whether the clock is good.

dakschnitzer
Posts: 5
Joined: Wed Aug 07, 2019 10:52 pm

Re: Trouble connecting to SPI display sh1106

Post by dakschnitzer » Tue Aug 20, 2019 3:48 am

Thanks so much, Robert! Inserting the hspi initialization worked like a charm after changing around the pinouts.

Post Reply