Skip to content

Commit aa9a72b

Browse files
authored
Refactor the oled_i2c example (#217)
This PR does a number of things: 1. Renames the oled_i2c example to sssd1306_i2c to match other example folder names that use the device name 2. Merge code from another ssd1306 exmaple that was sitting in another PR 3. Add a few more demo parts to the code for extra fun. 4. Couple of bug fixes that were reported in original code to fix handling different display sizes, so code now works for 32 and 64 pixel height displays by changing a define at top of code.
1 parent 75c6a5e commit aa9a72b

14 files changed

+508
-328
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ App|Description
8383
[mma8451_i2c](i2c/mma8451_i2c) | Read acceleration from a MMA8451 accelerometer and set range and precision for the data.
8484
[mpl3115a2_i2c](i2c/mpl3115a2_i2c) | Interface with an MPL3115A2 altimeter, exploring interrupts and advanced board features, via I2C.
8585
[mpu6050_i2c](i2c/mpu6050_i2c) | Read acceleration and angular rate values from a MPU6050 accelerometer/gyro, attached to an I2C bus.
86-
[oled_i2c](i2c/oled_i2c) | Convert and display a bitmap on a 128x32 SSD1306-driven OLED display
86+
[ssd1306_i2c](i2c/ssd1306_i2c) | Convert and display a bitmap on a 128x32 or 128x64 SSD1306-driven OLED display
8787
[pa1010d_i2c](i2c/pa1010d_i2c) | Read GPS location data, parse and display data via I2C.
8888
[pcf8523_i2c](i2c/pcf8523_i2c) | Read time and date values from a real time clock. Set current time and alarms on it.
8989

i2c/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (NOT PICO_NO_HARDWARE)
77
add_subdirectory(mma8451_i2c)
88
add_subdirectory(mpl3115a2_i2c)
99
add_subdirectory(mpu6050_i2c)
10-
add_subdirectory(oled_i2c)
10+
add_subdirectory(ssd1306_i2c)
1111
add_subdirectory(pa1010d_i2c)
1212
add_subdirectory(pcf8523_i2c)
1313
endif ()

i2c/oled_i2c/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

i2c/oled_i2c/oled_i2c.c

Lines changed: 0 additions & 298 deletions
This file was deleted.

i2c/oled_i2c/oled_i2c_bb.png

-153 KB
Binary file not shown.
File renamed without changes.

i2c/ssd1306_i2c/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_executable(ssd1306_i2c
2+
ssd1306_i2c.c
3+
)
4+
5+
# pull in common dependencies and additional i2c hardware support
6+
target_link_libraries(ssd1306_i2c pico_stdlib hardware_i2c)
7+
8+
# create map/bin/hex file etc.
9+
pico_add_extra_outputs(ssd1306_i2c)
10+
11+
# add url via pico_set_program_url
12+
example_auto_set_url(ssd1306_i2c)

i2c/oled_i2c/README.adoc renamed to i2c/ssd1306_i2c/README.adoc

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
This example code shows how to interface the Raspberry Pi Pico with an 128x32 OLED display board based on the SSD1306 display driver, datasheet https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf[here].
44

5-
The code displays a series of tiny raspberries that scroll horizontally, in the process showing you how to initialize the display, write to the entire display, write to only a portion of the display, and configure scrolling.
5+
The code displays a series of small demo graphics; tiny raspberries that scroll horizontally, some text, and some line drawing, in the process showing you how to initialize the display, write to the entire display, write to only a portion of the display, configure scrolling, invert the display etc.
66

77
The SSD1306 is operated via a list of versatile commands (see datasheet) that allows the user to access all the capabilities of the driver. After sending a slave address, the data that follows can be either a command, flags to follow up a command or data to be written directly into the display's RAM. A control byte is required for each write after the slave address so that the driver knows what type of data is being sent.
88

9-
This display is 32 pixels high by 128 pixels wide. These 32 vertical pixels are partitioned into 4 pages, each 8 pixels in height. In RAM, this looks roughly like:
9+
The example code supports displays of 32 pixel or 64 pixels high by 128 pixels wide by changing a define at the top of the code.
1010

11-
[NOTE]
12-
======
13-
The SSD1306 can drive displays that are up to 64 pixels high and 128 pixels wide.
14-
======
11+
In the 32 vertical pixels case, the display is partitioned into 4 pages, each 8 pixels in height. In RAM, this looks roughly like:
1512

1613
----
1714
| COL0 | COL1 | COL2 | COL3 | ... | COL126 | COL127 |
@@ -42,30 +39,24 @@ The driver has 3 modes of transferring the pixels in RAM to the display (provide
4239

4340
Horizontal addressing mode has the key advantage that we can keep one single 512 byte buffer (128 columns x 4 pages and each byte fills a page's rows) and write this in one go to the RAM (column address auto increments on writes as well as reads) instead of working with 2D matrices of pixels and adding more overhead.
4441

45-
[NOTE]
46-
======
47-
* The SSD1306 is able to drive 128x64 displays but as our display is 128x32, only half of the COM (common) pins are connected to the display.
48-
* The specific display model being used is UG-2832HSWEG02
49-
======
50-
5142
== Wiring information
5243

5344
Wiring up the device requires 4 jumpers, to connect VCC (3.3v), GND, SDA and SCL and optionally a 5th jumper for the driver RESET pin. The example here uses the default I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the 3.3V pin from the Pico.
5445

55-
[[oled_i2c_wiring]]
46+
[[ssd1306_i2c_wiring]]
5647
[pdfwidth=75%]
5748
.Wiring Diagram for oled display via I2C.
58-
image::oled_i2c_bb.png[]
49+
image::ssd1306_i2c_bb.png[]
5950

6051
== List of Files
6152

6253
CMakeLists.txt:: CMake file to incorporate the example into the examples build tree.
63-
oled_i2c.c:: The example code.
54+
sd1306_i2c.c:: The example code.
6455

6556
== Bill of Materials
6657

6758
.A list of materials required for the example
68-
[[oled_i2c-bom-table]]
59+
[[ssd1306_i2c-bom-table]]
6960
[cols=3]
7061
|===
7162
| *Item* | *Quantity* | Details
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)