Author Topic: Help Getting ArduinoPro Mini 3.3V and NHD-C12864A1Z-FSW-FBW-HTT to work via SPI  (Read 1421 times)

dalemoore

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
I have scoured this forum and the example code provided by NewHaven for longer than I'd like to admit and I'm unable to get the titled graphic LCD working with an ArduinoPro Mini 3.3V.

I'm using SPI to communicate with the LCD.  At one time, I was able to turn on all of the pixels (so I know the device is working), but I couldn't control individual pixels.  I've since stitched together, what I hope, is a simple to read program from the various posts on this forum as well as NewHaven's examples.  Ideally, I'd just like to see something appear on the LCD that I actually put there and I think I can figure out the rest. 

My Arduino to LCD pin connections are as follows (I've used the standard Arduino SPI connections to avoid problems).
PIN Connections
  • Arduino PIN 10 (CS or SS) connected to PIN 6 on display
  • Arduino PIN 11 (MOSI) connected to PIN 2 on display
  • Arduino PIN 12 (MISO) not used
  • Arduino PIN 13 (SCK or CLOCK) connected to PIN 1 on display
  • Arduino PIN VCC connected to PIN 3 and 7 on display for + power
  • Arduino PIN 8 connected to PIN 5 (RESET) on display.  Set to LOW to reset the display
  • Arduino PIN 9 connected to PIN 4 (A0) on display for register selector (0:instruction, 1:data)
  • Arduino PIN GND connected to PINs (7 and 10) for grounds

The Arduino is connected to my computer's USB port through an FTDI Basic (Sparkfun).  I've done other Arduino projects in this manner, including SPI communications, and haven't had any issues.

Here's the code that I've been working with.  Like I mentioned, anything that jumps out to anyone as a potential problem I would really love to hear.  Thank you.

Code: [Select]
#include <SPI.h>
// PIN Connections
// Arduino PIN 10 (CS or SS) connected to PIN 6 on display
// Arduino PIN 11 (MOSI) connected to PIN 2 on display
// Arduino PIN 12 (MISO) not used
// Arduino PIN 13 (SCK or CLOCK) connected to PIN 1 on display
// Arduino PIN VCC connected to PIN 3 and 7 on display for + power
// Arduino PIN 8 connected to PIN 5 (RESET) on display.  Set to LOW to reset the display
// Arduino PIN 9 connected to PIN 4 (A0) on display for register selector (0:instruction, 1:data)
// Arduion PIN GND connected to PINs (7 and 10) for grounds
#define RESET       8 
#define AZERO       9 
                       
int loopCounter = 0;  // used for debugging

void setup() { 
  // Open the serial debugging port
  Serial.begin(115200); 
  Serial.println("Begin LCD test"); 
  // initialize pin configurations on Arduino
  pinMode(MOSI, OUTPUT);
  pinMode(MISO, INPUT);
  pinMode(SS,OUTPUT);
  pinMode(RESET, OUTPUT); 
  pinMode(AZERO, OUTPUT); 
  // Reset the LCD
  digitalWrite(SS, LOW);      // enable the device
  digitalWrite(RESET, LOW);   // reset active   
  digitalWrite(RESET, HIGH);  // reset inactive
  delay(1000); 
  digitalWrite(SS, HIGH);  // disable the device
  // Start API communications   
  SPI.begin(); 
  SPI.setClockDivider(SPI_CLOCK_DIV128);  // Slowest speed
  SPI.setBitOrder(MSBFIRST);
  delay(200); 
  // Send instructions to LCD for setup
  initializeLcd();
  delay(50); 
}

void writeCommand(char bits) {
  digitalWrite(SS,LOW);    // chip select 
  digitalWrite(AZERO, LOW); 
  SPI.transfer(bits);       
  digitalWrite(SS,HIGH);    // chip deselect
}

void writeData(char bits) {
  digitalWrite(SS,LOW);    // chip select 
  digitalWrite(AZERO, HIGH); 
  SPI.transfer(bits); 
  digitalWrite(SS,HIGH);    // chip deselect
}

void initializeLcd() {
  writeCommand(0b10100010);  // 0xA2 - LCD bias set to 1/9
  writeCommand(0b10100000);  // 0xA0 1010 0000,  - ADC select in normal mode
  writeCommand(0b11000000);  // 0xC0 COM scan direction = normal
  writeCommand(0b00100101);  // 0x25 resistor ratio
  writeCommand(0b10000001);  // 0x81 electronic volume mode set
  writeCommand(0b00010101);  // 0x15 electronic volume register set
  writeCommand(0b00101111);  // 0x2F operationg mode
  writeCommand(0b01000000);  // 0x40 start line set
  writeCommand(0b10101111);  // 0xAF display on
}

void loop() {   
  Serial.print("loop: ");
  Serial.println(loopCounter++); 
  unsigned int i, j;
  unsigned char page=0xB0;
  for(i=0;i<8;i++)             // fill display with checkerboard pattern
  {
    writeCommand(0x10);        //set column address
    writeCommand(0x00);        //set column address
    writeCommand(page);        //set page address
    for(j=0;j<64;j++)
    {
      writeData(0xAA);
      writeData(0x55);
    }
    page++;
  } 
  delay(2000);
}


« Last Edit: September 21, 2016, 08:51:45 PM by dalemoore »

dalemoore

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
No response from Newhaven after posting here and sending a request via their support page for 3 days. 

With so many people using Arduino, it would seem like this would be an easy question.

I'm beginning to wonder if this device works with Arduino/SPI. I've seen a handful of posts on this forum about Arduino, but I haven't seen any resolutions.

Hmm...

dalemoore

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
As a test, I used some code from another poster that was asking for similar help.  He was using an Arduino Uno and the response was asking to validate the voltage.  No reply from the original poster whether the suggested solution worked.  The code, copied directly from his post is as follows (I added a couple of comments).  This code does not work either.

Code: [Select]
#define DATAOUT 11      //MOSI - tied to pin 2 on display
#define DATAIN  12      //MISO - not connected
#define SPICLOCK  13    //sck - tied to pin 1 on display
#define SLAVESELECT 10  //ss - tied to pin 6 on display
#define RESET 9         // tied to PIN 5 on display
#define A0 8            // tied to pin 4 on display

uint8_t display_on = 0b10101111;
uint8_t display_all_points = 0b10100101;
uint8_t shutdown_all_points = 0b10100100;
uint8_t n;

/* ======================================= Functions ================================================*/

void spi_transfer(volatile uint8_t data,volatile bool instruc_or_data) // char = int_8
{
  if (instruc_or_data) // instruction 0, data 1
  { digitalWrite(A0,HIGH); } // write data
  else
  { digitalWrite(A0,LOW); } // write instruction

  digitalWrite(SLAVESELECT,LOW); //enable device
 
  // writing a byte to the SPI Data Register SPDR starts the SPI clock generator
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
  {
    //write the data
  };                   // return the received byte
 
  Serial.print("Tranfer done \n");
  delay(500);
  digitalWrite(SLAVESELECT,HIGH); //disable device
}
/* ======================================== SETUP ===================================================*/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //run the UART : serial monitor

  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
 
  digitalWrite(SLAVESELECT,LOW); //enable device
  digitalWrite(RESET,LOW); // reset active
  delay(1000); //wait 1 second
  digitalWrite(RESET,HIGH); //reset inactive
  digitalWrite(SLAVESELECT,HIGH); //disable device
                                     
  // We want SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);

  spi_transfer(display_on, 0);
}
/* ======================================= LOOP =====================================================*/

