Author Topic: NHD-0216CW-AB3 and an Arduino Micro  (Read 2192 times)

The Fat Bastid

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
    • View Profile
NHD-0216CW-AB3 and an Arduino Micro
« on: October 29, 2016, 10:10:06 AM »
I'm having some (I think) timing/command issues with the NHD-0216CW-AB3 and an Arduino Micro.

I've attached a pic of the first character cut off on both lines and I'm at a loss.
I have seen different delay times used in various spots, some not having any. As well a different commands used for the same purpose (like 0xC0 vs 0xA0)
I've tried various delays and even commented some out. I don't see much of a difference. I'm a pretty green amateur at this stuff so any help would be greatly appericated!
Here is my code cobbled together from forum posts here, the us2066 git hub, the mouser ino sketch, and the datasheet example:
(try not to laugh at it :P )
Code: [Select]
/*  Setup for parallel 6800 mode
 *  nhd-0216CW-AB3 oled -> Arduino micro rev 3
 *  (us2066 controller)
 * 
 * Data bits
 *     pin - name         port  -  pin
 *      7 (DB0)         - portb 0 (ss pin used as digital 17)
 *      8 (DB1)         - portb 1 (sck pin used as digital 15)
 *      9 (DB2)         - portb 2 (mosi pin used as digital 16)
 *     10 (DB3)         - portb 3 (miso pin used as digital 14)
 *     11 (DB4)         - portb 4 (digital 8)
 *     12 (DB5)         - portb 5 (digital 9)
 *     13 (DB6)         - portb 6 (digital 10)
 *     14 (DB7)         - portb 7 (digital 11)
 * Interface signal select
 *    pin - name         port  -  pin
 *     17 (BS0)         - portd 0 - (digital pin 3) For 6800 8-bit parallel: 0
 *     18 (BS1)         - portd 1 - (digital pin 2)                          0
 *     19 (BS2)         - portd 4 - (digital pin 4)                          1
 * Power supply
 *    pin - name         pin
 *      1 (VSS)        -   GND
 *      2 (VDD)        -   5V
 *      3 (REGVDD)     -   5V
 *      20 (VSS)       -   GND
 * Operation signals
 *    pin - name
 *      4 - D/C         - portf 0 (analog pin A5)
 *      5 - R/W         - portf 1 (analog pin A4)
 *      6 - E           - portf 4 (analog pin A3)
 *      15 - /CS        - portf 5 (analog pin A2)
 *      16 - /RES       - porff 6 (analog pin A1)
 *
 *Unused pins
 *                      -  portd 3 (digital pin 1) (tx)
 *                      -  portd 2 (digital pin 2) (rx)
 *                      -  portc 6 (digital pin 5)
 *                      -  portd 7 (digital pin 6)
 *                      -  porte 6 (digital pin 7)
 *                      -  portd 6 (digital pin 12)
 *                      -  portc 7 (digital pin 13)
 *                      -  portf 7 (analog pin A0)
  */
 
