NHD-FT81x-SHIELD and microSD card
Hi,
I'm using an Arduino Due, NHD-5.0-800480FT-CTXL-T LCD screen, NHD-FT81x-SHIELD and a 32gb SanDisk microSD card.
I’ve been trying to send an array of display list commands to an external memory device and then to the LCD so I can send more commands – due to the limited memory on the Arduino. I’m trying to use the microSD card slot located on the NHD-FT81x-SHIELD.
I can run a test program that seems to work fine – writing the array of uint32 commands to a .txt file and then reading it back and displaying on the serial monitor. I can also view the file on the SD card after running. I’ve attached this test code. The test code doesn't try to utlize the LCD.
However when I transfer these same lines of code to my larger program – the serial monitor only prints “error opening DisplayList.txt”. I've attached the relevant snippets of code that I'm trying to implement.
I'm wondering if it could be an issue with interfacing with LCD and SD card – because they both use SPI? Are they interfering with each other? i'm not sure if I'm enabling Dual/Quad SPI mode correctly. An example program that utlizes the LCD and SD card could be very helpful.
Any help you can provide is greatly appreciated. Thanks,
Kyle D
SDcard code:
#include <stdio.h>
#include <Arduino.h>
#include <SPI.h>
#include <hardwareSerial.h>
//#include "Adafruit_BLE.h"
//#include "Adafruit_BluefruitLE_UART.h" //disabled bluetooth functionality for
testing
//#include "BluefruitConfig.h"
#include <avr/pgmspace.h>
#include "FT_Platform.h"
#include <SD.h>
uint32_t commands[625];
uint8_t commandIndex = 0;
File DisplayList;
ft_void_t setup() {
Serial.begin(115200);
home_setup();
Info();
//=================================================
//SD Card Initialization
Serial.print("Initializing SD card...");
if(!SD.begin(5)){
Serial.println("initialization failed!");
while(1);
}
Serial.println("initialization done.");
loop();
}
void DisplayData() {
screenX = (Xaverage * Xratio) - 240;
screenY = 7680 - ((Yaverage * Yratio) - 240);
Serial.println(screenX);
Serial.println(screenY);
if(y >=0&& screenY <=7680&& x >=0&& screenX <=12800){
if(previousX != screenX && previousY != screenY){
previousX = screenX;
previousY = screenY;
screenX2 = screenX + 480;
screenY2 = screenY + 480;
Ft_Gpu_CoCmd_Dlstart(phost);
Ft_App_WrCoCmd_Buffer(phost, CLEAR(1, 1, 1));
if(average >1750){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(255, 255, 255);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
if(1650< average && average <=1750){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(255, 255, 25);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
if(1350< average && average <=1650){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(255, 125, 0);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
if(950< average && average <=1350){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(205, 0, 0);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
if(650< average && average <=950){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(50, 0, 100);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
if(200< average && average <=650){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(0, 0, 50);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
if(average <=200){
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(0, 0, 0);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX, screenY);
commandIndex++;
commands[commandIndex] = VERTEX2F(screenX2, screenY2);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
}
}
}
DisplayList = SD.open("DisplayList.txt", FILE_WRITE);
if(DisplayList){
Serial.print("Writing to DisplayList.txt...");
for(int i =0; i <= commandIndex; i++){
DisplayList.println(commands[i]);
}
DisplayList.close();
Serial.println("done.");
}else{
// if the file didn't open, print an error:
Serial.println("error opening DisplayList.txt");
}
}
void showScreen() {
//===================================
//SD Card Commands
DisplayList = SD.open("DisplayList.txt");
if(DisplayList){
Serial.println("DisplayList.txt:");
// read from the file until there's nothing else in it:
while(DisplayList.available()){
Ft_App_WrCoCmd_Buffer(phost, DisplayList.read());
//Serial.write(DisplayList.read());
}
// close the file:
DisplayList.close();
}else{
// if the file didn't open, print an error:
Serial.println("error opening DisplayList.txt");
}
Ft_App_WrCoCmd_Buffer(phost, DISPLAY());
Ft_Gpu_CoCmd_Swap(phost);
Ft_App_Flush_Co_Buffer(phost);
Ft_Gpu_Hal_WaitCmdfifo_empty(phost);
}
#include <SPI.h>
#include <SD.h>
#include <avr/pgmspace.h>
#include "FT_Platform.h"
#include <stdio.h>
#include <Arduino.h>
uint32_t commands[625];
uint8_t commandIndex = 0;
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while(!Serial){
; // wait for serial port to connect. Needed for native USB port only
}
commands[commandIndex] = BEGIN(RECTS);
commandIndex++;
commands[commandIndex] = COLOR_RGB(255, 255, 255);
commandIndex++;
commands[commandIndex] = VERTEX2F(480, 480);
commandIndex++;
commands[commandIndex] = VERTEX2F(800, 800);
commandIndex++;
commands[commandIndex] = END();
commandIndex++;
Serial.print("Initializing SD card...");
if(!SD.begin(5)){
Serial.println("initialization failed!");
while(1);
}
Serial.println("initialization done.");
}
void loop() {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if(myFile){
Serial.print("Writing to test.txt...");
for(int i =0; i <= commandIndex; i++){
myFile.println(commands[i]);
}
// close the file:
myFile.close();
Serial.println("done.");
}else{
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if(myFile){
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while(myFile.available()){
Serial.write(myFile.read());
}
// close the file:
myFile.close();
}else{
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
-
Hello,
Unfortunately, the Due is not compatible, the NHD-FT81x-SHIELD requires an operating voltage of 5V to be supplied by the Arduino.
The Due's IO pins are not tolerant of the 5V levels from the shield.
For a list of compatible Arduino's please refer to our NHD-FT81x-SHIELD User Guide on page 11.https://newhavendisplay.com/content/userguide/NHD-FT81x-SHIELD_User_Guide.pdf
If you have any further question please contact us at: nhtech@newhavendisplay.com
Best Regards.0
Please sign in to leave a comment.
Comments
1 comment