void loop() {
  // put your main code here, to run repeatedly:
  spi_transfer(display_all_points, 0);
  delay(3000);
  Serial.print("test \n");
  spi_transfer(shutdown_all_points, 0);
  delay(3000);
}

Paul_B

  • Administrator
  • Sr. Member
  • *****
  • Posts: 248
  • Karma: 16
    • View Profile
Morning dalemoore,

Thank you for contacting us with this inquiry, I am happy to provide some example Arduino code for you!

Please email me directly at pbartek@newhavendisplay.com, feel free to contact me if you have any additional questions or concerns!

dalemoore

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Paul provided some example code used for the Arduino Mega which I was able to convert to Arduino Pro Mini.  The following example works with the NHD-C12864A1Z-FSW-FBW-HTT Graphic LCD and an Arduino Pro Mini with SPI data connections.  This example doesn't use the Arduino SPI library, but instead sets the CLOCK and MOSI lines manually.  Much of this code was originally from the NewHaven examples which used port manipulation via PORTA on the Arduino Mega.  PORTA isn't available on Arduino Pro Mini so the digitalWrite(...) commands were used instead.

Hopefully this will help someone else out.  It would be nice if this example was expanded to use the SPI libraries, but for now, this is all I need for my efforts. 

Thanks Paul!

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

#define CLOCK       10  // connected to LCD PIN 1 (SCL)
#define DATA        11  // connected to LCD PIN 2 (SI)
#define AZERO       12  // connected to LCD PIN 4 (A0)
#define RESET       7   // connected to LCD PIN 5 (/RESET)
#define CHIPSELECT  8   // connected to LCD PIN 6 (/CS)

// Additional connections:
// PIN 3 from LCD is connected to Arduino's VCC PIN
// PIN 7 from LCD is connected to Arduino's GND PIN
// PIN 10 from LCD is connected to Arduino's GND PIN
// PIN 11 from LCD is connected to Arduino's VCC PIN
                       
