Help Getting ArduinoPro Mini 3.3V and NHD-C12864A1Z-FSW-FBW-HTT to work via SPI

Comments

5 comments

  • dalemoore

    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...

    0
  • dalemoore

    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.

    #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);
    }

     

    0
  • Paul_B

    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!

    0
  • dalemoore

    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!

    #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);
    }

     

    0
  • Paul_B
    Glad to hear you got your display up and running!

    Thanks for sharing your solution, it will definitely help others  
    0

Please sign in to leave a comment.