Trying to use Newhaven display on ESP32 with the Arduino IDE

I know the subject line is not very specific, but let me expand.

I wish to use the Newhaven NHD_0216AW_XB3 (US2066 driver chip with I2C interface) display on an ESP32 (or maybe ESP8266 if that is easer).

I know Newhaven provide an Arduino library (based on the Mega chip). However, that is very low-level and directly “bit-twiddles” the Mega registers.

My question is in two parts:
Does anyone know of a US2066 library for the ESP32> Or…
Is there a shim or wrapper that can “elevate” the <avr/io.h> references within the Newhaven library to make it of any use to the ESP32?

Regards, ~Martin

There seems to be code on GitHub - NewhavenDisplay/NHD_US2066: This is a library for our Slim Monochrome OLEDs based on US2066 controller.

You have only got to edit the H file to match the GPIO pin numbers on your ESP32


You have only got to edit the H file to match the GPIO pin numbers on your ESP32

Thanks Dave,

Unfortunately, I don't think that it is that simple? The Newhaven sample code refers to the ATMega control ports. How would these map? For example, looking at a few lines from the Newhaven .cpp:

178 void init_oled()
179 {
180  pinMode(ASCL, OUTPUT);      //set Arduino I2C lines as outputs
181  pinMode(ASDA, OUTPUT);      //
182  digitalWrite(ASCL, LOW);    //
183  digitalWrite(ASDA, LOW);    //

//     removed for brevity...

189  DDRA = 0xFF;
190  PORTA = 0x00;
191  DDRC = 0xFF;
192  PORTC = 0x00;

Irrespective of the values, as long as the variable like ASCL & ASDA have a value (as they do), the .ino will compile (but of course will not work). So editing the Newhaven .H file to change, say, ASDA (line 180) from 21 for the Mega, to 22 for the ESP32 is certainly required. But my problem is the the control registers.

There is no resolution to the variables like DDRA, PORTA & PORTC (lines 189-192). As I understand it ,in the AVR processors, these are resolved via the avr/io.h file but that header file is not relevant to the ESP32/8266 world.

Or am I just overcomplicating the issue? Am I overlooking an obvious solution?

Regards, ~Martin

PORTC, DDRC don't seem to be used.

6800-8 parallel interface uses PORTA. You just need to replace with 8 pinMode() and digitalWrite()
I2C uses Wire.h
SPI uses SPI.h

Personally, I would choose the interface at the design stage. I2C would be wise.

I have not got your display. I am sure that Aunty Google would find something for you.

Think about it. Most I2C display controllers follow the same sequence for User commands and data.
The "Manufacturer commands" will differ e.g. setting contrast, voltage generation, scanning, ...


Thank you David,

Good advice. Looking at the .cpp file again with your thoughts in mind, I can see that the code covers all three interfaces to cope with the different models. As I have the NHD-0216AW-IB3 (the -IB3 is the I2C variant), I have REM'd out the references to the 8-bit and SPI interfaces. And as you have pointed out the port references are only needed for the 8-bit mode.

So to cut a long-story-short.... I'm up and working. ESP32 & ESP8266 talking to the Newhaven display and coded in the Arduino IDE.

Result, ~Martin

The CPP file reduces to a few lines.
The H file reduces to external function declarations.

I think you will find that most I2C controllers will be the same.
You just alter the init_oled() function to Wire.begin() with the appropriate command() sequence.

Having reduced the code to command(), data(), init() you can put a C++ class around it.
Then use it like all the other Arduino Character LCD libraries.