Difficulty configuring NHD-0220CW-AB3 for new product

Comments

7 comments

  • Engineering Support
    Community moderator

    Hi Chad, 

    We are currently reviewing your code. Could you please confirm that BS0,BS1,BS2 are all connected to GND since you are interfacing in SPI?

    0
  • Chad S Gephart

    Thank you - I have verified with a multimeter that BS0, BS1, BS2 (pins 17-19) are GND. Unused pins 4-6 and 10-14 are also GND per the datasheet.

    The 5V supply was checked for voltage level and noise with an oscilloscope, no issues. Pin 9 (SDO) is not connected to anything. At power-up, RESET is asserted (low) for 160 milliseconds before going high with the current code.

    I will get 1-2 more displays ordered, just in case there is something wrong with this particular unit.

    Edit: forgot to add - 5V being applied to pins 2 and 3.

    0
  • Engineering Support
    Community moderator

    Hi Chad,

    Thank you for confirming those pins for me. Could you please try the following initialization code? 

      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(0x09);     //extended function set (4‐lines)
      command(0x06);     //COM SEG direction
      command(0x72);     //function selection B
      data(0x40);        //ROM CGRAM selection
      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(5);
      command(0x80);     //set DDRAM address to 0x00
      command(0x0C);     //display ON
      delay(10);        //delay

    0
  • Chad S Gephart

    I have pasted in your initialization code after commenting out the original (and also verified the copy/paste didn't miss anything). The display output has not changed from my earlier photos, with the exception of text moving from right to left instead of left to right (i.e. direction of address auto-incrementing).

    This direction is easily changed with the "//COM SEG direction" command (RE =1), by using 0x07 versus 0x06 - so this is one of the commands that has the expected result. Note that characters are still mirrored.

    Another display is expected here by end of week, so I will test that right away to see if it behaves differently. Thank you!

    0
  • Engineering Support
    Community moderator

    Hi Chad,

    Thank you for trying that. After looking at your code closer it looks like there might be an issue on the command and data functions. Could you try the following functions instead. i have bold the 2 changes.

    void command(unsigned char c)
    {
      unsigned char i, temp;
                  temp = 0xF8;
                  for(i=0;i<8;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((temp&0x80)>>7==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    temp = temp << 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((c&0x01)==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    c = c >> 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    digitalWrite(SDIN, LOW);
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((c&0x01)==0x01)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    c = c >> 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    digitalWrite(SDIN, LOW);
                    digitalWrite(SCLK, HIGH);
                  }
                  delay(2);
    }

    void data(unsigned char d)
    {
      unsigned char i, temp; 
                  temp = 0xFA;
                  for(i=0;i<8;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((temp&0x80)>>7==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    temp = temp << 1;
                    digitalWrite(SCLK, HIGH);
                  }
      
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((d&0x01)==1)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    d = d >> 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    digitalWrite(SDIN, LOW);
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    if((d&0x01)==0x01)
                    {
                      digitalWrite(SDIN, HIGH);
                    }
                    else
                    {
                      digitalWrite(SDIN, LOW);
                    }
                    d = d >> 1;
                    digitalWrite(SCLK, HIGH);
                  }
                  for(i=0;i<4;i++)
                  {
                    digitalWrite(SCLK, LOW);
                    digitalWrite(SDIN, LOW);
                    digitalWrite(SCLK, HIGH);
                  }
                  delay(2);
    }

    0
  • Chad S Gephart

    Much better, thank you! 

    I blindly copied that bug from the example code (link below) and failed to trace it out fully. This is what happens when a hardware engineer writes code.

    https://support.newhavendisplay.com/hc/en-us/articles/4413876825111-NHD-0216MW-0216CW-0220CW-0420CW-with-Arduino

    0
  • Engineering Support
    Community moderator

    Hi Chad,

    I am glad you were able to get it working. Please let us know if you have any other questions

    0

Please sign in to leave a comment.