Author Topic: NHD-2.4-240320CF-CSXN#-F with ESP32 Devkit V1  (Read 115 times)

Gerdchen03

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
NHD-2.4-240320CF-CSXN#-F with ESP32 Devkit V1
« on: October 19, 2019, 12:36:06 PM »
I like to use a NHD-2.4-240320CF-CSXN#-F with a ESP32 Devkit V1 (https://docs.zerynth.com/latest/official/board.zerynth.doit_esp32/docs/index.html).

My Sketch to test is:
Code: [Select]
//****  Screen and SPIFFS Headers and Defines ****
//************************************************

//#include<HardwareSerial.h>
#include<TFT_eSPI.h>
#include<SPI.h>
#include "LogoJR.h"
#include "LogoOV.h"

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x18E3

//HardwareSerial Serial1(1);
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite needle = TFT_eSprite(&tft);
TFT_eSprite Nav1 = TFT_eSprite(&tft);
TFT_eSprite Nav2 = TFT_eSprite(&tft);


//******************************************
//****  FreeRTOS Headers and Variables  ****
//******************************************

#include"freertos/FreeRTOS.h"
#include"freertos/Task.h"
//#include"freertos/semphr.h"
#include"esp_system.h"
#include<stdio.h>

#define OuterRadius 160
#define InnerRadius 130
#define xCenter 160
#define yCenter 160

void setup() {
  tft.init();
  tft.setRotation(0);
  Serial.begin(115200,SERIAL_8N1);
}

void loop() { 
  delay(20);
}

//*************************
//****  Splash Screen  ****
//*************************

void splash(){
  Serial.print("Splash Screen");
  tft.fillScreen(BLACK);
  tft.drawBitmap(45,85,logobunny,150,149,WHITE);
  delay(3000);
  tft.fillScreen(WHITE);
  tft.setWindow(20,91,20+199,91+136);
  tft.pushColors(logoOV,200*137);
  delay(3000);
  tft.fillScreen(GREY);
  tft.fillCircle(xCenter,yCenter,InnerRadius,BLACK); 
}

Configuration at User_Setup.h from the TFT_eSPI library is:
Code: [Select]
#define ST7789_DRIVER
#define TFT_WIDTH  240
#define TFT_HEIGHT 320
#define ESP32_PARALLEL
#define TFT_CS   -1 
#define TFT_DC   15 
#define TFT_RST  22
#define TFT_WR   2 
#define TFT_RD   4 
#define TFT_D0   16   
#define TFT_D1   17   
#define TFT_D2   5   
#define TFT_D3   18 
#define TFT_D4   19
#define TFT_D5   21
#define TFT_D6   26
#define TFT_D7   25
#define SMOOTH_FONT
#define SPI_FREQUENCY  40000000
#define SPI_READ_FREQUENCY  20000000
#define SPI_TOUCH_FREQUENCY  2500000

I'm not able to get a picture. I have no idea what I've made wrong. Hope someone could help me.

Gerdchen03

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: NHD-2.4-240320CF-CSXN#-F with ESP32 Devkit V1
« Reply #1 on: October 25, 2019, 07:39:35 AM »
Newhaven Display has published a demo code, but it is not be written for Arduino.

Code: [Select]
//---------------------------------------------------------
/*
(c)2014 Curt Lagerstam - 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.
*/
//---------------------------------------------------------

