Skip to content

Commit 77ba35a

Browse files
committed
[examples] Add SH1106/SSD1306 I2C display example for Nucleo-G474RE
1 parent a06da05 commit 77ba35a

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2023, Raphael Lehmann
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <modm/board.hpp>
12+
#include <modm/driver/display/sh1106_i2c.hpp>
13+
// #include <modm/driver/display/ssd1306_i2c.hpp>
14+
15+
/// SH1106 display in I2C mode
16+
using MyI2cMaster = modm::platform::I2cMaster1;
17+
using Scl = Board::D15;
18+
using Sda = Board::D14;
19+
20+
using Display = modm::Sh1106I2c<MyI2cMaster>;
21+
// using Display = modm::Ssd1306<MyI2cMaster>;
22+
23+
Display display;
24+
25+
int
26+
main()
27+
{
28+
Board::initialize();
29+
30+
modm::delay(100ms);
31+
32+
MyI2cMaster::connect<Sda::Sda, Scl::Scl>();
33+
// Use 20kHz I2C and internal pull-ups, works without external pull-ups
34+
// if the jumper wires are short enought
35+
MyI2cMaster::connect<Sda::Sda, Scl::Scl>(MyI2cMaster::PullUps::Internal);
36+
37+
modm::delay(100ms);
38+
39+
RF_CALL_BLOCKING(display.initialize());
40+
RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0));
41+
RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted));
42+
RF_CALL_BLOCKING(display.setContrast(80));
43+
44+
display.setFont(modm::font::Assertion);
45+
46+
modm::ShortPeriodicTimer timer(333ms);
47+
uint16_t counter(0);
48+
49+
while (true)
50+
{
51+
if (timer.execute())
52+
{
53+
display.clear();
54+
display.setCursor(1, 1);
55+
display << "Hello World!";
56+
display.setCursor(1, 17);
57+
display << counter++;
58+
display.setCursor(1, 33);
59+
display << "Line 3";
60+
display.setCursor(1, 49);
61+
display << "Line 4";
62+
63+
display.update();
64+
}
65+
}
66+
67+
return 0;
68+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<library>
2+
<extends>modm:nucleo-g474re</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_g474re/sh1106_i2c</option>
5+
</options>
6+
<modules>
7+
<module>modm:driver:sh1106.i2c</module>
8+
<module>modm:driver:ssd1306.i2c</module>
9+
<module>modm:platform:gpio</module>
10+
<module>modm:platform:i2c:1</module>
11+
<module>modm:build:scons</module>
12+
</modules>
13+
</library>

0 commit comments

Comments
 (0)