int loopCounter = 0;  // used for debugging

void setup() { 
  // Open the serial debugging port
  Serial.begin(115200); 
  Serial.println("Begin LCD test"); 

  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT);
  pinMode(AZERO, OUTPUT);
  pinMode(RESET, OUTPUT);
  pinMode(CHIPSELECT, OUTPUT);

  // Reset the LCD
  digitalWrite(RESET, LOW);
  delay(120);
  digitalWrite(RESET, HIGH);

  // Initialize
  digitalWrite(CHIPSELECT, HIGH);
  digitalWrite(AZERO, HIGH);
   
  // Send instructions to LCD for setup
  writeCommand(0xA2);  // 0xA2 - LCD bias set to 1/9 
  writeCommand(0xA0);  // 0xA0 1010 0000,  - ADC select in normal mode
  writeCommand(0xC8);  // 0xC8 Added
  writeCommand(0xC0);  // 0xC0 COM scan direction = normal
  writeCommand(0x40);  // 0x40 operationg mode   
  writeCommand(0x25);  // 0x25 resistor ratio
  writeCommand(0x81);  // 0x81 electronic volume mode set
  writeCommand(0x19);  // 0x19 electronic volume register set
  writeCommand(0x2F);  // 0x2F power control set
  writeCommand(0xAF);  // 0xAF display on     
}

void writeCommand(char bits) {
  digitalWrite(CHIPSELECT,LOW);    // chip select 
  digitalWrite(AZERO, LOW);       
  transfer(bits); 
  digitalWrite(CHIPSELECT,HIGH);    // chip deselect
  digitalWrite(AZERO, HIGH);
}

void writeData(char bits) {
  digitalWrite(CHIPSELECT,LOW);    // chip select         
  transfer(bits);
  digitalWrite(CHIPSELECT,HIGH);    // chip deselect
}

void transfer(char bits) {
  for (int i=0; i<8; i++)
  {
    // Compare far left bit to 1000,0000 with bitwise AND
    if ((bits & 0x80) == 0x80)
    {
      // left most bit is high so set data high
      digitalWrite(DATA, HIGH);     
    }
    else
    {
      // left most bit is low so set data low
      digitalWrite(DATA, LOW);     
    }
    // move bits to the left
    bits = bits << 1;

    digitalWrite(CLOCK, LOW); 
    digitalWrite(CLOCK, HIGH);
  }
}

void loop() {   
  Serial.print("loop: ");
  Serial.println(loopCounter++); 

  // Illustrates all pins turned on.  To use, uncomment
  // the following line and then comment out all lines below that
  // down to the delay(...) call.
  //writeCommand(0b10100101);

  // Illustrates a checkerboard pattern where every other
  // pin is off and every other is on
  unsigned int i, j;
  unsigned char page=0xB0;
  for(i=0;i<8;i++)             // fill display with checkerboard pattern
  {
    writeCommand(0x10);        //set column address
    writeCommand(0x00);        //set column address
    writeCommand(page);        //set page address
    for(j=0;j<64;j++)
    {
      writeData(0xAA);
      writeData(0x55);
    }
    page++;
  } 
 
  delay(2000);
}
« Last Edit: September 22, 2016, 09:18:58 PM by dalemoore »

Paul_B

  • Administrator
  • Sr. Member
  • *****
  • Posts: 248
  • Karma: 16
    • View Profile
Glad to hear you got your display up and running!

Thanks for sharing your solution, it will definitely help others  :D

 

NHD‐C12864A1Z‐FS(RGB)‐FBW‐HT1 Initialization

Started by BMohlmanBoard Graphic LCDs

Replies: 5
Views: 3924
Last post January 13, 2016, 07:44:16 AM
by Paul_B
NHD‐C12864A1Z‐FSW‐FBW‐HTT display clears after draw

Started by EdAverillBoard Graphic LCDs

Replies: 6
Views: 5706
Last post November 07, 2014, 08:25:20 AM
by Michael_L
NHD-C12864A1Z-FSRGB-FBW-HT1 boost speed (clear to black and black to clear)

Started by facotlBoard Graphic LCDs

Replies: 4
Views: 2607
Last post January 27, 2016, 10:18:45 AM
by facotl
NHD-C12864A1Z not listed in NHDev Supported Displays List

Started by JimLBoard Evaluation Tools

Replies: 1
Views: 828
Last post April 19, 2017, 05:34:28 PM
by JimL
Current limiting resistors needed for NHD-C12864A1Z-FS(RGB)-FBW-HT1?

Started by andysBoard Graphic LCDs

Replies: 1
Views: 1167
Last post September 28, 2016, 08:36:06 AM
by Saurabh_B