/*******************************************************************************
* Function Name  : TFT_24_7789_Init
* Description    : Initializes LCD with built-in ST7789S controller.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void TFT_24_7789_Init(void)
{
int n;
GPIO_ResetBits(GPIOC, CS1);
GPIO_SetBits(GPIOC, nRD);
GPIO_ResetBits(GPIOC, nWR);
GPIO_WriteBit(GPIOC, RES, Bit_RESET);
TFT_delay(100);
GPIO_WriteBit(GPIOC, RES, Bit_SET);
TFT_delay(100);
TFT_24_7789_Write_Command(0x0011);//exit SLEEP mode
TFT_delay(100);

TFT_24_7789_Write_Command(0x0036);TFT_24_7789_Write_Data(0x0080);//MADCTL: memory data access control
TFT_24_7789_Write_Command(0x003A);TFT_24_7789_Write_Data(0x0066);//COLMOD: Interface Pixel format *** I use 262K-colors in 18bit/pixel format when using 8-bit interface to allow 3-bytes per pixel
//TFT_24_7789_Write_Command(0x003A);TFT_24_7789_Write_Data(0x0055);//COLMOD: Interface Pixel format  *** I use 65K-colors in 16bit/pixel (5-6-5) format when using 16-bit interface to allow 1-byte per pixel
TFT_24_7789_Write_Command(0x00B2);TFT_24_7789_Write_Data(0x000C);TFT_24_7789_Wri​te_Data(0x0C);TFT_24_7789_Write_Data(0x00);TFT_24_7789_Write_Data(0x33);TFT_24_7​789_Write_Data(0x33);//PORCTRK: Porch setting
TFT_24_7789_Write_Command(0x00B7);TFT_24_7789_Write_Data(0x0035);//GCTRL: Gate Control
TFT_24_7789_Write_Command(0x00BB);TFT_24_7789_Write_Data(0x002B);//VCOMS: VCOM setting
TFT_24_7789_Write_Command(0x00C0);TFT_24_7789_Write_Data(0x002C);//LCMCTRL: LCM Control
TFT_24_7789_Write_Command(0x00C2);TFT_24_7789_Write_Data(0x0001);TFT_24_7789_Wri​te_Data(0xFF);//VDVVRHEN: VDV and VRH Command Enable
TFT_24_7789_Write_Command(0x00C3);TFT_24_7789_Write_Data(0x0011);//VRHS: VRH Set
TFT_24_7789_Write_Command(0x00C4);TFT_24_7789_Write_Data(0x0020);//VDVS: VDV Set
TFT_24_7789_Write_Command(0x00C6);TFT_24_7789_Write_Data(0x000F);//FRCTRL2: Frame Rate control in normal mode
TFT_24_7789_Write_Command(0x00D0);TFT_24_7789_Write_Data(0x00A4);TFT_24_7789_Wri​te_Data(0xA1);//PWCTRL1: Power Control 1
TFT_24_7789_Write_Command(0x00E0);TFT_24_7789_Write_Data(0x00D0);
                                  TFT_24_7789_Write_Data(0x0000);
                                  TFT_24_7789_Write_Data(0x0005);
                                  TFT_24_7789_Write_Data(0x000E);
                                  TFT_24_7789_Write_Data(0x0015);
                                  TFT_24_7789_Write_Data(0x000D);
                                  TFT_24_7789_Write_Data(0x0037);
                                  TFT_24_7789_Write_Data(0x0043);
                                  TFT_24_7789_Write_Data(0x0047);
                                  TFT_24_7789_Write_Data(0x0009);
                                  TFT_24_7789_Write_Data(0x0015);
                                  TFT_24_7789_Write_Data(0x0012);
                                  TFT_24_7789_Write_Data(0x0016);
                                  TFT_24_7789_Write_Data(0x0019);//PVGAMCTRL: Positive Voltage Gamma control   
TFT_24_7789_Write_Command(0x00E1);TFT_24_7789_Write_Data(0x00D0);
                                  TFT_24_7789_Write_Data(0x0000);
                                  TFT_24_7789_Write_Data(0x0005);
                                  TFT_24_7789_Write_Data(0x000D);
                                  TFT_24_7789_Write_Data(0x000C);
                                  TFT_24_7789_Write_Data(0x0006);
                                  TFT_24_7789_Write_Data(0x002D);
                                  TFT_24_7789_Write_Data(0x0044);
                                  TFT_24_7789_Write_Data(0x0040);
                                  TFT_24_7789_Write_Data(0x000E);
                                  TFT_24_7789_Write_Data(0x001C);
                                  TFT_24_7789_Write_Data(0x0018);
                                  TFT_24_7789_Write_Data(0x0016);
                                  TFT_24_7789_Write_Data(0x0019);//NVGAMCTRL: Negative Voltage Gamma control
TFT_24_7789_Write_Command(0x002A);TFT_24_7789_Write_Data(0x0000);TFT_24_7789_Wri​te_Data(0x0000);TFT_24_7789_Write_Data(0x0000);TFT_24_7789_Write_Data(0x00EF);//X address set
TFT_24_7789_Write_Command(0x002B);TFT_24_7789_Write_Data(0x0000);TFT_24_7789_Wri​te_Data(0x0000);TFT_24_7789_Write_Data(0x0001);TFT_24_7789_Write_Data(0x003F);//Y address set

TFT_delay(10);
}




/*******************************************************************************
* Function Name  : TFT_24_7789_Write_Command
* Description    : writes a 1 byte command to 2.4" TFT.
* Input          : command = one byte command (register address)
* Output         : None
* Return         : None
*******************************************************************************/
void TFT_24_7789_Write_Command(unsigned int command)
{
GPIO_ResetBits(GPIOC, CS1);
GPIO_ResetBits(GPIOC, RS);
GPIO_SetBits(GPIOC, nRD);
GPIO_ResetBits(GPIOC, nWR);
GPIO_Write(GPIOB, command);//when using 16-bit interface (DB17:10,DB8:1)//when using 8-bit interface (DB17:10)
TFT_delay(10);
GPIO_SetBits(GPIOC, nWR);
TFT_delay(1);
}

