-
Notifications
You must be signed in to change notification settings - Fork 152
[driver] SSD1306 SPI display #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rleh
wants to merge
5
commits into
modm-io:develop
Choose a base branch
from
rleh:ssd1306_spi
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
def628e
[driver] Rename SSD1306 driver to ssd1306.i2c
rleh a06da05
[examples] Update SSD1306 examples
rleh 77ba35a
[examples] Add SH1106/SSD1306 I2C display example for Nucleo-G474RE
rleh 275c635
[driver] Add SSD1306 SPI driver
rleh 4c0e511
[examples] Add SSD1306 SPI display example for Nucleo-G474RE
rleh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2023, Raphael Lehmann | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/driver/display/sh1106_i2c.hpp> | ||
// #include <modm/driver/display/ssd1306_i2c.hpp> | ||
|
||
/// SH1106 display in I2C mode | ||
using MyI2cMaster = modm::platform::I2cMaster1; | ||
using Scl = Board::D15; | ||
using Sda = Board::D14; | ||
|
||
using Display = modm::Sh1106I2c<MyI2cMaster>; | ||
// using Display = modm::Ssd1306<MyI2cMaster>; | ||
|
||
Display display; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
modm::delay(100ms); | ||
|
||
MyI2cMaster::connect<Sda::Sda, Scl::Scl>(); | ||
// Use 20kHz I2C and internal pull-ups, works without external pull-ups | ||
// if the jumper wires are short enought | ||
MyI2cMaster::connect<Sda::Sda, Scl::Scl>(MyI2cMaster::PullUps::Internal); | ||
|
||
modm::delay(100ms); | ||
|
||
RF_CALL_BLOCKING(display.initialize()); | ||
RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0)); | ||
RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted)); | ||
RF_CALL_BLOCKING(display.setContrast(80)); | ||
|
||
display.setFont(modm::font::Assertion); | ||
|
||
modm::ShortPeriodicTimer timer(333ms); | ||
uint16_t counter(0); | ||
|
||
while (true) | ||
{ | ||
if (timer.execute()) | ||
{ | ||
display.clear(); | ||
display.setCursor(1, 1); | ||
display << "Hello World!"; | ||
display.setCursor(1, 17); | ||
display << counter++; | ||
display.setCursor(1, 33); | ||
display << "Line 3"; | ||
display.setCursor(1, 49); | ||
display << "Line 4"; | ||
|
||
display.update(); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<library> | ||
<extends>modm:nucleo-g474re</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_g474re/sh1106_i2c</option> | ||
</options> | ||
<modules> | ||
<module>modm:driver:sh1106.i2c</module> | ||
<module>modm:driver:ssd1306.i2c</module> | ||
<module>modm:platform:gpio</module> | ||
<module>modm:platform:i2c:1</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2023, Raphael Lehmann | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/driver/display/ssd1306_spi.hpp> | ||
|
||
/** | ||
* SSD1306 display in SPI 4-wire mode | ||
* | ||
* SCK <-> Arduino D3 / GpioB3 | ||
* MOSI <-> Arduino D4 / GpioB5 | ||
* CS <-> Arduino D5 / GpioB4 | ||
* D/C# <-> Arduino D2 / GpioA10 | ||
* RESET# <-> Arduino D7 / GpioA8 | ||
* | ||
* En7V5 <-> Arduino D6 / GpioB10 | ||
* | ||
* TODO: Describe charge pump setup for 7.5V | ||
*/ | ||
|
||
using MySpiMaster = modm::platform::SpiMaster1; | ||
using Sck = Board::D3; | ||
using Mosi = Board::D4; | ||
using Cs = Board::D5; | ||
using Dc = Board::D2; | ||
using Reset = Board::D7; | ||
using En7V5 = Board::D6; | ||
using Display = modm::Ssd1306Spi<MySpiMaster, Cs, Dc, 32>; | ||
Display display; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
En7V5::reset(); | ||
En7V5::setOutput(); | ||
Reset::reset(); | ||
Reset::setOutput(); | ||
|
||
Cs::setOutput(); | ||
Dc::setOutput(); | ||
MySpiMaster::connect<Sck::Sck, Mosi::Mosi>(); | ||
MySpiMaster::initialize<Board::SystemClock, 660_kHz>(); | ||
|
||
Cs::set(); | ||
En7V5::set(); | ||
modm::delay(500ms); | ||
|
||
Reset::set(); | ||
modm::delay(1ms); | ||
|
||
RF_CALL_BLOCKING(display.initialize()); | ||
RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0)); | ||
RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted)); | ||
RF_CALL_BLOCKING(display.setContrast(80)); | ||
|
||
display.setFont(modm::font::Assertion); | ||
|
||
modm::ShortPeriodicTimer timer(333ms); | ||
uint16_t counter(0); | ||
|
||
while (true) | ||
{ | ||
if (timer.execute()) | ||
{ | ||
display.clear(); | ||
display.setCursor(1, 1); | ||
display << "Hello World!"; | ||
display.setCursor(1,17); | ||
display << counter++; | ||
|
||
display.update(); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<library> | ||
<extends>modm:nucleo-g474re</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_g474re/ssd1306_spi</option> | ||
</options> | ||
<modules> | ||
<module>modm:driver:ssd1306.spi</module> | ||
<module>modm:platform:gpio</module> | ||
<module>modm:platform:spi:1</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...2f4_discovery/display/ssd1306/project.xml → ...discovery/display/ssd1306_i2c/project.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command sequence {
0x10
,0x02
,0xB0 | page
} gets interpreted (at least on my SSD1306 GME12864 module) as three command:1.
0x10
: Set Higher Column Start Address for Page Addressing Mode (10h~1Fh) to value 02.
0x02
Set Lower Column Start Address for Page Addressing Mode (00h~0Fh) to value 23.
0xB0
Set Page Start Address for Page Addressing Mode (B0h~B7h) to valuepage
The first two commands result in the first two columns of display pixels displaying garbage and the last two columns of the frame not getting displayed, so I removed them.
SSD1106 should behave the same way like SH1106 in Page Addressing Mode, but I don't have SH1106 hardware laying arround, so I can't test it. Maybe @TomSaw could check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the hardware test shows:
These lines have a purpose. Whitout, the displays pages (columns of pixels) get ugly shifted.
I remember having read about this necessary micro-management in an adafruit or arduino library comment, not in the datasheet or elsewhere.