NOTES
- IM2 & IM1 tied LOW | IM0 tied HIGH
- Interface Select: 8-bit 8080-II
- Replace 5V regulator with 3.3V regulator
OUTPUT
This demo will fill the screen with red, green, and blue continuously.
/******************************************************************************
Copyright (c) 2026 - Newhaven Display International, Inc.
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.
* NHD_1.5_240240AF_CSXP Example Code
*
* Description: Arduino example code for the Newhaven Display
* NHD-1.5-240240AF-CSXP
*
* This demo showcases colors filling the screen on touch
*
* !! IMPORTANT !!
* The demo uses the following components:
* - Arduino Due
*
* Pinout:
* - (NHD-1.5-240240AF-CSXP) DCX -> 30 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) WRX -> 31 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) RDX -> 32 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) RES -> 33 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) X1 -> A0 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) X2 -> A1 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) Y1 -> A2 (Arduino Due)
* - (NHD-1.5-240240AF-CSXP) Y2 -> A3 (Arduino Due)
*
* Libraries Required:
* - SD.h - From Arduino
*
* Notes:
* - IM2 & IM1 tied LOW | IM0 tied HIGH
* - Interface Select: 8-bit 8080-II
* - Replace 5V regulator with 3.3V regulator
*
*
*
******************************************************************************/
#include <SD.h>
/****************************************************
* PINOUT: Arduino Due -> 1.5" TFT *
****************************************************/
// Uses 8-bit 8080 Parallel interface
// 8-bit data bus DB7-DB0 connected to Arduino Due pins 29 - 22
#define DCX 30 // DCX signal connected to Arduino digital pin 30
#define WRX 31 // WRX signal connected to Arduino digital pin 31
#define RDX 32 // RDX signal connected to Arduino digital pin 32
#define RES 33 // RESX signal connected to Arduino digital pin 33
/* RTP pins connected to Arduino Analog pins */
#define X1 A0
#define X2 A1
#define Y1 A2
#define Y2 A3
/* Screen resolution */
#define Xresolution 240
#define Yresolution 240
/* SD Card connected to Arduino SPI bus */
const int CS = 37; //CS pin
File myFile;
/* Global variables for program */
int refresh = 0;
int imageD = 0;
/* Function for sending commands to display */
void comm_out(unsigned char c) {
PIOD->PIO_CODR = 1 << 9; // Set DCX LOW
for (int i = 29; i >= 22; i--) { // Set the 8-bit databus
if ((c & 0x80) == 0x80) {
digitalWrite(i, HIGH);
} else {
digitalWrite(i, LOW);
}
c = c << 1; // Shift Byte
}
PIOA->PIO_CODR = 1 << 7; // Set WRX LOW
PIOA->PIO_SODR = 1 << 7; // Set WRX HIGH
}
/* Function for sending data to display */
void data_out(unsigned char d) {
PIOD->PIO_SODR = 1 << 9; // Set DCX HIGH
for (int i = 29; i >= 22; i--) { // Set the 8-bit databus
if ((d & 0x80) == 0x80) {
digitalWrite(i, HIGH);
} else {
digitalWrite(i, LOW);
}
d = d << 1; // Shift Byte
}
PIOA->PIO_CODR = 1 << 7; // Set WRX LOW
PIOA->PIO_SODR = 1 << 7; // Set WRX HIGH
}
/****************************************************
* Display Commands *
****************************************************/
/* MADCTL: memory data access control */
void MADCTL() {
comm_out(0x36);
data_out(0x10);
}
/* Display inversion */
void InvOn() {
comm_out(0x21);
}
/* COLMOD: Interface Pixel format */
void COLMOD() {
comm_out(0x3A);
data_out(0x55); //0x55 = 65k //0x65 = 262k
}
/* PORCTRK: Porch setting */
void PORCH_set() {
comm_out(0xB2);
data_out(0x0C);
data_out(0x0C);
data_out(0x00);
data_out(0x33);
data_out(0x33);
}
/* GCTRL: Gate Control */
void GCTL() {
comm_out(0xB7);
data_out(0x35);
}
/* VCOMS: VCOM setting */
void VCOMS_set() {
comm_out(0xBB);
data_out(0x2B);
}
/* LCMCTRL: LCM Control */
void LCMCTL() {
comm_out(0xC0);
data_out(0x2C);
}
/* VDVVRHEN: VDV and VRH Command Enable */
void VDVVHREN() {
comm_out(0xC2);
data_out(0x01);
data_out(0xFF);
}
/* VRHS: VRH Set */
void VRHS() {
comm_out(0xC3);
data_out(0x11);
}
/* VDVS: VDV Set */
void VDVS() {
comm_out(0xC4);
data_out(0x20);
}
/* FRCTRL2: Frame Rate control in normal mode */
void FRCTL2() {
comm_out(0xC6);
data_out(0x0F);
}
/* PWCTRL1: Power Control 1 */
void PWRCTL1() {
comm_out(0xD0);
data_out(0xA4);
data_out(0xA1);
}
/* PVGAMCTRL: Positive Voltage Gamma control */
void PVGAMCTL() {
comm_out(0xE0);
data_out(0xD0);
data_out(0x00);
data_out(0x05);
data_out(0x0E);
data_out(0x15);
data_out(0x0D);
data_out(0x37);
data_out(0x43);
data_out(0x47);
data_out(0x09);
data_out(0x15);
data_out(0x12);
data_out(0x16);
data_out(0x19);
}
/* NVGAMCTRL: Negative Voltage Gamma control */
void NVGAMCTL() {
comm_out(0xE1);
data_out(0xD0);
data_out(0x00);
data_out(0x05);
data_out(0x0D);
data_out(0x0C);
data_out(0x06);
data_out(0x2D);
data_out(0x44);
data_out(0x40);
data_out(0x0E);
data_out(0x1C);
data_out(0x18);
data_out(0x16);
data_out(0x19);
}
/* X address set
* @Parameters: XsU - X address start (Upper Byte)
* @Parameters: XsL - X address start (Lower Byte)
* @Parameters: XeU - X address end (Upper Byte)
* @Parameters: XeL - X address end (Lower Byte)
*/
void X_set(unsigned char XsU, unsigned char XsL, unsigned char XeU, unsigned char XeL) {
comm_out(0x2A);
data_out(XsU);
data_out(XsL);
data_out(XeU);
data_out(XeL);
delay(10);
}
/* X address set
* @Parameters: YsU - Y address start (Upper Byte)
* @Parameters: YsL - Y address start (Lower Byte)
* @Parameters: YeU - Y address end (Upper Byte)
* @Parameters: YeL - Y address end (Lower Byte)
*/
void Y_set(unsigned char YsU, unsigned char YsL, unsigned char YeU, unsigned char YeL) {
comm_out(0x2B);
data_out(YsU);
data_out(YsL);
data_out(YeU);
data_out(YeL);
delay(10);
}
/* Display on */
void disp_on() {
comm_out(0x29);
delay(10);
}
/* Display off */
void disp_off() {
comm_out(0x28);
}
/* Exit SLEEP mode */
void slp_exit() {
comm_out(0x11);
delay(100);
}
/* Begin writing to frame memory */
void RAMWR() {
comm_out(0x2C);
}
/****************************************************
* Display Functions *
****************************************************/
/* Fill screen with RGB */
void disp() {
unsigned int x = 3000;
//fill screen with red pixels
RAMWR();
for (int i = 0; i < 28800; i++) {
data_out(0xF8);
data_out(0x00);
data_out(0xF8);
data_out(0x00);
}
delay(x);
//fill screen with green pixels
RAMWR();
for (int i = 0; i < 28800; i++) {
data_out(0x07);
data_out(0xE0);
data_out(0x07);
data_out(0xE0);
}
delay(x);
//fill screen with blue pixels
RAMWR();
for (int i = 0; i < 28800; i++) {
data_out(0x00);
data_out(0x1F);
data_out(0x00);
data_out(0x1F);
}
delay(x);
}
/* Display image from SD card*/
void image(unsigned char image) {
switch (image) {
case 1:
myFile = SD.open("image1.bmp");
break;
case 2:
myFile = SD.open("image2.bmp");
break;
case 3:
myFile = SD.open("image3.bmp");
break;
case 4:
myFile = SD.open("image4.bmp");
break;
case 5:
myFile = SD.open("image5.bmp");
break;
}
unsigned char dummy;
X_set(0x00, 0x00, 0x00, 0xEF); // Address Start Bit / Address End bit
Y_set(0x00, 0x00, 0x00, 0xEF); // Address Start Bit / Address End bit
RAMWR(); // Command to begin writing to frame memory
if (myFile) {
for (unsigned int i = 0; i < 66; i++) { // Read header bytes to begin
dummy = myFile.read();
}
for (unsigned int i = 0; i < 57600; i++) { // 240x240 Pixel Resolution
uint8_t lowByte = myFile.read();
uint8_t highByte = myFile.read();
data_out(highByte);
data_out(lowByte);
}
}
myFile.close();
}
/****************************************************
* Setup and Loop *
*****************************************************/
/* TFT initialization */
void initLCD() {
disp_off();
slp_exit();
MADCTL();
COLMOD();
PORCH_set();
GCTL();
VCOMS_set();
LCMCTL();
VDVVHREN();
VRHS();
VDVS();
FRCTL2();
PWRCTL1();
PVGAMCTL();
NVGAMCTL();
X_set(0x00, 0x00, 0x00, 0xEF); // Address Start Bit / Address End bit
Y_set(0x00, 0x00, 0x00, 0xEF); // Address Start Bit / Address End bit
InvOn();
disp_on();
delay(10);
}
/* Setup Arduino Pins */
void pinSetup() {
for (int x = 22; x < 40; x++) {
pinMode(x, OUTPUT);
}
digitalWrite(RDX, HIGH); // Disable Display Read Signal
digitalWrite(WRX, LOW); // Set Display Write as Active
digitalWrite(RES, LOW); // Toggle Reset
delay(100);
digitalWrite(RES, HIGH);
delay(100);
pinMode(Y1, INPUT); //RTP pins
pinMode(Y2, INPUT);
digitalWrite(Y2, LOW);
pinMode(X1, OUTPUT);
pinMode(X2, OUTPUT);
digitalWrite(X1, HIGH);
digitalWrite(X2, LOW);
}
/* Setup Arduino + TFT */
void setup() {
pinSetup();
initLCD();
SD.begin(CS);
}
void loop() {
disp();
}