Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
esp8266-oled-ssd1306
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3pb
esp8266-oled-ssd1306
Commits
23baef21
Commit
23baef21
authored
9 years ago
by
Neptune
Browse files
Options
Downloads
Patches
Plain Diff
Added code for SPI version of the display
parent
20af1cae
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SSD1306.cpp
+59
-11
59 additions, 11 deletions
SSD1306.cpp
SSD1306.h
+12
-1
12 additions, 1 deletion
SSD1306.h
with
71 additions
and
12 deletions
SSD1306.cpp
+
59
−
11
View file @
23baef21
...
...
@@ -23,21 +23,48 @@ SOFTWARE.
See more at http://blog.squix.ch
Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
SPI additions by Neptune2
*/
#include
"SSD1306.h"
#include
<Wire.h>
// constructor for I2C - we indicate i2cAddress, sda and sdc
SSD1306
::
SSD1306
(
int
i2cAddress
,
int
sda
,
int
sdc
)
{
myI2cAddress
=
i2cAddress
;
mySda
=
sda
;
mySdc
=
sdc
;
I2C_io
=
true
;
}
// constructor for hardware SPI - we indicate Reset, DataCommand and ChipSelect
// (HW_SPI used to differentiate constructor - reserved for future use)
SSD1306
::
SSD1306
(
bool
HW_SPI
,
int
rst
,
int
dc
,
int
cs
)
{
myRST
=
rst
;
myDC
=
dc
;
myCS
=
cs
;
I2C_io
=
false
;
}
void
SSD1306
::
init
()
{
Wire
.
begin
(
mySda
,
mySdc
);
Wire
.
setClock
(
400000
);
if
(
I2C_io
){
Wire
.
begin
(
mySda
,
mySdc
);
Wire
.
setClock
(
400000
);
}
else
{
pinMode
(
myDC
,
OUTPUT
);
pinMode
(
myCS
,
OUTPUT
);
SPI
.
begin
();
SPI
.
setClockDivider
(
SPI_CLOCK_DIV2
);
pinMode
(
myRST
,
OUTPUT
);
// Pulse Reset low for 10ms
digitalWrite
(
myRST
,
HIGH
);
delay
(
1
);
digitalWrite
(
myRST
,
LOW
);
delay
(
10
);
digitalWrite
(
myRST
,
HIGH
);
}
sendInitCommands
();
resetDisplay
();
}
...
...
@@ -50,7 +77,11 @@ void SSD1306::resetDisplay(void) {
}
void
SSD1306
::
reconnect
()
{
Wire
.
begin
(
mySda
,
mySdc
);
if
(
I2C_io
){
Wire
.
begin
(
mySda
,
mySdc
);
}
else
{
SPI
.
begin
();
}
}
void
SSD1306
::
displayOn
(
void
)
{
...
...
@@ -84,6 +115,8 @@ void SSD1306::display(void) {
sendCommand
(
0x0
);
sendCommand
(
0x7
);
if
(
I2C_io
)
{
for
(
uint16_t
i
=
0
;
i
<
(
128
*
64
/
8
);
i
++
)
{
// send a bunch of data in one xmission
Wire
.
beginTransmission
(
myI2cAddress
);
...
...
@@ -96,8 +129,15 @@ void SSD1306::display(void) {
yield
();
Wire
.
endTransmission
();
}
}
else
{
digitalWrite
(
myCS
,
HIGH
);
digitalWrite
(
myDC
,
HIGH
);
// data mode
digitalWrite
(
myCS
,
LOW
);
for
(
uint16_t
i
=
0
;
i
<
(
128
*
64
/
8
);
i
++
)
{
SPI
.
transfer
(
buffer
[
i
]);
}
digitalWrite
(
myCS
,
HIGH
);
}
}
void
SSD1306
::
setPixel
(
int
x
,
int
y
)
{
...
...
@@ -316,10 +356,18 @@ void SSD1306::drawXbm(int x, int y, int width, int height, const char *xbm) {
}
void
SSD1306
::
sendCommand
(
unsigned
char
com
)
{
Wire
.
beginTransmission
(
myI2cAddress
);
//begin transmitting
Wire
.
write
(
0x80
);
//command mode
Wire
.
write
(
com
);
Wire
.
endTransmission
();
// stop transmitting
if
(
I2C_io
)
{
Wire
.
beginTransmission
(
myI2cAddress
);
//begin transmitting
Wire
.
write
(
0x80
);
//command mode
Wire
.
write
(
com
);
Wire
.
endTransmission
();
// stop transmitting
}
else
{
digitalWrite
(
myCS
,
HIGH
);
digitalWrite
(
myDC
,
LOW
);
//command mode
digitalWrite
(
myCS
,
LOW
);
SPI
.
transfer
(
com
);
digitalWrite
(
myCS
,
HIGH
);
}
}
void
SSD1306
::
sendInitCommands
(
void
)
{
...
...
This diff is collapsed.
Click to expand it.
SSD1306.h
+
12
−
1
View file @
23baef21
...
...
@@ -27,6 +27,8 @@ Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
#pragma once
#include
<Arduino.h>
#include
<Wire.h>
#include
<SPI.h>
#include
"SSD1306Fonts.h"
#define BLACK 0
...
...
@@ -73,9 +75,15 @@ Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
class
SSD1306
{
private:
// I2C
int
myI2cAddress
;
int
mySda
;
int
mySdc
;
bool
I2C_io
;
// SPI
int
myDC
,
myRST
,
myCS
;
uint8_t
buffer
[
128
*
64
/
8
];
int
myTextAlignment
=
TEXT_ALIGN_LEFT
;
int
myColor
=
WHITE
;
...
...
@@ -83,9 +91,12 @@ private:
const
char
*
myFontData
=
ArialMT_Plain_10
;
public:
// Create the display object connected to pin sda and sdc
// Create the display object connected to
I2C pins
pin sda and sdc
SSD1306
(
int
i2cAddress
,
int
sda
,
int
sdc
);
// Create the display object connected to SPI pins and rst, dc and cs (HW_SPI reserved for future use)
SSD1306
(
bool
HW_SPI
,
int
rst
,
int
dc
,
int
cs
);
// Initialize the display
void
init
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment