ESP8266 / SH1106 SPI - Garbled Output
-
- Posts: 4
- Joined: Fri Sep 16, 2016 10:58 pm
ESP8266 / SH1106 SPI - Garbled Output
Does anyone have some tips for getting the SH1106 "Waveshare" board working with the esp8266 (dev board)? I've gotten it to power on/off but the screen is all lit up with random blue pixels, not sure if it's an SPI issue of some sort, no errors or the like thrown. I've been using the ssd1306 driver from the main micropython repository, I couldn't find an official one for the SH1106. I did find various posts around but most dealt with I2C which I need to solder an onboard resistor to use, trying to hold off on that for now. I'm pretty new to both Python and Micro-anything ( long time JavaScript full stack guy here ) so hopefully its something simple I'm doing( or not doing )
- Components:
*** ESP8266 Dev Board
*** SH1106 WaveShare OLED Display
****** http://www.waveshare.com/wiki/1.3inch_OLED_(B)
****** http://www.waveshare.com/w/upload/7/76/ ... Manual.pdf
- Using I2C
*** Get I2C Bus Error, I think because the resistor on the back needs to be soldered to enable I2C mode with the SH1106, have not tested this theory but based on the data sheet above seems likely
- Using SPI
*** Screen powers on, but is filled with garbled pixels or all blue pixels. Tried various incarnations of instantiating the SPI class Pins, messing with baud rate etc... I'm just shooting in the dark at this point
- Pin Map
*** D7 - GPIO 13 - Din / MOSI
*** D5 - GPIO 14 - Clk / Sck
*** D1 - GPIO 5 - CS
*** D6 - GPIO 12 - D/C
*** D2 - GPIO 4 - Res
- Code
***
from machine import Pin, SPI
import time
import ssd1306
def initScreen():
spi = SPI(mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))
display = ssd1306.SSD1306_SPI(width=128, height=64, spi=spi, dc=Pin(12, Pin.OUT), res=Pin(4, Pin.OUT), cs=Pin(5), external_vcc=False)
display.fill(0)
display.text('Testing', 0, 0, 1)
display.show()
time.sleep_ms(3000)
display.poweroff()
initScreen()
print('Done!')
***
EDIT:
- I've also tried the sh1106.py driver found here https://goo.gl/Hfczob which I cannot get to display anything.
- I found the Espruino driver here http://www.espruino.com/modules/SH1106.js for what that is worth, might give it a shot just for a sanity check a little later
- Components:
*** ESP8266 Dev Board
*** SH1106 WaveShare OLED Display
****** http://www.waveshare.com/wiki/1.3inch_OLED_(B)
****** http://www.waveshare.com/w/upload/7/76/ ... Manual.pdf
- Using I2C
*** Get I2C Bus Error, I think because the resistor on the back needs to be soldered to enable I2C mode with the SH1106, have not tested this theory but based on the data sheet above seems likely
- Using SPI
*** Screen powers on, but is filled with garbled pixels or all blue pixels. Tried various incarnations of instantiating the SPI class Pins, messing with baud rate etc... I'm just shooting in the dark at this point
- Pin Map
*** D7 - GPIO 13 - Din / MOSI
*** D5 - GPIO 14 - Clk / Sck
*** D1 - GPIO 5 - CS
*** D6 - GPIO 12 - D/C
*** D2 - GPIO 4 - Res
- Code
***
from machine import Pin, SPI
import time
import ssd1306
def initScreen():
spi = SPI(mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))
display = ssd1306.SSD1306_SPI(width=128, height=64, spi=spi, dc=Pin(12, Pin.OUT), res=Pin(4, Pin.OUT), cs=Pin(5), external_vcc=False)
display.fill(0)
display.text('Testing', 0, 0, 1)
display.show()
time.sleep_ms(3000)
display.poweroff()
initScreen()
print('Done!')
***
EDIT:
- I've also tried the sh1106.py driver found here https://goo.gl/Hfczob which I cannot get to display anything.
- I found the Espruino driver here http://www.espruino.com/modules/SH1106.js for what that is worth, might give it a shot just for a sanity check a little later
Re: ESP8266 / SH1106 SPI - Garbled Output
I made a driver for that display some time ago: https://bitbucket.org/thesheep/micropyt ... /sh1106.py
-
- Posts: 4
- Joined: Fri Sep 16, 2016 10:58 pm
Re: ESP8266 / SH1106 SPI - Garbled Output
[quote="deshipu"]I made a driver for that display some time ago: https://bitbucket.org/thesheep/micropyt ... /sh1106.py[/quote]
Right, thanks... I tried your driver but I don't get any activity out of the display. Like I said, I'm pretty new to the hardware side of things, I don't suppose you have an SPI code snippet using your driver do you? Maybe it's something with how I'm setting up SPI, there seems to be some conflicting documentation out there and multiple boards that require different SPI init code plus different if HW Vs SW SPI doesn't make it easier for me knowing if its something I've done wrong.
Thanks.
Right, thanks... I tried your driver but I don't get any activity out of the display. Like I said, I'm pretty new to the hardware side of things, I don't suppose you have an SPI code snippet using your driver do you? Maybe it's something with how I'm setting up SPI, there seems to be some conflicting documentation out there and multiple boards that require different SPI init code plus different if HW Vs SW SPI doesn't make it easier for me knowing if its something I've done wrong.
Thanks.
Re: ESP8266 / SH1106 SPI - Garbled Output
Something like this should get you started:
This code assumes the following connections:
Code: Select all
from machine import Pin, SPI
import sh1106
spi = SPI(1)
display = sh1106.SH1106(spi, dc=Pin(4), rst=Pin(5), cs=Pin(15))
display.fill(1)
display.pixel(64, 32, 0)
display.show()
- MISO → gpio12 (if available)
- MOSI → gpio13
- SCK → gpio14
- CS → gpio15
- DC → gpio4
- RST → gpio5
Code: Select all
spi = SPI(1, baudrate=10000000)
-
- Posts: 4
- Joined: Fri Sep 16, 2016 10:58 pm
Re: ESP8266 / SH1106 SPI - Garbled Output
Thanks, I gave that a shot but still not working, used the same pin map you laid out ( no miso afaik, although here is an unused pin 'NC' I haven't seen used in any examples )... no error, nothing shows on screen using your driver. Also tried a slower baudrate as suggested, same result
As a sanity check I got an Arduino driver at the link below, loaded the example for the esp8266, didn't change any of the pin mappings and the screen works just fine out of the box using SPI. ( I was kinda shocked, could have swear it was something I was doing ). At this point, seeing as Arduino is working, I'm assuming this is a driver issue of some sort? If there is a way to get some debug information let me know and I can try anything needed.
Arduino Driver: https://github.com/rene-mt/esp8266-oled-sh1106
I also tried both, the release firmware "esp8266-20160909-v1.8.4.bin" and the latest nightly "esp8266-20160917-v1.8.4-16-gb9672bc.bin" and got the same result, no error, nothing on screen. I erased flash in between all this testing.
I'm stumped, thanks for taking the time to help though, it is appreciated.
As a sanity check I got an Arduino driver at the link below, loaded the example for the esp8266, didn't change any of the pin mappings and the screen works just fine out of the box using SPI. ( I was kinda shocked, could have swear it was something I was doing ). At this point, seeing as Arduino is working, I'm assuming this is a driver issue of some sort? If there is a way to get some debug information let me know and I can try anything needed.
Arduino Driver: https://github.com/rene-mt/esp8266-oled-sh1106
I also tried both, the release firmware "esp8266-20160909-v1.8.4.bin" and the latest nightly "esp8266-20160917-v1.8.4-16-gb9672bc.bin" and got the same result, no error, nothing on screen. I erased flash in between all this testing.
I'm stumped, thanks for taking the time to help though, it is appreciated.
Re: ESP8266 / SH1106 SPI - Garbled Output
Just making sure, it won't update the screen until you actually call display.show()
I tested this with my own screen, and it worked, so something is weird. Can you try with software SPI?
I tested this with my own screen, and it worked, so something is weird. Can you try with software SPI?
Code: Select all
spi = SPI(-1, miso=Pin(12), mosi=Pin(13), sck=Pin(14))
Re: ESP8266 / SH1106 SPI - Garbled Output
You can also call display.sleep(False) to force the display to switch on, although that shoudn't be necessary.
Re: ESP8266 / SH1106 SPI - Garbled Output
I just tried a random SH1106 display from my drawer, and it required display.sleep(False) to switch it on first.
-
- Posts: 4
- Joined: Fri Sep 16, 2016 10:58 pm
Re: ESP8266 / SH1106 SPI - Garbled Output
Ha, that was it, in combination with manually setting the baud rate. Both the baud rate and manually setting sleep False works, however without either one the screen remains off and nothing happens. Thank you so much for the help!! To recap the code is below which finally works with the driver found here: https://bitbucket.org/thesheep/micropyt ... ew-defaultdeshipu wrote:You can also call display.sleep(False) to force the display to switch on, although that shoudn't be necessary.
Code: Select all
# Waveshare sh1106: http://www.waveshare.com/w/upload/7/76/1.3inch_OLED_UserManual.pdf
# uPython Driver: https://bitbucket.org/thesheep/micropython-ili9341/src/tip/sh1106.py?fileviewer=file-view-default
# Pin Map
# - 3v - xxxxxx - Vcc
# - G - xxxxxx - Gnd
# - D7 - GPIO 13 - Din / MOSI
# - D5 - GPIO 14 - Clk / Sck
# - D8 - GPIO 15 - CS
# - D2 - GPIO 4 - D/C
# - D1 - GPIO 5 - Res
from machine import Pin, SPI
import sh1106
spi = SPI(1, baudrate=10000000)
display = sh1106.SH1106(spi, dc=Pin(4), rst=Pin(5), cs=Pin(15))
display.sleep(False)
display.fill(0)
display.text('Testing 1', 0, 0, 1)
display.show()