single repo

This commit is contained in:
Adolfo Reyna
2026-01-01 13:33:51 -05:00
parent 8b56187ef1
commit bc8ae91eba
334 changed files with 124529 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(text_example)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(text_example
main.cpp)
target_link_libraries(text_example
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(text_example)

View File

@@ -0,0 +1,39 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/textRenderer/TextRenderer.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main(){
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// Draw text on display
// After passing a pointer to display, we need to tell the function what font and text to use
// Available fonts are listed in textRenderer's readme
// Last we tell this function where to anchor the text
// Anchor means top left of what we draw
drawText(&display, font_12x16, "TEST text", 0 ,0);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 KiB

View File

@@ -0,0 +1,3 @@
# This examples produces such a result
![output](output.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(bitmap_example)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(bitmap_example
main.cpp)
target_link_libraries(bitmap_example
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(bitmap_example)

View File

@@ -0,0 +1,55 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main() {
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// Create a variable storing our bitmap image
unsigned char image[] = {
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000011, 0b11000000,
0b00000010, 0b01000000,
0b00000110, 0b11100000,
0b00001100, 0b00110000,
0b00111001, 0b00011100,
0b11101000, 0b01000111,
0b11100010, 0b00000111,
0b00111000, 0b01011100,
0b00001100, 0b10110000,
0b00000110, 0b01100000,
0b00000011, 0b01000000,
0b00000011, 0b11000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000
};
// Add image to buffer with anchor at point x: 10, y:10 and image width: 16 and height:16
display.addBitmapImage(10, 10, 16, 16, image);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 KiB

View File

@@ -0,0 +1,3 @@
# This examples produces such a result
![output](output.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(line_example)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(line_example
main.cpp)
target_link_libraries(line_example
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(line_example)

View File

@@ -0,0 +1,31 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/shapeRenderer/ShapeRenderer.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main(){
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Draw a line on display from 0, 0 to 127, 63
drawLine(&display, 0, 0 ,127, 63);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 KiB

View File

@@ -0,0 +1,3 @@
# This examples produces such a result
![output](output.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(falling_dots)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(falling_dots
main.cpp)
target_link_libraries(falling_dots
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(falling_dots)

View File

@@ -0,0 +1,50 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "hardware/i2c.h"
#pragma ide diagnostic ignored "EndlessLoop"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main() {
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// variable to count on witch frame we are on
uint32_t frame_counter = 0;
// Infinite animation loop
while (1){
// Draw pixels spaced 8 px apart, one px lower every frame
for (uint8_t pass1 = 0; pass1 < 15; pass1 ++){
display.setPixel(pass1 * 8, frame_counter % 63);
}
// Send buffer to display
display.sendBuffer();
// Show the frame for 100ms
sleep_ms(100);
// Clear the buffer
display.clear();
// Increment frame counter
frame_counter ++;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 KiB

View File

@@ -0,0 +1,7 @@
# This examples produces such a result
![output](output1.jpg)
![output](output2.jpg)
![output](output3.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(flag)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(flag
main.cpp)
target_link_libraries(flag
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(flag)

View File

@@ -0,0 +1,44 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/shapeRenderer/ShapeRenderer.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main() {
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// Draw an outline
drawRect(&display, 0, 0, 127, 63);
// Draw 2 rectangles
fillRect(&display, 0, 0, 63, 31);
fillRect(&display, 64, 32, 127, 63);
// Draw a line across the screen
drawLine(&display, 127, 0, 0, 63);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 KiB

View File

@@ -0,0 +1,5 @@
# This examples produces such a result
## Ignore yellow at the bottom (that's just my screen dying from hours of testing and development and some abuse)
![output](output1.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(multiple_displays)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(multiple_displays
main.cpp)
target_link_libraries(multiple_displays
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(multiple_displays)

View File

@@ -0,0 +1,44 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/textRenderer/TextRenderer.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main() {
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3C and size of 128x32
SSD1306 display1 = SSD1306(i2c0, 0x3C, Size::W128xH32);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display2 = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display1.setOrientation(0);
display2.setOrientation(0);
// Draw text on display 1
drawText(&display1, font_16x32, "Disp 1", 0, 0);
// Draw text on display 2
drawText(&display2, font_16x32, "Disp 2", 0, 0);
// Send buffer to the displays
display1.sendBuffer();
display2.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 KiB

View File

@@ -0,0 +1,3 @@
# This examples produces such a result
![output](output1.jpg)

View File

@@ -0,0 +1,53 @@
# Examples for pico ssd1306 library
## Core library
| Link | Description |
|----------------------------------------|-------------------------------------------------|
| [bitmap_image](bitmap_image) | Display a simple bitmap image |
| [falling_dots](falling_dots) | Animation of dots falling on screen |
| [write_mode](write_mode) | Example showing differences between write modes |
| [multiple_displays](multiple_displays) | 2 Displays connected to the same i2c controller |
## Shape Renderer Module
| Link | Description |
|------------------------|-------------------------------------------------------------------------------|
| [draw_line](draw_line) | Example of drawing a line across the screen |
| [flag](flag) | Drawing a "flag" on your display. Shows how to use different shape renderers. |
## Text Renderer Module
| Link | Description |
|--------------------------------------------|----------------------------------------|
| [basic_text](basic_text) | Drawing some sample text to the screen |
| [text_advanced](text_advanced) | Drawing normal and rotated text |
| [text_extended_ascii](text_extended_ascii) | Using extended ASCII chars |
## How to build an example
* Clone this project and go into one of the examples
```shell
git clone https://github.com/Harbys/pico-ssd1306.git
cd pico-ssd1306/examples/(choose_an_example)
```
* Copy pico_sdk_import.cmake from your pico-sdk
```shell
cp (path_to_pico_sdk)/external/pico_sdk_import.cmake .
```
* Set the PICO_SDK_PATH environment variable
```shell
export PICO_SDK_PATH="(path_to_pico_sdk)"
```
* Create a symlink to the whole library
```shell
ln -s ../../. pico-ssd1306
```
* Create a build directory and enter it
```shell
mkdir build
cd build
```
* Build
```shell
cmake .. && make
```
* Copy the uf2 file to your pico

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(text_advanced)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(text_advanced
main.cpp)
target_link_libraries(text_advanced
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(text_advanced)

View File

@@ -0,0 +1,40 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/textRenderer/TextRenderer.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main() {
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// Draw unrotated text
drawText(&display, font_8x8, "Text Normal", 16, 0);
// Draw text rotated by 90 degrees
drawText(&display, font_5x8, "Text Rotated", 0, 0, WriteMode::ADD, Rotation::deg90);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 KiB

View File

@@ -0,0 +1,3 @@
# This examples produces such a result
![output](output1.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(text_extended_ascii)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(text_extended_ascii
main.cpp)
target_link_libraries(text_extended_ascii
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(text_extended_ascii)

View File

@@ -0,0 +1,46 @@
// Define SSD1306_ASCII_FULL to use full ascii range (32 - 255)
#define SSD1306_ASCII_FULL
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/textRenderer/TextRenderer.h"
#include "hardware/i2c.h"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main(){
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// Draw text on display
// After passing a pointer to display, we need to tell the function what font and text to use
// Available fonts are listed in textRenderer's readme
// Last we tell this function where to anchor the text
// Anchor means top left of what we draw
// We use \x escape to use chars by their hex numeration according to the ASCII table
drawText(&display, font_5x8, "\x24 \xba \xb2", 0 ,0);
drawText(&display, font_8x8, "\x24 \xba \xb2", 0 ,10);
drawText(&display, font_12x16, "\x24 \xba \xb2", 0 ,20);
drawText(&display, font_16x32, "\x24 \xba \xb2", 0 ,36);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

View File

@@ -0,0 +1,3 @@
# This examples produces such a result
![output](output1.jpg)

View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(write_mode)
pico_sdk_init()
add_subdirectory(pico-ssd1306)
add_executable(write_mode
main.cpp)
target_link_libraries(write_mode
hardware_i2c
pico_ssd1306)
pico_add_extra_outputs(write_mode)

View File

@@ -0,0 +1,65 @@
#include "pico/stdlib.h"
#include "pico-ssd1306/ssd1306.h"
#include "pico-ssd1306/shapeRenderer/ShapeRenderer.h"
#include "hardware/i2c.h"
#pragma ide diagnostic ignored "EndlessLoop"
// Use the namespace for convenience
using namespace pico_ssd1306;
int main() {
// Init i2c0 controller
i2c_init(i2c0, 1000000);
// Set up pins 12 and 13
gpio_set_function(12, GPIO_FUNC_I2C);
gpio_set_function(13, GPIO_FUNC_I2C);
gpio_pull_up(12);
gpio_pull_up(13);
// If you don't do anything before initializing a display pi pico is too fast and starts sending
// commands before the screen controller had time to set itself up, so we add an artificial delay for
// ssd1306 to set itself up
sleep_ms(250);
// Create a new display object at address 0x3D and size of 128x64
SSD1306 display = SSD1306(i2c0, 0x3D, Size::W128xH64);
// Here we rotate the display by 180 degrees, so that it's not upside down from my perspective
// If your screen is upside down try setting it to 1 or 0
display.setOrientation(0);
// Fill left half of the screen
fillRect(&display, 0, 0, 63,63);
// Create a variable storing a bitmap image
unsigned char image[] = {
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000011, 0b11000000,
0b00000010, 0b01000000,
0b00000110, 0b11100000,
0b00001100, 0b00110000,
0b00111001, 0b00011100,
0b11101000, 0b01000111,
0b11100010, 0b00000111,
0b00111000, 0b01011100,
0b00001100, 0b10110000,
0b00000110, 0b01100000,
0b00000011, 0b01000000,
0b00000011, 0b11000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000
};
// To see this example at work play with WriteMode
// Add will turn pixels on regardless of their state
// Subtract will turn pixels off regardless of their state
// Invert will swap state of selected pixels
display.addBitmapImage(63-8, 31-8, 16, 16, image, WriteMode::INVERT);
// Send buffer to the display
display.sendBuffer();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 KiB

View File

@@ -0,0 +1,12 @@
# This examples produces such a result
## Ignore yellow at the bottom (that's just my screen dying from hours of testing and development and some abuse)
### WriteMode::ADD
![output](output1.jpg)
### WriteMode::SUBTRACT
![output](output2.jpg)
### WriteMode::INVERT
![output](output3.jpg)