void setup() {
  //B76543210 - most -> least
  //DDRX sets output/input
  //PORTX sets high/low
  DDRD = B00010011; // bs2, bs1, bs0 are outputs.
  DDRB = 0xFF; //Port b set to all output
  DDRF = B01110011; // /res, /cs, e , r/w, d/c
  PORTD = B00010000; // bs2 high, bs1 low, bs0 low: 6800 parallel 8-bit
  PORTF = B01000000; // /res high (don't reset), /cs low (only 1 display), E, R/W low (always write), D/C
  PORTB = 0x00;
  delay(10);          //delay
  command(0x2A);     //function set (extended command set)
  command(0x71);     //function selection A
  data(0x5C);        // Set 5V on REGVDD
  command(0x28);     //function set (fundamental command set)
  command(0x08);     //display off, cursor off, blink off
  command(0x2A);     //function set (extended command set)
  command(0x79);     //OLED command set enabled 
  command(0xD5);     //set display clock divide ratio/oscillator frequency
  command(0x70);     //set display clock divide ratio/oscillator frequency
  command(0x78);     //OLED command set disabled
  command(0x08);     //extended function set (2‐lines)
  command(0x06);     //COM SEG direction
  command(0x72);     //function selection B
  data(0x01);        //ROM CGRAM selection (40? 00?)
  command(0x2A);     //function set (extended command set)
  command(0x79);     //OLED command set enabled
  command(0xDA);     //set SEG pins hardware configuration
  command(0x10);     //set SEG pins hardware configuration
  command(0xDC);     //function selection C
  command(0x00);     //function selection C
  command(0x81);     //set contrast control
  command(0x7F);     //set contrast control
  command(0xD9);     //set phase length
  command(0xF1);     //set phase length
  command(0xDB);     //set VCOMH deselect level
  command(0x40);     //set VCOMH deselect level
  command(0x78);     //OLED command set disabled
  command(0x28);     //function set (fundamental command set)
  command(0x01);     //clear display
  delay(2);
  command(0x80);     //set DDRAM address to 0x00
  command(0x0C);     //display ON
  delay(100);        //delay

unsigned char text5[] = {"Newhaven Display"};
unsigned char text6[] = {" 2X16 Character "};
unsigned char text7[] = {"  Slim  Design  "};
unsigned char text8[] = {"0123456789abcdef"};
void loop() {
        command(0x01); //clear display
        delay(2);
        command(0x02); //return home
        for(int i = 0; i < 16; i++){
          data(text5[i]);
        }
       
        command(0xC0); //
        for(int i = 0; i < 16; i++){
          data(text6[i]);
        }
        delay(2000);

        command(0x01);//clear display
        delay(2);
        command(0x02); //return home
        for(int i = 0; i < 16; i++){
          data(text7[i]);
        }
        command(0xC0);
        for(int i = 0; i < 16; i++){
          data(text8[i]);
        }
        delay(2000);
}

void command(unsigned char c){  //To send commands
   PORTB = c;                   //command on port
   PORTF &= B11111110;         //D/C set to LOW for command
   PORTF &= ~B00010000;         //e high
   delay(1);
   PORTF |= B00010000;          //e low
}

void data(unsigned char d){    //To send data
   PORTB = d;                  //data on port
   PORTF |= B00000001;         //d/c high for data
   PORTF &= ~B00010000;        //e high
   delay(1);
   PORTF |= B00010000;         //e low
}

https://www.arduino.cc/en/Main/ArduinoBoardMicro
Thanks for any help!
« Last Edit: October 30, 2016, 11:27:20 PM by The Fat Bastid »

The Fat Bastid

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
    • View Profile
Re: NHD-0216CW-AB3 and an Arduino Micro
« Reply #1 on: November 01, 2016, 08:36:16 PM »
Got it working.
My first attempt I didn't use ports at all, got garbage output (used bitread to feed the data lines)
Found a post on here that recommend nothing but port registers. Faster? ok sounds good.
Finally remebered to try port register data and directwrite on everything else.
and bam. perfect output now.

Paul_B

  • Administrator
  • Sr. Member
  • *****
  • Posts: 248
  • Karma: 16
    • View Profile
Re: NHD-0216CW-AB3 and an Arduino Micro
« Reply #2 on: November 02, 2016, 10:10:05 AM »
Glad to hear you are up and running!

The Fat Bastid

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
    • View Profile
Re: NHD-0216CW-AB3 and an Arduino Micro
« Reply #3 on: November 02, 2016, 10:24:41 AM »
Oh, I forgot the 'why' part.
The full timing cycle (tCYCLE) is 400ns.
 Port register manipulation is a lot faster than directwrite. (250ns vs 70042ns)
So,it would need timing delays to get it work right.

 

Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 8843
Last post July 10, 2014, 08:46:06 AM
by Michael_L
MOVED: 320x240 sunlight readable dispaly to arduino + library

Started by Michael_LBoard Customer Projects

Replies: 0
Views: 2447
Last post October 23, 2015, 11:45:28 AM
by Michael_L
320x240 sunlight readable dispaly to arduino + library

Started by vonz66Board Graphic LCDs

Replies: 1
Views: 3058
Last post October 23, 2015, 11:46:04 AM
by Michael_L
Wiring connectiond between NHD-1.69-160128ASC3 SSD1351 and Arduino Nano

Started by amitkumarsharma008Board OLEDs

Replies: 3
Views: 3064
Last post March 23, 2016, 03:38:11 PM
by Paul_B
NHD-0420D3Z-NSW-BBW-V3 i2c display and Arduino missing characters

Started by 0miker0Board Character LCDs

Replies: 0
Views: 658
Last post July 06, 2017, 11:05:59 AM
by 0miker0