Newhaven Products > Graphic LCDs

NHD-C12864B2Z-RN-FBW Arduino Uno

(1/2) > >>

simonp54:
Hello again...
After this board has had all its content dropped, I thought I should post again to see if you can help me further.
As you know I am struggling to get this screen to work.  I am now using an I2C I/O expander and two 4050 chips to do the logic conversion to 3.3V I have debugged the outputs using LEDs and I am confident that the code which I attach is sending the correct stuff to the interface (through a NHD-FFC28).  I have checked and double checked everything and still I get nothing from the screen.  When I test without the screen connected it all looks correct, when the screen is inserted into the FFC28 the LEDs dont flash the same way at all...
I am using capacitors from Farnell part number (8126933).

Code is as follows:

--- Code: ---#include <Wire.h>

#define IO_I2C_ADDR 0x20
#define IO_DIRA_REG 0x00
#define IO_DIRB_REG 0x01
#define IO_ALL_OUTPUTS 0x00
#define IO_ALL_INPUTS 0xFF
#define IO_ADDR_PORT_A 0x12
#define IO_ADDR_PORT_B 0x13

#define RD_PIN 4
#define WR_PIN 3
#define A0_PIN 2

void writeCom(byte bits)
{
  digitalWrite( A0_PIN, LOW );     // A0 - set LOW
  digitalWrite( RD_PIN, HIGH );    // aka E - set HIGH
  digitalWrite( WR_PIN, LOW );     // aka RW - set LOW

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(bits);
  Wire.endTransmission();

  digitalWrite( RD_PIN, LOW );    // aka E - set LOW
  digitalWrite( WR_PIN, LOW );    // aka RW - set LOW
}

void writeData(byte bits)
{
  digitalWrite( A0_PIN, HIGH );    // A0 - set HIGH
  digitalWrite( WR_PIN, LOW );     // aka RW - set LOW
  digitalWrite( RD_PIN, HIGH );    // aka E - set HIGH
 
  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(bits);
  Wire.endTransmission();
 
  digitalWrite( RD_PIN, LOW );    // aka E - set LOW
  digitalWrite( WR_PIN, LOW );    // aka RW - set LOW
}



void initScreen()
{
  digitalWrite( WR_PIN, LOW );      // aka RW - set RW to LOW
  digitalWrite( A0_PIN, LOW );      // aka RS - set RS to LOW
                                    // RESTB ?aka RST? - wired to VDD
                                    // CS1B - wired to VSS
  digitalWrite( RD_PIN, LOW );      // aka E - set E to LOW
  delay(22);                        //wait 22ms

  writeCom( 0xA2 );    // 1/9 bias
  writeCom( 0xA0 );    // ADC SELECT NORMAL
  writeCom( 0xC8 );    // COM OUTPUT REVERSE
  writeCom( 0xA4 );    // DISPLAY ALL POINTS NORMAL
  writeCom( 0x40 );    // DISPLAY START LINE SET
  writeCom( 0x25 );    // INTERNAL RESISTOR RATIO
  writeCom( 0x81 );    // ELECTRONIC VOLUME MODE SET
  writeCom( 0x10 );    // ELECTRONIC VOLUME
  writeCom( 0x2F );    // POWER CONTROLLER SET
  writeCom( 0xAF );    // DISPLAY ON
}

//***************************************************
//The setup() function is called
//when a sketch starts. Use it to
//initialize variables, pin modes,
//start using libraries, etc. The
//setup function will only run once,
//after each powerup or reset of the Arduino board.
//***************************************************
void setup()
{
  Serial.begin(9600);

  Wire.begin();

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_DIRA_REG);              // IDDIRA register
  Wire.write(IO_ALL_OUTPUTS);              // set all port A to outputs
  Wire.endTransmission();

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_DIRB_REG);              // IDDIRB register
  Wire.write(IO_ALL_OUTPUTS);              // set all port B to outputs
  Wire.endTransmission();
 
  pinMode( WR_PIN, OUTPUT );    // aka RW
  pinMode( A0_PIN, OUTPUT );    // aka RS
  pinMode( RD_PIN, OUTPUT );    // aka E
 
  initScreen(); 
}


//***************************************************
//the loop() function does precisely what its name suggests,
//and loops consecutively, allowing your program to change
//and respond. Use it to actively control the Arduino board.
//***************************************************
void loop()
{
  writeCom( B10100110 );
  delay(1000);
  writeCom( B10100111 );
  delay(1000);
}
--- End code ---

