Page 1 of 1

SSD1306 using SPI

Posted: Fri Jun 11, 2021 6:38 pm
by skymast
Hi

I have an SSD1306 Oled 128x64
It looks identical to the one on this page https://simple-circuit.com/ssd1306-oled ... -projects/

The resistors are configured for it to be in SPI mode.

I can't get it to display anything at all. I'm not sure if it is a wiring problem or a software problem.

I am wiring it as follows:
1 GND --> GND
2 VDD --> 3.3V
3 SCX --> Raspberry Pi Pico pin 4 (GP2/SPI0 SCK)
4 SDA --> Raspberry Pi Pico pin 5 (GP3/SPI0 TX)
5 RES --> 3.3V
6 DC --> Raspberry Pi Pico pin 6 (GP4/SPI0 RX)
7 CS --> GND

I am trying to write to it using this code

import machine

spi_sck = machine.Pin(2)
spi_tx = machine.Pin(3)
spi_rx = machine.Pin(4)
spi = machine.SPI( 0, baudrate=20000, sck=spi_sck, mosi=spi_tx, miso=spi_rx)

spi.write('\x7C')
spi.write('\x2D')
spi.write("hello world")

If anyone has any ideas or suggestions please, they would be very gratefully received :)

Re: SSD1306 using SPI

Posted: Fri Jun 11, 2021 6:49 pm
by Roberthh
Follow the examples of the documentation: https://docs.micropython.org/en/latest/ ... ht=ssd1306

Re: SSD1306 using SPI

Posted: Fri Jun 11, 2021 7:42 pm
by skymast
Thank you very much - that's solved my problem.

I was following the tutorial for the RP2xxx - which seemed sensible!! :) The tutorial for the ESP8266 which you linked to was different, but actually worked. Go figure ...

For future reference - here is my working setup

1 GND --> GND
2 VDD --> 3.3V
3 SCX --> Raspberry Pi Pico pin 4 (GP2/SPI0 SCK)
4 SDA --> Raspberry Pi Pico pin 5 (GP3/SPI0 TX)
5 RES --> Raspberry Pi Pico pin 9 (GP6)
6 DC --> Raspberry Pi Pico pin 6 (GP4/SPI0 RX)
7 CS --> Raspberry Pi Pico pin 7 (GP5/SPI0 CSn)

import machine
import ssd1306

hspi = machine.SPI(0)
dc = machine.Pin(4)
cs = machine.Pin(5)
rst = machine.Pin(6)

display = ssd1306.SSD1306_SPI(128, 64, hspi, dc, rst, cs)
display.text('Hello World!', 0, 0, 1 )
display.show()