Newhaven Display Forum

Newhaven Products => Character LCDs => Topic started by: SteveS on August 15, 2014, 05:56:47 AM

Title: I2C on NHD-C0216CiZ-FSW-FBW-3V3
Post by: SteveS on August 15, 2014, 05:56:47 AM
I am interfacing a NHD-C0216CiZ-FSW-FBW-3V3 serial I2C display to an Intel Galileo Arduino (set to 3.3V operation) but have not been ale to get any response from the display. In order to reduce the variables on what could be going wrong, does anyone have suitable sample code for this 2 wire serial interface - eg to initalise and write something on the screen?
Thanks,
Steve
Title: Re: I2C on NHD-C0216CiZ-FSW-FBW-3V3
Post by: Michael_L on August 15, 2014, 10:33:53 AM
I have some Arduino code for this display below:

Code: [Select]
#include <Wire.h>

int RES = 22;
int ASDA = 20;
int ASCL = 21;

int test = 55;

unsigned char text1[]={"Newhaven Display"};
unsigned char text2[]={"    I2C TEST    "};
unsigned char text3[]={" March 21 2014  "};
unsigned char text4[]={" Michael LaVine "};

const char slave2w = 0x3E;  //3E for CiZ (0x7C shifted over 1 bit)  //3C for BiZ (0x78 shifted over 1 bit)
const char comsend = 0x00;
const char datasend = 0x40;
const char line2 = 0xC0;

void show(unsigned char *text)
{
  int n, d;
  d=0x00;
  Wire.beginTransmission(slave2w);
  Wire.write(datasend);
  for(n=0;n<16;n++)
  {
    Wire.write(*text);
    ++text;
  }
  Wire.endTransmission();
}

void nextline(void)
{
  Wire.beginTransmission(slave2w);
  Wire.write(comsend);
  Wire.write(line2);
  Wire.endTransmission();
}

void CGRAM(void)
{
  Wire.beginTransmission(slave2w);
  Wire.write(comsend);
  Wire.write(0x38);
  Wire.write(0x40);
  Wire.endTransmission();
  delay(10);
  Wire.beginTransmission(slave2w);
  Wire.write(datasend);
  Wire.write(0x00);
  Wire.write(0x1E);
  Wire.write(0x18);
  Wire.write(0x14);
  Wire.write(0x12);
  Wire.write(0x01);
  Wire.write(0x00);
  Wire.write(0x00);
  Wire.endTransmission();
}

void CiZ_init()
{
  Wire.beginTransmission(slave2w);
  Wire.write(comsend);
  Wire.write(0x38);
  delay(10);
  Wire.write(0x39);
  delay(10);
  Wire.write(0x14);
  Wire.write(0x70);
  Wire.write(0x5E);
  Wire.write(0x6D);
  Wire.write(0x0C);
  Wire.write(0x01);
  Wire.write(0x06);
  Wire.endTransmission();
 
  CGRAM();
 
  Wire.beginTransmission(slave2w);
  Wire.write(comsend);
  Wire.write(0x39);
  Wire.write(0x01);
  test = Wire.endTransmission();
  Wire.endTransmission();
  if(test!=0)
  {
    while(1)
    {
      delay(100);
    }
  }
  delay(10);
}

void setup()
{
  pinMode(RES, OUTPUT);
  pinMode(ASCL, OUTPUT);
  pinMode(ASDA, OUTPUT);
  digitalWrite(RES, HIGH);
  delay(10);
  digitalWrite(ASCL, LOW);
  digitalWrite(ASDA, LOW);
  delay(10);
 
  delay(10);
  //CiZ_init();
  //delay(5);
}

void loop()
{
 
  Wire.begin();
  //TWBR = 12;
  //TWSR |= _BV(TWPS0);
  while(1)
  {
  CiZ_init();
  show(text1);
  nextline();
  show(text2);
  delay(1000);
 
  CiZ_init();
  show(text3);
  nextline();
  show(text4);
  delay(1000);
  }
}
Title: Re: I2C on NHD-C0216CiZ-FSW-FBW-3V3
Post by: SteveS on August 19, 2014, 05:37:31 AM
Thanks for your help Michael - I will give it a try.
Regards,
Steve