Michael_L:
I noticed you are using an i2c interface, and I just want to make sure you know this display only has a parallel interface.  I see you mentioned you are using an i2c I/O expander, so I will assume this is converting your i2c data into 8 separate bits and putting the byte on the display's data bus.  If this is the case, then when I looked at your code I noticed you are using 6800 mode protocol for the parallel interface, when this display is actually only 8080 mode.  You will need to modify your write command/data functions to correct this.  I actually have some Arduino code for our NHD-C12864KGZ display, which uses the same controller.  The code will work for the display you are using too, but more importantly, you can use it as reference to correctly write commands and data in your software.


--- Code: ---//---------------------------------------------------------
/*
NHD_C12864KGZ_mega.ino
Program for writing to Newhaven Display 128x64 COG graphic LCD with ST7565R controller

(c)2013 Mike LaVine - Newhaven Display International, LLC.

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
*/
//---------------------------------------------------------

// The 8 bit data bus is connected to PORTA of the Arduino Mega2560
// 5V voltage regulator on Arduino Mega has been replaced with a 3.3V regulator to provide 3.3V logic

int RS = 30;      // RS (A0) signal connected to Arduino digital pin 30
int WR = 31;      // /WR signal connected to Arduino digital pin 31
int RD = 32;      // /RD signal connected to Arduino digital pin 32
int RES = 33;     // /RES signal connected to Arduino digital pin 33

// /CS signal tied to GND

void comm_out(unsigned char c)
{
  digitalWrite(RS, LOW);      //A0 = L = command
  PORTA = c;
  digitalWrite(WR, LOW);
  digitalWrite(WR, HIGH);
}

void data_out(unsigned char d)
{
  digitalWrite(RS, HIGH);     //A0 = H = data
  PORTA = d;
  digitalWrite(WR, LOW);
  digitalWrite(WR, HIGH);
}
void disp()
{
unsigned int i, j;
        unsigned char page=0xB0;
for(i=0;i<8;i++)           //fill display with checkerboard pattern
{
            comm_out(0x10);        //set column address
            comm_out(0x00);        //set column address
    comm_out(page);        //set page address
            for(j=0;j<64;j++)
            {
               data_out(0xAA);
               data_out(0x55);
            }
            page++;
}
}

void setup()
{
  DDRC = 0xFF;         //set PORTC (control signals) as output
  PORTC = 0x00;
  DDRA = 0xFF;         //set PORTA (data signals) as output
  PORTA = 0x00;
  digitalWrite(RD, HIGH);
  digitalWrite(WR, HIGH);
  digitalWrite(RES, LOW);
  delay(150);
  digitalWrite(RES, HIGH);
  delay(150);
 
  comm_out(0xA2);      //added 1/9 bias
 
  comm_out(0xA0);      //ADC segment driver direction (A0=Normal)
 
  comm_out(0xC0);      //COM output scan direction (C0=Normal)
 
  comm_out(0x25);      //resistor ratio
 
  comm_out(0x81);      //electronic volume mode set
 
  comm_out(0x15);      //electronic volume register set
 
  comm_out(0x2F);      //operating mode
 
  comm_out(0x40);      //start line set
 
  comm_out(0xAF);      //display ON
 
  delay(10);
}

void loop()
{
  disp();
  delay(1000);
}
--- End code ---

simonp54:
Hi Michael,

Thanks for the response and code.. Yes I know its parallel, and the IO expander I am using is designed to do just this kind of update of all the pins at the same time... so we are ok there.

my code now looks like this
--- Code: ---#include <Wire.h>

#define IO_I2C_ADDR 0x20
#define IO_DIRA_REG 0x00
#define IO_DIRB_REG 0x01
#define IO_ALL_OUTPUTS 0x00
#define IO_ALL_INPUTS 0xFF
#define IO_ADDR_PORT_A 0x12
#define IO_ADDR_PORT_B 0x13

#define RES_PIN 5
#define RD_PIN 4
#define WR_PIN 3
#define A0_PIN 2

void writeCom(byte bits)
{
  digitalWrite( A0_PIN, LOW );     // A0 - set LOW

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(bits);
  Wire.endTransmission();

  digitalWrite( WR_PIN, LOW );    // aka RW - set LOW
  digitalWrite( WR_PIN, HIGH );    // aka RW - set LOW
}

void writeData(byte bits)
{
  digitalWrite( A0_PIN, HIGH );    // A0 - set HIGH
 
  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(bits);
  Wire.endTransmission();
 
  digitalWrite( WR_PIN, LOW );    // aka RW - set LOW
  digitalWrite( WR_PIN, HIGH );    // aka RW - set LOW
}



