Skip to content

Commit

Permalink
Update signaling to match spec. Fixes #3. (#4)
Browse files Browse the repository at this point in the history
* Fix for #3 (fix pin levels and state to match datasheet)

* Improved example sketch

* Update version to 1.1.4
  • Loading branch information
Andy4495 authored Jul 14, 2024
1 parent 63aa1f5 commit 9d3ff53
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
5 changes: 3 additions & 2 deletions examples/Newhaven_OLED_example/Newhaven_OLED_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Modified 19 May 2015 by Pasquale D'Antini:
https://www.newhavendisplay.com/NHD_forum/index.php?topic=914.0
Further modifications to use "NewhavenOLED" library by Andy4495, Dec 2017 and Jan 2019.
Further modifications to use "NewhavenOLED" library by Andy4495, Dec 2017, Jan 2019, July 2024.
This example code is in the public domain.
*/
Expand Down Expand Up @@ -128,11 +128,12 @@ void oneAtATime() {

void singleUpdate() {
char c = '0';
oled.clear();

for (int i = 0; i < COLUMN_N; i++) {
oled.write(COLUMN_N/2, 0, c++);
delay(100);
}
delay(100);

}
// _______________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NewhavenOLED
version=1.1.3
version=1.1.4
author=Andreas Taylor <[email protected]>
maintainer=Andreas Taylor <[email protected]>
sentence=Library for Newhaven 0216CW and 0220CW OLEDs.
Expand Down
43 changes: 29 additions & 14 deletions src/NewhavenOLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void NewhavenOLED::command(byte c)
digitalWrite(CS_pin, LOW);
}

enable_SCK_MOSI();

byte i = 0; // Bit index

for (i = 0; i < 5; i++)
Expand All @@ -91,6 +93,8 @@ void NewhavenOLED::command(byte c)

send_byte(c); // Transmits the byte

disable_SCK_MOSI();

if (CS_pin != NO_PIN) {
digitalWrite(CS_pin, HIGH);
}
Expand All @@ -111,6 +115,8 @@ void NewhavenOLED::data(byte d)
digitalWrite(CS_pin, LOW);
}

enable_SCK_MOSI();

byte i = 0; // Bit index

for (i = 0; i < 5; i++)
Expand All @@ -127,6 +133,8 @@ void NewhavenOLED::data(byte d)

send_byte(d); // Transmits the byte

disable_SCK_MOSI();

if (CS_pin != NO_PIN) {
digitalWrite(CS_pin, HIGH);
}
Expand Down Expand Up @@ -255,10 +263,8 @@ void NewhavenOLED::begin()
pinMode(CS_pin, OUTPUT);
digitalWrite(CS_pin, HIGH);
}
pinMode(MOSI_pin, OUTPUT);
digitalWrite(MOSI_pin, LOW);
pinMode(SCK_pin, OUTPUT);
digitalWrite(SCK_pin, HIGH);

enable_SCK_MOSI();

cursorC = 0;
cursorR = 0;
Expand Down Expand Up @@ -299,6 +305,9 @@ void NewhavenOLED::begin()
delay(2); // After a clear display, a minimum pause of 1-2 ms is required
command(0x80); // Set DDRAM address 0x00 in address counter (cursor home) (default value)
command(0x0C); // Display ON/OFF control: display ON, cursor off, blink off

disable_SCK_MOSI();

delay(250); // Waits 250 ms for stabilization purpose after display on
}

Expand All @@ -308,20 +317,15 @@ void NewhavenOLED::begin()
void NewhavenOLED::end()
{
command(0x20 | Row_bit); // RE=0 (exit from extended command set), lines #
command(0x08); // display off, cursor off, blink off (default values)
command(0x08); // display off, cursor off, blink off (default values)

// Put control pins in default state
pinMode(MOSI_pin, OUTPUT);
digitalWrite(MOSI_pin, LOW);
pinMode(SCK_pin, OUTPUT);
digitalWrite(SCK_pin, HIGH);
if (CS_pin != NO_PIN) {
pinMode(CS_pin, OUTPUT);
digitalWrite(CS_pin, HIGH);
pinMode(CS_pin, OUTPUT);
}
if (RST_pin != NO_PIN) {
pinMode(RST_pin, OUTPUT);
digitalWrite(RST_pin, HIGH);
pinMode(RST_pin, OUTPUT);
}

}
Expand All @@ -340,9 +344,9 @@ void NewhavenOLED::clock_cycle()
// Note that the Arduino and Energia documentation state that the function
// is only accurate for values of 3us and greater; hence, the delay below
// uses 3 us, even though a 1 us delay would be sufficient.
digitalWrite(SCK_pin, LOW); // Sets LOW the SCLK line of the display
digitalWrite(SCK_pin, HIGH);
delayMicroseconds(3); // Waits >1 us (required for timing purpose)
digitalWrite(SCK_pin, HIGH); // Sets HIGH the SCLK line of the display
digitalWrite(SCK_pin, LOW);
delayMicroseconds(3); // Waits >1 us (required for timing purpose)
}

Expand Down Expand Up @@ -385,3 +389,14 @@ void NewhavenOLED::send_byte(byte tx_b)
clock_cycle();
}
}

void NewhavenOLED::enable_SCK_MOSI() {
pinMode(MOSI_pin, OUTPUT);
digitalWrite(SCK_pin, LOW);
pinMode(SCK_pin, OUTPUT);
}

void NewhavenOLED::disable_SCK_MOSI() {
pinMode(SCK_pin, INPUT);
pinMode(MOSI_pin, INPUT);
}
3 changes: 3 additions & 0 deletions src/NewhavenOLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ class NewhavenOLED {
void clock_cycle();
void send_byte(byte c);
byte row_address[4];
void enable_SCK_MOSI();
void disable_SCK_MOSI();

};
#endif

0 comments on commit 9d3ff53

Please sign in to comment.