Skip to content

Commit 8032724

Browse files
committed
[examples] Add SH1106/SSD1306 I2C display example for Nucleo-G474RE
1 parent 57001dc commit 8032724

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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::initialize<Board::SystemClock, 20_kHz>();
36+
Sda::configure(Sda::InputType::PullUp);
37+
Scl::configure(Sda::InputType::PullUp);
38+
39+
modm::delay(100ms);
40+
41+
RF_CALL_BLOCKING(display.initialize());
42+
RF_CALL_BLOCKING(display.setOrientation(modm::glcd::Orientation::Landscape0));
43+
RF_CALL_BLOCKING(display.setDisplayMode(Display::DisplayMode::Inverted));
44+
RF_CALL_BLOCKING(display.setContrast(80));
45+
46+
display.setFont(modm::font::Assertion);
47+
48+
modm::ShortPeriodicTimer timer(333ms);
49+
uint16_t counter(0);
50+
51+
while (true)
52+
{
53+
if (timer.execute())
54+
{
55+
display.clear();
56+
display.setCursor(1, 1);
57+
display << "Hello World!";
58+
display.setCursor(1, 17);
59+
display << counter++;
60+
display.setCursor(1, 33);
61+
display << "Line 3";
62+
display.setCursor(1, 49);
63+
display << "Line 4";
64+
65+
display.update();
66+
}
67+
}
68+
69+
return 0;
70+
}
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)