void initScreen()
{
  digitalWrite( RD_PIN, HIGH );      // aka E - set E to HIGH
  digitalWrite( WR_PIN, HIGH );      // aka RW - set RW to HIGH
  digitalWrite( RES_PIN, LOW );
  delay(150);
  digitalWrite( RES_PIN, HIGH );
  delay(150);
 
  writeCom( 0xA2 );    // 1/9 bias
  writeCom( 0xA0 );    // ADC SELECT NORMAL
  writeCom( 0xC0 );    // COM OUTPUT NORMAL
  writeCom( 0x25 );    // INTERNAL RESISTOR RATIO
  writeCom( 0x81 );    // ELECTRONIC VOLUME MODE SET
  writeCom( 0x15 );    // ELECTRONIC VOLUME
  writeCom( 0x2F );    // POWER CONTROLLER SET
  writeCom( 0x40 );    // DISPLAY START LINE SET
  writeCom( 0xAF );    // DISPLAY ON
 
  delay(10);
}

void disp()
{
unsigned int i, j;
        unsigned char page=0xB0;
for(i=0;i<8;i++)           //fill display with checkerboard pattern
{
            writeCom(0x10);        //set column address
            writeCom(0x00);        //set column address
    writeCom(page);        //set page address
            for(j=0;j<64;j++)
            {
               writeData(0xAA);
               writeData(0x55);
            }
            page++;
}
}


//***************************************************
//The setup() function is called
//when a sketch starts. Use it to
//initialize variables, pin modes,
//start using libraries, etc. The
//setup function will only run once,
//after each powerup or reset of the Arduino board.
//***************************************************
void setup()
{
  Serial.begin(9600);

  Wire.begin();

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_DIRA_REG);              // IDDIRA register
  Wire.write(IO_ALL_OUTPUTS);              // set all port A to outputs
  Wire.endTransmission();

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_DIRB_REG);              // IDDIRB register
  Wire.write(IO_ALL_OUTPUTS);              // set all port B to outputs
  Wire.endTransmission();
 
  pinMode( WR_PIN, OUTPUT );    // aka RW
  pinMode( A0_PIN, OUTPUT );    // aka RS
  pinMode( RD_PIN, OUTPUT );    // aka E
  pinMode( RES_PIN, OUTPUT );   // aka RESTB
 
  initScreen(); 
}


//***************************************************
//the loop() function does precisely what its name suggests,
//and loops consecutively, allowing your program to change
//and respond. Use it to actively control the Arduino board.
//***************************************************
void loop()
{
  disp();
  delay(10000);
}
--- End code ---

But still no joy.
Brings me back to my original question about checking the power supply is operating correctly???

Michael_L:
The code that I sent you is working code, I tested it this morning to be 100% certain.  Therefore, the problem should not lie within your software.  As for your power supply concern, what exactly do you mean?  I assume you are powering the display with 3.3V, and all 9 capacitors are in the appropriate places and soldered properly (this can be seen on page 4 of the datasheet).  Are you making sure to align the display's FFC cable to whatever side of the NHD-FFC28 you are using as pin 1?  The display is 27-pin, and the breakout board is 28, so you need to be very careful ensuring it is aligned in the connector properly.

If all of the above is verified to be correct, and your connections are all correct, then the only other thing to troubleshoot would be your I/O expander and level shifters.  Since you are using the Arduino, could you try using the Arduino's parallel port instead?  It would be PORTD[7..0], (digital pins [7..0]).  I am trying to eliminate any possible causes of error from your setup, since the code is verified to be correct.

simonp54:
Hey Michael, just before anything else... I appreciate the help and I am very pleased with your responses so far.  I am however a bit disappointed with the misleading information in the Datasheet document (particularly the example code applying to a scheme that the device doesnt support 8080 vs 6800 i just followed the example thinking it was right and the commented out little bits didn't make that any easier either)...

To answer your question, I have rechecked all the wiring and I have been very aware of the 27 vs 28 pin issue and also if you remember emailed you on the orientation of the connector which I understand is "pins" down towards the board...  (btw yes have offset the ribbon to pin 2 - 28, and checked all connections again).

I had written a long number of questions.... but as I have now got the code and screen working!!!!! I don't need them answered.

The problems were two fold..

1) I hadn't level shifted the control lines... only the DB0-7 lines.... DOH
2) I was debugging the "on off" states of the pins by putting LEDs on the driven side of the level shifter... this dragged the voltages down to an unacceptable level for them to be considered "HIGH" etc...

