using_pico_with_ssd1306_based_lcd_and_spi
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| using_pico_with_ssd1306_based_lcd_and_spi [2026/08/21 13:24] – [Python Code] walkeradmin | using_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 # | ||
| - | \\ | ||
| <color # | <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 # | ||
| + | < | ||
| + | from machine import Pin, SPI | ||
| + | from ssd1306_spi import SSD1306_SPI | ||
| + | import time | ||
| + | |||
| + | # SPI1 setup | ||
| + | spi = SPI(1, baudrate=8000000, | ||
| + | |||
| + | dc = Pin(13, Pin.OUT) | ||
| + | res = Pin(12, Pin.OUT) | ||
| + | cs = Pin(14, Pin.OUT) | ||
| + | |||
| + | oled = SSD1306_SPI(128, | ||
| + | |||
| + | oled.fill(0) | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.show() | ||
| + | |||
| + | # call the function below from your main code with the value 255 (max brightness) | ||
| + | oled.set_brightness(255) | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
| + | ==== LCD Test Code ---- | ||
| + | \\ | ||
| + | I want to look at the old I2C code and compare to the SPI code to point out some differences, | ||
| + | \\ | ||
| + | \\ | ||
| + | Here is the original I2C code | ||
| + | < | ||
| + | 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, | ||
| + | |||
| + | lcd.fill(0) | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.text(" | ||
| + | lcd.show() | ||
| + | |||
| + | time.sleep(300) | ||
| + | lcd.fill(0) | ||
| + | lcd.show() | ||
| + | </ | ||
| + | |||
| + | Here is the same code, but modified to run the SPI LCD Screen. | ||
| + | \\ | ||
| + | <color # | ||
| + | |||
| + | < | ||
| + | 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, | ||
| + | |||
| + | dc = Pin(13, Pin.OUT) | ||
| + | res = Pin(12, Pin.OUT) | ||
| + | cs = Pin(14, Pin.OUT) | ||
| + | |||
| + | oled = SSD1306_SPI(128, | ||
| + | |||
| + | oled.fill(0) | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.text(" | ||
| + | oled.show() | ||
| + | |||
| + | time.sleep(300) | ||
| + | oled.fill(0) | ||
| + | oled.show() | ||
| + | </ | ||
| + | |||
| + | 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, | ||
| + | * **In the second example we used the name oled** - oled = SSD1306_SPI(128, | ||
| + | |||
| + | 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). | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | 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
