Author Topic: NHD-0420D3Z-FL-GWB-V3 no I2C code example for Arduino??  (Read 110 times)

yanard

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
NHD-0420D3Z-FL-GWB-V3 no I2C code example for Arduino??
« on: June 07, 2017, 08:24:24 PM »
I am looking for a basic code sample that connects the NHD-0420D3Z-FL-GWB-V3 display to my Arduino Uno using the I2C protocol. There doesn't appear to be one :( I am new so I may have missed it somewhere and any help pointing me in the right direction even if it is to teach me is appreciated.
Thanks

Ted_M

  • Administrator
  • Newbie
  • *****
  • Posts: 7
  • Karma: 1
    • View Profile
Re: NHD-0420D3Z-FL-GWB-V3 no I2C code example for Arduino??
« Reply #1 on: June 08, 2017, 08:50:29 AM »
Here is some example Arduino code for a 2x16 display using I2C that may help to get you started.

/******************************************************
 * Using i2c on NHD 0216KZ3
 * ARDUINO MEGA
 */

#define SCLK 21
#define SDO 20



const char Slave    = 0x50;

const char t1[]=("Newhaven Display");
const char t2[]=("    LINE  2     ");

void I2C_out(unsigned char j){
  int n;
  unsigned char d;
  d=j;
  for(n = 0; n<8; n++){
    if((d&0x80) == 0x80)
      digitalWrite(SDO, HIGH);
    else
      digitalWrite(SDO, LOW);
    d = (d<<1);
    digitalWrite(SCLK, LOW);
    delay(10);
    digitalWrite(SCLK, HIGH);
    delay(5);
    digitalWrite(SCLK, LOW);
    delay(10);
  }
  digitalWrite(SCLK, HIGH);
  delay(1);
  while(SDO ==1){
   
    digitalWrite(SCLK, LOW);
    //delay(1);
    digitalWrite(SCLK, HIGH);
    //delay(1);
   
  }
  digitalWrite(SCLK, LOW);
}
void I2C_Start(){
  digitalWrite(SCLK, HIGH);
  digitalWrite(SDO, HIGH);
  digitalWrite(SDO, LOW);
  digitalWrite(SCLK, LOW);
}

void I2C_Stop(){
  digitalWrite(SDO, LOW);
  digitalWrite(SCLK, LOW);
  digitalWrite(SCLK, HIGH);
  digitalWrite(SDO, HIGH);
}
void disp(const char *text)
{
  int n;
  for(n=0;n<16;n++)
  {
    I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(*text);
    text++;
    I2C_Stop();
    delay(10);
  }
}

void setup() {
  // put your setup code here, to run once:
  pinMode(SDO, OUTPUT);
  pinMode(SCLK, OUTPUT);
  digitalWrite(SCLK, LOW);
  digitalWrite(SDO, LOW);
 
  I2C_Start();
  delay(1);
  I2C_out(0x50);
  delay(1);
 
  delay(10);
  I2C_out(0xFE);
  I2C_out(0x51);
  I2C_Stop();
  delay(100);
  I2C_Start();
  delay(5);
  I2C_out(Slave);
  delay(5);
  I2C_out(0xFE);
  I2C_out(0x46);
  delay(10);
  I2C_Stop();
  delay(100);
  I2C_Start();
  delay(5);
  I2C_out(Slave);
  delay(5);
  I2C_out(0xFE);
  I2C_out(0x47);
 

  delay(100);
  I2C_Stop();
  delay(10);
  I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(0xFE);
    I2C_out(0x52);
    delay(5);
    I2C_out(40);
    delay(5);
    I2C_Stop();
    delay(250);
 
 
}

void loop() {
  unsigned char x = 0x21;
  int i;
  I2C_Start();
  delay(5);
  I2C_out(Slave);
  delay(5);
  I2C_out(0xFE);
  I2C_out(0x51);
  I2C_Stop();
  double a;
  char buff[10];
  a = 2.523;

  sprintf(buff, "%g" , a);
  int n = 0;
  /*
    for (n = 0; n < 8 ; n ++){
      I2C_Start();
  delay(1);
  I2C_out(Slave);
  delay(1);
    I2C_out(buff[n]);
    delay(1);
    I2C_Stop();
    delay(1);
  }
 
  delay (2500);*/
  disp(t1);
  delay(100);

  delay(100);
  I2C_Start();
  delay(5);
  I2C_out(Slave);
  delay(5);
  I2C_out(0xFE);
  I2C_out(0x45);
  //delay(10);
  I2C_out(0x40);
  delay(10);
  I2C_Stop();
  delay(10);
  disp(t2);
  I2C_Stop();
  delay(1000);
  do{
   delay(10);
  for( i = 0 ; i < 50 ; i++){
    I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(0xFE);
    I2C_out(0x52);
    delay(5);
    I2C_out(i);
    delay(5);
    I2C_Stop();
    delay(5);
  }
  int b;
  for( i = 0 ; i < 51 ; i++){
    I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(0xFE);
    I2C_out(0x52);
    delay(5);
    b = 50 - i;
    I2C_out(b);
    delay(5);
    I2C_Stop();
    delay(25);
  }
  }while(1);
  /*for(i = 0; i < 57; i++){
    I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(x);
    x++;
    I2C_Stop();
    delay(10);
  }
// delay(5000);
 
  I2C_Start();
  delay(5);
  I2C_out(Slave);
  delay(5);
  I2C_out(0xFE);
 
  I2C_out(0x51);
  delay(10);

    I2C_out(0xFE);
  I2C_out(0x4B);
  delay(10);
  I2C_out(0xFE);
  I2C_out(0x46);
  delay(10);
  I2C_Stop();
  disp(t1);
  delay(1000);
  for( i = 0 ; i < 50 ; i++){
    I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(0xFE);
    I2C_out(0x52);
    delay(5);
    I2C_out(i);
    delay(5);
    I2C_Stop();
    delay(250);
  }
   I2C_Start();
    delay(5);
    I2C_out(Slave);
    delay(5);
    I2C_out(0xFE);
    I2C_out(0x52);
    delay(5);
    I2C_out(40);
    delay(5);
    I2C_Stop();
    delay(250);
 
  while(1);*/
 
}
« Last Edit: June 08, 2017, 08:58:57 AM by Ted_M »

 

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

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 6947
Last post July 10, 2014, 08:46:06 AM
by Michael_L
Sample Code Question for NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM LCD

Started by SteveCBoard Character LCDs

Replies: 2
Views: 2586
Last post July 31, 2014, 08:44:29 PM
by SteveC
MOVED: 320x240 sunlight readable dispaly to arduino + library

Started by Michael_LBoard Customer Projects

Replies: 0
Views: 1884
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: 2407
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: 2372
Last post March 23, 2016, 03:38:11 PM
by Paul_B