using_pico_with_ssd1306_based_lcd
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 [2026/08/16 18:44] – [How the Code Works] walkeradmin | using_pico_with_ssd1306_based_lcd [2026/08/19 19:36] (current) – [Something Quirky with this OLED Screen] walkeradmin | ||
|---|---|---|---|
| Line 58: | Line 58: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | {{ : | + | {{ : |
| \\ | \\ | ||
| There are a sets of I2C0 pins and I2C1 pins, so you need to remember which Bus you are on (zero for our example) You also need to remember the pin numbers as we will reference both the Pin numbers and Bus number is our code. | There are a sets of I2C0 pins and I2C1 pins, so you need to remember which Bus you are on (zero for our example) You also need to remember the pin numbers as we will reference both the Pin numbers and Bus number is our code. | ||
| Line 67: | Line 67: | ||
| * Bus = 0 | * Bus = 0 | ||
| * Pins = 6(SDA) and 7(SCL) | * Pins = 6(SDA) and 7(SCL) | ||
| - | \\ | + | |
| - | \\ | + | Note: Pins 6 and 7 are the physical pins, but for the Python code, we need to supply the GPIO numbers, which will be: |
| + | |||
| + | * Pin 6 = GPIO4 (SDA) | ||
| + | * Pin 7 = GPIO5 (SCL) | ||
| ---- | ---- | ||
| ==== The Micro Python Code ==== | ==== The Micro Python Code ==== | ||
| Line 194: | Line 198: | ||
| This part imports some libraries, including our LCD library, there is a time library here, but we are not using it (I want to make a clock eventually) | This part imports some libraries, including our LCD library, there is a time library here, but we are not using it (I want to make a clock eventually) | ||
| - | <code | download> | + | <code: |
| from machine import Pin, I2C | from machine import Pin, I2C | ||
| import ssd1306 | import ssd1306 | ||
| Line 200: | Line 204: | ||
| </ | </ | ||
| - | This next part is crucial. It contains the Pico Pins you used for data | + | This next part is crucial. It contains the Pico Pins you used for data. However, we are using the GPIO pin reference, not the actual pin number. |
| + | \\ | ||
| + | \\ | ||
| + | At the start of this line: i2c = I2C(< | ||
| - | <code | download> | + | <code: |
| - | # Your wiring: SDA=GP6, SCL=GP7 → I2C0 | + | # Your wiring: SDA=GP4, SCL=GP5 → I2C0 |
| i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000) | i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000) | ||
| </ | </ | ||
| + | |||
| + | This next line does the following: | ||
| + | |||
| + | * lcd creates and object called <color # | ||
| + | * ssd1306 refers to the library we created. | ||
| + | * SSD1306_I2C defines we are using I2C (not SPI for example) | ||
| + | * The rest are parameters passed to the library so the library knows how to handle our LCD | ||
| + | |||
| + | < | ||
| + | lcd = ssd1306.SSD1306_I2C(128, | ||
| + | </ | ||
| + | |||
| + | Now for the good part: | ||
| + | |||
| + | * lcd.fill(0) - fils the LCD with zeroes (blank the LCD) | ||
| + | * lcd.text(" | ||
| + | * lcd.text(" | ||
| + | * lcd.text(" | ||
| + | * lcd.text(" | ||
| + | * lcd.show() - Write to the LCD. | ||
| + | |||
| + | The numbers (0, 0), (0, 16) are the x,y start point of each line of text, we can see that the height of the text we are using is 16 pixels. | ||
| + | \\ | ||
| + | \\ | ||
| + | At this point, the LCD will show our text, and you shoud see something very similar to below: | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | |||
| + | This last part just turns the LCD off after 5 seconds, as I don't know what my LCD is like for burn in. | ||
| + | |||
| + | < | ||
| + | time.sleep(5) | ||
| + | lcd.fill(0) | ||
| + | lcd.show() | ||
| + | </ | ||
| + | |||
| + | Hopefully, this has worked for you and you can have some fun with the LCD. This example we are only writing text to the LCD, in future examples, we will explore something a little more graphical. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
| + | ==== Oh No!!! I don't have an LCD to play with yet!!! ==== | ||
| + | \\ | ||
| + | Don't worry, I got you. I have set up this project on Wokwi, a simulator site for Microcontrollers. | ||
| + | \\ | ||
| + | \\ | ||
| + | Please follow this link: [[https:// | ||
| + | \\ | ||
| + | \\ | ||
| + | Here you can see the code, the library and if you press play it will emulate the actual hardware version we have made. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | I hope you find this wiki article useful :) | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
| + | ==== Something Quirky with this OLED Screen ==== | ||
| + | \\ | ||
| + | So I have noticed something a little quirky with this LCD Panel. It seems to be in two parts, let me explain. | ||
| + | \\ | ||
| + | \\ | ||
| + | The Yellow section of the panel is 16 pixels high, then there seems to be a hard barrier between there and the Blue section which is 48 pixels high. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | So you can move text vertically up and down the screen, but not through the join in the yellow/blue part, the text will get chopped off. So you will have to think about the screen as two parts. | ||
| + | \\ | ||
| + | \\ | ||
| + | Below is some code where you can squeeze 8 lines of text on to this little OLED. Each line the text is 6 pixels tall, and there is a two pixel gap between each line. Effectively each line takes 8 pixels, so 8 lines = 8linex8Pixel = 64 pixels, the exact LCD height. | ||
| + | |||
| + | < | ||
| + | from machine import Pin, I2C | ||
| + | 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() | ||
| + | </ | ||
| + | |||
| + | The LCD can have 16 characters across, so the characters are 8 pixels wide. So 16char x 8pixel =128 Pixels wide. | ||
| + | \\ | ||
| + | \\ | ||
| + | Using the code above, feel free to change the text and have a play, also play with the line spacing to explore the Yellow/Blue section limitation, each line is moved down by 8 pixels in the script, but have a play with these values to see what fits for you. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
using_pico_with_ssd1306_based_lcd.1786905863.txt.gz · Last modified: by walkeradmin
