User Tools

Site Tools


using_pico_with_ssd1306_based_lcd_and_spi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
using_pico_with_ssd1306_based_lcd_and_spi [2026/08/21 13:24] – [Python Code] walkeradminusing_pico_with_ssd1306_based_lcd_and_spi [2026/08/24 20:01] (current) – [Python Code] walkeradmin
Line 1: Line 1:
 ====== Using Pico with SSD1306 based LCD and SPI ====== ====== Using Pico with SSD1306 based LCD and SPI ======
-<color #ed1c24>***** THIS PAGE IS WORK IN PROGRESS *****</color> 
-\\  
 <color #db5f0b>Aug 2026</color> <color #db5f0b>Aug 2026</color>
 \\  \\ 
Line 53: Line 51:
 \\  \\ 
 \\  \\ 
 +----
 +==== The Driver for SPI (1306 driver chip) ====
 +\\ 
 +Below is the driver you will need for the LCD. You need to put it in to the <color #ed1c24>lib</color> folder on your Pico.
  
 +<code:python | download>
 +from machine import Pin, SPI
 +from ssd1306_spi import SSD1306_SPI
 +import time
 +
 +# SPI1 setup
 +spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
 +
 +dc  = Pin(13, Pin.OUT)
 +res = Pin(12, Pin.OUT)
 +cs  = Pin(14, Pin.OUT)
 +
 +oled = SSD1306_SPI(128, 64, spi, dc, res, cs)
 +
 +oled.fill(0)
 +oled.text("Hello Alan!", 0, 0)
 +oled.text("SSD1306 SPI OK", 0, 16)
 +oled.text("Pico 2 Ready", 0, 32)
 +oled.show()
 +
 +# call the function below from your main code with the value 255 (max  brightness)
 +oled.set_brightness(255)
 +</code>
 +\\ 
 +\\ 
 +----
 +==== LCD Test Code ----
 +\\ 
 +I want to look at the old I2C code and compare to the SPI code to point out some differences, this is the Python code that just prints 8 static lines on the LCD for a simple test.
 +\\ 
 +\\ 
 +Here is the original I2C code
 +<code:python | download>
 +from machine import Pin, I2C    #Gives access to the I²C Pins. Without it, you couldn’t use GPIO pins or I²C.
 +import ssd1306
 +import time
 +
 +i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
 +lcd = ssd1306.SSD1306_I2C(128, 64, i2c)
 +
 +lcd.fill(0)
 +lcd.text("Yo Tuesday Club!", 0, 0)
 +lcd.text("SSD1306 LCD",      0, 8)
 +lcd.text("Address 0x3C",     0, 16)
 +lcd.text("Cool :)",          0, 24)
 +lcd.text("Another Line :)",  0, 32)
 +lcd.text("One More? :)",     0, 40)
 +lcd.text("Line 7",           0, 48)
 +lcd.text("Line 8",           0, 56)
 +lcd.show()
 +
 +time.sleep(300)
 +lcd.fill(0)
 +lcd.show()
 +</code>
 +
 +Here is the same code, but modified to run the SPI LCD Screen.
 +\\ 
 +<color #ed1c24>Use this code for your SPI LCD Display.</color>
 +
 +<code:python | download>
 +from machine import Pin, SPI    #Gives access to the SPI Pins. Without it, you couldn’t use GPIO pins or SPI.
 +from ssd1306_spi import SSD1306_SPI
 +import time
 +
 +spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
 +
 +dc  = Pin(13, Pin.OUT)
 +res = Pin(12, Pin.OUT)
 +cs  = Pin(14, Pin.OUT)
 +
 +oled = SSD1306_SPI(128, 64, spi, dc, res, cs)
 +
 +oled.fill(0)
 +oled.text("Yo Tuesday Club!", 0, 0)
 +oled.text("SSD1306 oled",      0, 8)
 +oled.text("Address 0x3C",     0, 16)
 +oled.text("Cool :)",          0, 24)
 +oled.text("Another Line :)",  0, 32)
 +oled.text("One More? :)",     0, 40)
 +oled.text("Line 7",           0, 48)
 +oled.text("Line 8",           0, 56)
 +oled.show()
 +
 +time.sleep(300)
 +oled.fill(0)
 +oled.show()
 +</code>
 +
 +The second line of each Python script loads some code, there is some difference in how they work:
 +
 +  * **import ssd1306** - Loads the entire module, and you have access to all classes within that module.
 +  * **from ssd1306_spi import SSD1306_SPI** - Loads just the SSD1306_SPI class from the module ssd1306_spi.
 +
 +  * **In the first example we used the name lcd** - lcd = ssd1306.SSD1306_I2C(128, 64, i2c)
 +  * **In the second example we used the name oled** - oled = SSD1306_SPI(128, 64, spi, dc, res, cs)
 +
 +The rest is pretty much the same, from a code perspective there really isn't much difference in the amount of work to get the I2C or SPI LCD displays working.
 +\\ 
 +\\ 
 +----
 +==== The Running LCDs ====
 +\\ 
 +Below we can see both the I2C LCD (on the right) and the SPI LCD (Below the Pico).
 +\\ 
 +\\ 
 +{{ :0.96-spi-lcd-running.jpeg?500 |}}
 +\\ 
 +They both work really well and for simple text based applications will be perfect. 
 +\\ 
 +\\ 
 +----
using_pico_with_ssd1306_based_lcd_and_spi.1787318653.txt.gz · Last modified: by walkeradmin