Thanks so much for all the help... are there any "low level" functions that I can grab to drive the screen to do simple tasks like fill an area (rectangle) etc...  and write text on it????
THANKS again.

and for anyone else...

--- Code: ---// this code expects an IO expander (MCP23017) on the I2C bus at address 0x20
// two level shifters (74HC4050) are used to migrate the levels from 5v to 3.3v
// pins for the control lines are self explanitory

#include <Wire.h>

#define IO_I2C_ADDR 0x20
#define IO_DIRA_REG 0x00
#define IO_DIRB_REG 0x01
#define IO_ALL_OUTPUTS 0x00
#define IO_ALL_INPUTS 0xFF
#define IO_ADDR_PORT_A 0x12
#define IO_ADDR_PORT_B 0x13

#define RES_PIN 5
#define RD_PIN 4
#define WR_PIN 3
#define A0_PIN 2

void writeCom(byte bits)
{
  digitalWrite( A0_PIN, LOW );     // A0 - set LOW

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(bits);
  Wire.endTransmission();

  digitalWrite( WR_PIN, LOW );    // aka RW - set LOW
  digitalWrite( WR_PIN, HIGH );    // aka RW - set HIGH
}

void writeData(byte bits)
{
  digitalWrite( A0_PIN, HIGH );    // A0 - set HIGH
 
  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(bits);
  Wire.endTransmission();
 
  digitalWrite( WR_PIN, LOW );    // aka RW - set LOW
  digitalWrite( WR_PIN, HIGH );    // aka RW - set HIGH
}



void initScreen()
{
  digitalWrite( RD_PIN, HIGH );      // aka E - set E to HIGH
  digitalWrite( WR_PIN, HIGH );      // aka RW - set RW to HIGH
  digitalWrite( RES_PIN, LOW );      // reset pin set LOW
  delay(150);
  digitalWrite( RES_PIN, HIGH );     // reset pin set HIGH
  delay(150);
 
  writeCom( 0xA2 );    // 1/9 bias
  writeCom( 0xA0 );    // ADC SELECT NORMAL
  writeCom( 0xC0 );    // COM OUTPUT NORMAL
  writeCom( 0x25 );    // INTERNAL RESISTOR RATIO
  writeCom( 0x81 );    // ELECTRONIC VOLUME MODE SET
  writeCom( 0x15 );    // ELECTRONIC VOLUME
  writeCom( 0x2F );    // POWER CONTROLLER SET
  writeCom( 0x40 );    // DISPLAY START LINE SET
  writeCom( 0xAF );    // DISPLAY ON
 
  delay(10);
}

void disp()
{
unsigned int i, j;
        unsigned char page=0xB0;
for(i=0;i<8;i++)           //fill display with checkerboard pattern
{
            writeCom(0x10);        //set column address
            writeCom(0x00);        //set column address
    writeCom(page);        //set page address
            for(j=0;j<64;j++)
            {
               writeData(0xAA);
               writeData(0x55);
            }
            page++;
}
}


//***************************************************
//The setup() function is called
//when a sketch starts. Use it to
//initialize variables, pin modes,
//start using libraries, etc. The
//setup function will only run once,
//after each powerup or reset of the Arduino board.
//***************************************************
void setup()
{
  Serial.begin(9600);

  Wire.begin();

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_DIRA_REG);              // IDDIRA register
  Wire.write(IO_ALL_OUTPUTS);              // set all port A to outputs
  Wire.endTransmission();

  Wire.beginTransmission(IO_I2C_ADDR);
  Wire.write(IO_ADDR_PORT_A);              // address port A
  Wire.write(0x00);
  Wire.endTransmission();
 
  pinMode( WR_PIN, OUTPUT );    // aka RW
  pinMode( A0_PIN, OUTPUT );    // aka RS
  pinMode( RD_PIN, OUTPUT );    // aka E
  pinMode( RES_PIN, OUTPUT );   // aka RESTB

  digitalWrite( WR_PIN, LOW );
  digitalWrite( A0_PIN, LOW );
  digitalWrite( RD_PIN, LOW );
  digitalWrite( RES_PIN, LOW );
 
  initScreen(); 
}


//***************************************************
//the loop() function does precisely what its name suggests,
//and loops consecutively, allowing your program to change
//and respond. Use it to actively control the Arduino board.
//***************************************************
void loop()
{
  disp();
  delay(1000);
}
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version