/*******************************************************************************
* Function Name  : TFT_24_7789_Write_Data
* Description    : writes 1 byte of data to 2.4" TFT.
* Input          : data1 = one byte of display data or command parameter
* Output         : None
* Return         : None
*******************************************************************************/
void TFT_24_7789_Write_Data(unsigned int data1)
{
GPIO_Write(GPIOB, data1);//when using 16-bit interface (DB17:10,DB8:1)//when using 8-bit interface (DB17:10)
GPIO_SetBits(GPIOC, RS);
GPIO_ResetBits(GPIOC, nWR);
TFT_delay(1);
GPIO_SetBits(GPIOC, nWR);
}







/*******************************************************************************
* Function Name  : TFT_24_7789_demo
* Description    : Loads bmp from SD card and writes to NHD-2.4-240320CF-CTXI#.
* Input          : None
* Output         : None
* Return         : 1-end of function reached
*******************************************************************************/
int TFT_24_7789_demo(void)
{
GPIO_SetBits(GPIOC, IM0);        //8-bit mode
//GPIO_ResetBits(GPIOC, IM0);        //16-bit mode
TFT_24_7789_Init();
TFT_24S_Write_Command(0x002C);                //Memory write

for (n=0;n<3;n++){
    memset(RGB16,0x0000,sizeof(RGB16));
    for (i=0;i<25600;i++)                    //for each 24-bit pixel...
    {
        f_read(&File1, &blue, 1, &blen);    //read the blue 8-bits
        f_read(&File1, &green, 1, &blen);    //read the green 8-bits
        f_read(&File1, &red, 1, &blen);        //read the red 8-bits
       
/* un-comment below for 8-bit interface */
        GPIO_SetBits(GPIOC, RS);
       
        GPIO_Write(GPIOB, red);
        GPIO_ResetBits(GPIOC, nWR);
        GPIO_SetBits(GPIOC, nWR);
       
        GPIO_Write(GPIOB, green);
        GPIO_ResetBits(GPIOC, nWR);
        GPIO_SetBits(GPIOC, nWR);
       
        GPIO_Write(GPIOB, blue);
        GPIO_ResetBits(GPIOC, nWR);
        GPIO_SetBits(GPIOC, nWR);
       
/* END of 8-bit interface */

/* un-comment below for 16-bit interface */
//
//        red=red>>3;                               //shift down to 5-bits
//        green=green>>2;                        //shift down to 6-bits
//        blue=blue>>3;                        //shift down to 5-bits
//        RGB16[i]= (RGB16[i] | red);            //put red 5-bits into int
//        RGB16[i]= (RGB16[i] << 6);            //move red bits over, make room for green
//        RGB16[i]= (RGB16[i] | green);        //put green 6-bits into int
//        RGB16[i]= (RGB16[i] << 5);            //move red and green bits over, make room for blue
//        RGB16[i]= (RGB16[i] | blue);        //put blue 5-bits into int
//        GPIO_Write(GPIOB, RGB16[i]);
//        GPIO_SetBits(GPIOC, RS);
//        GPIO_ResetBits(GPIOC, nWR);
//        GPIO_SetBits(GPIOC, nWR);
//                                     
/* END of 16-bit interface */

    }
}
                   
TFT_24_7789_Write_Command(0x0029);                //display ON

return 1;
}

 

NHD-2.4-240320CF-CTXI#-FT (ST7789S controller) and STM32F4 FSMC LCD Interface

Started by deshayesBoard TFTs

Replies: 1
Views: 7757
Last post March 17, 2016, 06:25:18 PM
by fahad
NHDEV firmware to support NHD-2.4-240320CF-CTXI#-FT (ST7889S controller)

Started by deshayesBoard Evaluation Tools

Replies: 1
Views: 6858
Last post December 17, 2015, 09:52:29 AM
by Saurabh_B
Can't display a sample BMP image properly on NHD-2.4-240320CF-CTXI#-F with NHDev

Started by HidefumiMBoard Evaluation Tools

Replies: 3
Views: 2134
Last post December 28, 2018, 05:12:36 PM
by Alee_S
NHD-2.4-240320CF-CSXI#-F minimal wiring for power

Started by enjaianBoard TFTs

Replies: 4
Views: 6284
Last post July 25, 2015, 04:32:22 PM
by enjaian
NHD-2.4-240320CF-CTXI#-FT ribbon cable question

Started by tom66888Board TFTs

Replies: 1
Views: 5425
Last post October 02, 2015, 08:29:03 AM
by Saurabh_B