Closed sith31 closed 1 year ago
Did you succeeded?
I have not been able to solve it, it is more now and I do not have an image with the lgt but with the nano
I think the main reason is the wrong delayMicroseconds()
in the latest release.
Replace your Arduino.h and wiring.c in directory C:\Users\(yourusername)\AppData\Local\Arduino15\packages\LGT8fx Boards\hardware\avr\1.0.5\cores\lgt8f\
with these files:
https://github.com/dbuezas/lgt8fx/blob/master/lgt8f/cores/lgt8f/Arduino.h
https://github.com/dbuezas/lgt8fx/blob/master/lgt8f/cores/lgt8f/wiring.c
@sith31 Since your question, the new v2.0.0. has been released, which has many changes. That's why I'm closing this issue. If the same error occurs next time, please open a new issue.
Hello, I am doing a project of a Sla printer, at the beginning I used an arduino nano, and I managed to make it work but with a very low performance, I found the lgt8f328p board that is twice as fast as the nano, but I can't make the images appear well with this plate, they come out compressed, I have tried all the libraries, both adafruit and SdFat and without result, I put the code to have if someone can help me. Edit: the screen is an ili9844 tft 3.5 "
`////////////////////////////////////////////////////////////
// * FOR CUSTOMIZATION
// If you want to change the length of the linear guide, the threaded rod, the motor or the microsteps // change them here and the rest of the variables will be updated.
define Lguide 100 //Total length of linear guide (Default value : 100 mm)
define pitch 2 //Pitch of movement screw thread (Default value : 2 mm)
define stepsMotorPerRev 720 //Motor steps per revolution, including gear reduction (Default value : 720 steps/rev)
define microsteps 32 //Driver microsteps (Default value 1)
////////////////////////////////////////////////////////////
// CONFIGURATION PARAMETERS
define hUp 3 // Lift distance in mm (Default value: 3 mm)
int FirstLayers = 5; //Number of initial layers (Default value: 5 initial layers)
int expotime = 25; //Starting exposure time in seconds
int iexpotime = 15; //Starting initial exposure time in seconds
define HighSpeed 90 //Delay in microseconds of the stepper motor pulses; higher speed at lower value (Default = 1800 microseconds)
define LowSpeed 170 //Delay in microseconds of the stepper motor pulses; higher speed at lower value (Default = 2500 microseconds)
define updowntime 6.7 //Printing downtime in seconds. Experimental value used to calculate print times. Counted from turning off the UV light on one layer and turning on the UV light on the next one.
//It must be modified if any of the configuration parameters are changed (speeds, number of initial layers, lift distance).
////////////////////////////////////////////////////////////
// Pin definition
define PinDir 15
define PinStep 14
define PinEn 10
//#define sclk 13 //#define miso 12 //#define mosi 11
define TFT_CS PD6
define TFT_DC PD3
define TFT_RST PD2
define _sdcs 5
define BtnUp 9
define BtnDown 6
define BtnOK 7
define BtnCancel 8
define PinEndStop 17
define LightPin 16
///////////////////////////////////////////////
// LIBRARIES
include "SPI.h"
include
include //FOR LCD DRIVER ILI9488
define USE_LGT_EEPROM_API
include
//#include <avr/power.h>
include
SdFat SD; //LCD TFT DRIVER //ILI9488 tft = ILI9488(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO); //ILI9488 tft = ILI9488(tftcs, dc, rst); //FOR LCD DRIVER ILI9488 ILI9488 tft = ILI9488(TFT_CS, TFT_DC, TFT_RST); //FOR LCD DRIVER ILI9488
define BU_BMP 1 // Temporarily flip the TFT coords for standard Bottom-Up bit maps
//#define TD_BMP 1 // Draw inverted Top-Down bitmaps in standard coord frame
///////////////////////////////////////////////
// GLOBAL VARIABLES
// Screen number
byte screen = 1;
// Screen Menu int mainmenusel = 0; int maxmainmenu = 2;
//Button status
bool edoBtnUP = HIGH; bool edoBtnDOWN = HIGH; bool edoBtnOK = HIGH; bool edoBtnCANCEL = HIGH;
//Button delay
define delaybutton 90
// EndStop Lecture
int LectEndStop = 0;
// Layer Height
float hLayer = 0.050; int hLayerx1000 = hLayer * 1000;
// Ascendant movement Height (mm)
int maxheight = Lguide - 30; //(30 mm lost due to carriage and platform)
// Print descendant movement
float hDown = hUp - hLayer;
//float hDownInitial = hUpInitial - hLayer;
// Steps per mm
int StepsPerMm = stepsMotorPerRev * microsteps / pitch;
// Calibration aditional steps
define maxAddDesc 3 // Additional maximum descent (Default = 3 mm)
int maxAddSteps = maxAddDesc * StepsPerMm / 8; //Division by 8 is due to memory EEPROM; then it is multiplied again.
byte stepsadditional = 0;
int stepsadditionalx8;
// For the correct name of file
String DirAndFile;
String FileName;
char result = (char)malloc(5);
int number;
//For the layers counter
int LayersCounter = 0;
int Layers;
String dirfoldersel;
// For the folder´s name
File root;
char foldersel[13];
int counter = 1;
// Main menu title
int screenWHalf; int screenHHalf; int screenW; int screenH;
// Main menu title
String titlemainmenu[3] = {"Start", "Calib", "Settings"};
/////////////////////////////////////////////// void setup() { // put your setup code here, to run once: //Serial.begin(9600); //Serial.print(F("DLP ILI9488 ")); //pinMode(_sdcs, OUTPUT); //clock_prescale_set(clock_div_1); //SPI.begin(); // Inicializa el bus SPI //SPI.beginTransaction(SPISettings (12000000, MSBFIRST, SPI_MODE0)); // Reloj de 2 MHz, MSB first, mode 0 pinMode (BtnUp, INPUT_PULLUP); pinMode (BtnDown, INPUT_PULLUP); pinMode (BtnCancel, INPUT_PULLUP); pinMode (BtnOK, INPUT_PULLUP);
pinMode (PinDir, OUTPUT); pinMode (PinStep, OUTPUT); pinMode (PinEn, OUTPUT);
pinMode (LightPin, OUTPUT); pinMode (PinEndStop, OUTPUT);
SPI.begin(); // Inicializa el bus SPI
digitalWrite (LightPin, LOW); digitalWrite (PinEn, HIGH); if (!SD.begin(_sdcs, SPI_HALF_SPEED)) { //if (!SD.begin(_sdcs)) { //return; } else { }
tft.begin(); //FOR LCD DRIVER ILI9488 tft.setRotation(1); tft.setTextSize(3); screenW = tft.width(); screenH = tft.height(); screenWHalf = (screenW / 2); screenHHalf = (screenH / 2); screen1();
}
void loop() { // put your main code here, to run repeatedly: edoBtnUP = digitalRead (BtnUp); edoBtnDOWN = digitalRead (BtnDown); edoBtnOK = digitalRead (BtnOK); edoBtnCANCEL = digitalRead (BtnCancel); //digitalWrite (LightPin, LOW); //delay(5000); //digitalWrite (LightPin, HIGH); //delay(5000); mainprint(); } ////////////////////////////////////////////////////////////
// MAIN FUNCTIONS void mainprint() {
if (edoBtnUP == LOW) { switch (screen) {
}
if (edoBtnDOWN == LOW) { switch (screen) { case 1: mainmenunavi(0); break; case 11: folderNavi(root, 1); break; case 12: switch (hLayerx1000) { case 100: hLayer = 0.05; hLayerx1000 = hLayer * 1000; String hLayerString = String(hLayer); char hLayerChar[7]; hLayerString.toCharArray(hLayerChar, 7); tft.setTextColor(ILI9488_WHITE, ILI9488_BLACK); tft.drawCentreString(hLayerChar, (screenWHalf) + 1, 115, 2); adjuststeps(); break; } delaybtn(); break;
}
if (edoBtnOK == LOW) { switch (screen) { case 1: switch (mainmenusel) { case 0: screenOpenSDcard(); break; case 1: blackscreen(); tft.drawCentreString("Calib!", (screenWHalf), 120, 2); calibrate();
}
if (edoBtnCANCEL == LOW) { if (screen < 17 && screen > 11 ) { screen = 11; screen11(); } else { screen = 1; screen1(); } delaybtn(); } } // PRINT FUNCTION void stopprint() { screen = 17; screen17(); } void startprint() {
number = 1; buildfolder(); calibrate();
// Printing the first layers (with initial exposure time)
for (int l = 0; l < FirstLayers; l++) {
}
// Printing the rest
for (int l = 0; l < Layers - FirstLayers; l++) {
}
screen = 17; screen17();
}
///////////////////////
// CALIBRATION FUNCTION
void calibrate() {
LectEndStop = digitalRead(PinEndStop);
if (LectEndStop != HIGH) {
} }
/////////////////////////////////////////////////////////////
// CALIBRATION AND PRINT SUPPORT FUNCTIONS void mainmenunavi(int isDown) { if (isDown == 1) { if (mainmenusel < 0) { mainmenusel = maxmainmenu; } else if (mainmenusel > 0) { mainmenusel--; } } else { if (mainmenusel > maxmainmenu) { mainmenusel = 0; } else if (mainmenusel < maxmainmenu) { mainmenusel++; } } //screen1(); readsdcard(); delaybtn(); } void folderNavi(File dir, int isDown) { if (isDown == 1) { counter++; } else if (isDown == 0) { if (counter > 2) { counter --; } else { return; } } for (int i = 0; i < counter; i++) { while (true) { File entry = dir.openNextFile(); if (! entry) { break; } if (entry.isDirectory()) { entry.getName(foldersel, 13); //entry.rename(foldersel, 13); break; } entry.close(); } } tft.fillRect(screenWHalf - 82, 130, 184, 36, ILI9488_BLACK); tft.setTextColor(ILI9488_WHITE); tft.drawCentreString(foldersel, (screenWHalf) + 1, 134, 2); delay(200); delaybtn(); }
void movasc (float Mm, int delaysteps) {
long int stepsmotor = StepsPerMm * Mm;
digitalWrite (PinEn, LOW); digitalWrite(PinDir, HIGH);
for (long int x = 0; x < stepsmotor; x++) { edoBtnCANCEL = digitalRead (BtnCancel); digitalWrite(PinStep, HIGH); digitalWrite(PinStep, LOW); delayMicroseconds(delaysteps); }
digitalWrite (PinEn, HIGH); }
void movdesc (float Mm, int delaysteps) {
long int stepsmotor = StepsPerMm * Mm;
digitalWrite (PinEn, LOW); digitalWrite(PinDir, LOW);
for (long int x = 0; x < stepsmotor; x++) { edoBtnCANCEL = digitalRead (BtnCancel); digitalWrite(PinStep, HIGH); digitalWrite(PinStep, LOW); delayMicroseconds(delaysteps); } digitalWrite (PinEn, HIGH); }
void buildfolder() {
DirAndFile = ""; String folderselString = String(foldersel); String barra = "/"; DirAndFile += barra; DirAndFile += folderselString; DirAndFile += barra; FileName = DirAndFile;
}
void contarlayers() {
LayersCounter = 0; dirfoldersel = ""; String folderselString2 = String(foldersel); number = 1; dirfoldersel += "/"; dirfoldersel += folderselString2; dirfoldersel += "/"; char dirfolderselChar[20]; dirfoldersel.toCharArray(dirfolderselChar, 20); File dircarp = SD.open(dirfolderselChar); while (true) { File entry = dircarp.openNextFile(); if (! entry) { break; } if (entry.isDirectory()) { } else { LayersCounter ++; } entry.close(); } }
void delayprint1() { delay (iexpotime * 250); }
void delayprint2() { delay (expotime * 250); }
void printname() { FileName += number; FileName += ".bmp"; char NameChar[20]; FileName.toCharArray(NameChar, 20); tft.setRotation(1); //bmpDraw(NameChar, 0, 0);
drawBMP(NameChar, 0, 0); //drawBMP(NameChar, 0, 0, BU_BMP); switch (hLayerx1000) { case 50: number ++; break;
} FileName = DirAndFile; }
void pause() {
edoBtnOK = digitalRead (BtnOK); edoBtnCANCEL = digitalRead (BtnCancel);
if (edoBtnCANCEL == LOW) {
}
}
void desctoendstop() {
digitalWrite (PinEn, LOW); digitalWrite(PinDir, LOW); LectEndStop = digitalRead(PinEndStop); //Serial.println("EndStop no Press");
while (LectEndStop != HIGH) { LectEndStop = digitalRead(PinEndStop); edoBtnCANCEL = digitalRead (BtnCancel); digitalWrite(PinStep, HIGH); digitalWrite(PinStep, LOW); delayMicroseconds(HighSpeed); } delay(300); }
void delaybtn() { delay(delaybutton); }
void adjuststeps() {
hDown = hUp - hLayer;
}
////////////////////////////////////////////////////////////
// SCREENS void screenOpenSDcard() { EEPROM.write (11, stepsadditional); //movasc(50, HighSpeed); if (!SD.begin(_sdcs, SPI_HALF_SPEED)) { //if (!SD.begin(_sdcs)) { digitalWrite (LightPin, LOW); cleanscreen(); failedReadSDCard(); screen = 1; } else { digitalWrite (LightPin, LOW); root = SD.open("/"); screen11(); screen = 11; } } void screen1() {
tft.setRotation(1); tft.setTextSize(3); cleanscreen();
//bannerprint(); readsdcard(); // arrows(); } void screen21() {
cleanscreen(); screen = 21;
}
void screen11() {
//bannerprint(); cleanscreen(); tft.setTextSize(3); tft.setTextColor(ILI9488_WHITE); tft.drawCentreString("FILE", (screenWHalf), 65, 2); tft.drawCentreString(foldersel, (screenWHalf) + 1, 134, 2); tft.drawRect((screenWHalf) - 85, 123, 180, 65, ILI9488_WHITE); // arrows();
}
void screenSetting(int page) { cleanscreen(); tft.setTextSize(3); tft.setTextColor(ILI9488_WHITE, ILI9488_BLACK); if (page == 1) { menuSettingTextSet("LAYER H", hLayer, "mm"); } else if (page == 2) { menuSettingTextSet("EXPTIME", expotime, "sec"); } else if (page == 3) { menuSettingTextSet("INITLAY", FirstLayers, "layer"); } else if (page == 4) { menuSettingTextSet("INITEXP", iexpotime, "sec"); } //rectscreen(); // arrows(); }
void menuSettingTextSet(char title, int value, char format) { tft.drawCentreString(title, (screenWHalf), 60, 2); String valueString = String(value); char valueChar[7]; valueString.toCharArray(valueChar, 7); tft.drawCentreString(valueChar, (screenWHalf) + 1, 115, 2); tft.drawCentreString(format, (screenWHalf) + 1, 160, 2); } void updateSettingText(int value) { String valueString = String(value); char valueChar[7]; valueString.toCharArray(valueChar, 7); cleantextscreen(); tft.setTextColor(ILI9488_WHITE); tft.drawCentreString(valueChar, (screenWHalf) + 1, 115, 2); }
void screen15() { long int timelayersinitial = FirstLayers iexpotime; long int quantitylayersresto = Layers - FirstLayers; long int timerestodelayers = quantitylayersresto expotime; long int timesubebajatot = Layers updowntime; long int timetotalseg = timesubebajatot + timelayersinitial + timerestodelayers; long int timetotalmin = timetotalseg / 60; int timetotalhours = timetotalmin / 60; int restominutes = timetotalmin - timetotalhours 60; cleanscreen(); tft.setTextSize(2); tft.setTextColor(ILI9488_WHITE); tft.drawCentreString("CONFIRM", (screenWHalf), 50, 2);
tft.drawString( "FOLDER: ", 20, 75, 2); tft.drawString(foldersel, 140, 75, 2); /* tft.drawString("LAYER H.:", 20, 95, 2); String hLayerString = String(hLayer); char hLayerChar[7]; hLayerString.toCharArray(hLayerChar, 7); tft.drawString(hLayerChar, 110, 95, 2);
tft.drawString("TOT LAYS:", 20, 100, 2); String LayersString = String(Layers); char LayersChar[7]; LayersString.toCharArray(LayersChar, 7); tft.drawString(LayersChar, 230, 100, 2);
tft.drawString("TIME:", 20, 125, 2); String timetotalhoursString = String(timetotalhours); char timetotalhoursChar[7]; timetotalhoursString.toCharArray(timetotalhoursChar, 7); tft.drawCentreString(timetotalhoursChar, 170, 125, 2); tft.drawString("h", 180, 125, 2); String restominutesString = String(restominutes); char restominutesChar[7]; restominutesString.toCharArray(restominutesChar, 7); tft.drawCentreString(restominutesChar, 230, 125, 2); tft.drawString("min", 250, 125, 2); tft.setTextSize(3); tft.drawCentreString("Insert & start!", (screenWHalf), 200, 2); }
void screen16() {
}
void screen17() {
tft.setRotation(1); blackscreen();
int heightup = Layers * hLayer; int heightremain = maxheight - heightup;
movasc(heightremain, HighSpeed);
while (digitalRead (BtnCancel) != LOW) { //This is for led 13 to blink blackscreen(); delay(100); }
}
////////////////////////////////////////////////////////////
// SCREEN SUPPORT FUNCTIONS //CHECK SD CARD AND SHOW SCREEN 1 void readsdcard() { if (!SD.begin(_sdcs, SPI_HALF_SPEED)) { // if (!SD.begin(_sdcs)) { failedReadSDCard(); } else { String titles = titlemainmenu[mainmenusel]; cleantextscreen(); switch (mainmenusel) { case 0: tft.drawCentreString("Start", screenWHalf, 130, 2); break; case 1: tft.drawCentreString("Calib", screenWHalf, 130, 2); break; case 2: tft.drawCentreString("Setting", screenWHalf, 130, 2); break; }
} }
void failedReadSDCard() { tft.drawCentreString("Please", (screenWHalf), 100, 2); tft.drawCentreString("insert SD", (screenWHalf), 135, 2); } //void arrows() {
//tft.fillTriangle(screenW-50, 135, screenW-30, 135, screenW-40, 120, ILI9488_WHITE ); //up arrow //tft.fillTriangle(screenW-50, 165, screenW-30, 165, screenW-40, 180, ILI9488_WHITE ); //down arrow //}
//void rectscreen() {
//tft.drawRect(screenWHalf - 40, 110, 100, 60, ILI9488_WHITE); //} void cleantextscreen() { tft.fillRect(screenWHalf - 110, 115, 220, 80, ILI9488_BLACK); }
void blackscreen() { tft.setRotation(2); //tft.fillRect(0, 0, screenW, screenH, ILI9488_BLACK); tft.fillScreen(ILI9488_BLACK); }
void cleanscreen() { tft.fillRect(0, 0, screenW, screenH, ILI9488_BLACK); //tft.fillScreen(ILI9488_BLACK); }
/ Function name: drawBMP Descriptions: draw a BMP format bitmap to the screen /
// This function opens a Windows Bitmap (BMP) file and // displays it at the given coordinates. It's sped up // by reading many pixels worth of data at a time // (rather than pixel by pixel). Increasing the buffer // size makes loading a little faster but the law of // rapidly diminishing speed improvements applies. // Suggest 8 minimum and 85 maximum (3 x this value is // stored in a byte = 255/3 max!) // A value of 8 is only ~20% slower than 24 or 48! // Note that 5 x this value of RAM bytes will be needed // Increasing beyond 48 gives little benefit. // Use integral division of TFT (or typical often used image) // width for slightly better speed to avoid short buffer purging
//#define BUFFPIXEL 80
define BUFF_SIZE 80
//void bmpDraw(char filename, uint8_t x, uint16_t y) { void drawBMP(char filename, uint8_t x, uint16_t y) { //void bmpDraw(char filename, int x, int y){ File bmpFile; long int bmpWidth, bmpHeight; uint8_t bmpDepth; uint32_t bmpImageoffset; uint32_t rowSize; //uint8_t sdbuffer[3BUFFPIXEL]; uint8_t sdbuffer[3 BUFF_SIZE]; uint16_t tftbuffer[BUFF_SIZE]; //uint16_t lcdbuffer[BUFFPIXEL]; uint8_t buffidx = sizeof(sdbuffer); int w, h, row, col; uint8_t r, g, b; uint32_t pos = 0, startTime = millis(); tft.setRotation(2); bmpFile = SD.open(filename); read16(bmpFile); read32(bmpFile); (void)read32(bmpFile); bmpImageoffset = read32(bmpFile); read32(bmpFile); bmpWidth = read32(bmpFile); bmpHeight = read32(bmpFile); bmpDepth = read16(bmpFile); rowSize = (bmpWidth 3 + 3) & ~3; tft.setAddrWindow(x, y, x + bmpWidth - 1, y + bmpHeight - 1); for (row = 0; row < bmpHeight; row++) { pos = bmpImageoffset + row * rowSize; bmpFile.seek(pos); buffidx = sizeof(sdbuffer);
} bmpFile.close(); } uint16_t read16(File &f) { uint16_t result; ((uint8_t )&result)[0] = f.read(); ((uint8_t )&result)[1] = f.read(); return result; } uint32_t read32(File &f) { uint32_t result; ((uint8_t )&result)[0] = f.read(); ((uint8_t )&result)[1] = f.read(); ((uint8_t )&result)[2] = f.read(); ((uint8_t )&result)[3] = f.read(); return result; }`