Hello everyone,
Before posting this I had a browse for something familiar and read up on “TFT Display works in Arduino IDE, but doesnt in PlatformIO” posted by leemanio in Apr 2023. Unfortunately I don’t see a solution there.
I am following this eample by Volos Projects Round GC9A01 240x240 display and gauges
and I can see he uses Arduino IDE.
I have copied the provided code from his well documented web page and put all the header files in >lib > All_Gauges and the project compiles without errors.
I know the code with espi by Bodmer is working up to a point as I am able in setup() to change the tft.fillScreen(TFT_ORANGE) to (TFT_SILVER) so I’m assuming that my pin configuration for the ESP32 is correct in the User_Setup_Select.h file.
What it does not appear to execute in the loop() is to generate the gauge code (presumably not reading the <gauge1.h> file and compiling it) ?
I have tried over the last few days using different versions of TFT_eSPI by Bodmer (ranging from 2.4.79 to 2.5.43) but still have the same result of a non displayed gauge?
To test my wiring and choice of User_Setup_Select.h settings I have successfully run the Animated_dial example found in TFT_eSPI > examples > Sprite > Animated_dial and even played around to correct that version of the needle overwriting the numeric background as it moves.
I’m now at a loss to find a solution?
Here is my platformio configuration code
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
lib_deps =
bodmer/TJpg_Decoder@^1.1.0
bodmer/TFT_eSPI@^2.5.43
Here is my main.cpp code
#include <Arduino.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include <gauge1.h>
#include <gauge2.h>
#include <gauge3.h>
#include <gauge4.h>
#include <gauge5.h>
#include <gauge6.h>
#include <font.h>
// Include the jpeg decoder library
////#include <TJpg_Decoder.h>
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite img = TFT_eSprite(&tft);
TFT_eSprite ln = TFT_eSprite(&tft);
double rad=0.01745;
int angle;
int sx=120;
int sy=120;
int r=76;
float x[360];
float y[360];
float x2[360];
float y2[360];
const int pwmFreq = 5000;
const int pwmResolution = 8;
const int pwmLedChannelTFT = 0;
int chosenOne=0;
int minValue[6]={0,20,0,0,0,80};
int maxValue[6]={40,100,60,80,70,160};
int dbounce=0;
int a1,a2;
int result=0;
/*
// =======================================================================================
// This function will be called during decoding of the jpeg file
// =======================================================================================
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
// Stop further decoding as image is running off bottom of screen
if ( y >= tft.height() ) return 0;
// This function will clip the image block rendering automatically at the TFT boundaries
tft.pushImage(x, y, w, h, bitmap);
// Return 1 to decode next block
return 1;
}
*/
void setup() {
// For code checking
Serial.begin(115200); // Debug only
// The byte order can be swapped (set true for TFT_eSPI)
////TJpgDec.setSwapBytes(true);
// The jpeg decoder must be given the exact name of the rendering function above
////TJpgDec.setCallback(tft_output);
ledcSetup(pwmLedChannelTFT, pwmFreq, pwmResolution);
ledcAttachPin(5, pwmLedChannelTFT);
ledcWrite(pwmLedChannelTFT, 90);
pinMode(12,INPUT_PULLUP);
tft.init();
tft.setRotation(0);
tft.setSwapBytes(true);
img.setSwapBytes(true);
////tft.fillScreen(TFT_ORANGE);
tft.fillScreen(TFT_SILVER);
img.createSprite(240, 240);
tft.setPivot(60,60);
img.setTextDatum(4);
img.setTextColor(TFT_BLACK,0xAD55);
img.setFreeFont(&Orbitron_Medium_28);
int i=0;
int a=136;
while(a!=44)
{
x[i]=r*cos(rad*a)+sx;
y[i]=r*sin(rad*a)+sy;
x2[i]=(r-20)*cos(rad*a)+sx;
y2[i]=(r-20)*sin(rad*a)+sy;
i++;
a++;
if(a==360)
a=0;
}
////Serial.print("Exiting setup()");
}
//min angle 136 or 137
//max angle 43
void loop() {
//// Not using a PushButton so commented out.
//// Just want to see Gauge 1 displayed!
/*
if(digitalRead(12)==0)
{
if(dbounce==0)
{
dbounce=1;
chosenOne++;
if(chosenOne>=6)
chosenOne=0;
}
}else dbounce=0;
result=map(analogRead(14),0,4095,minValue[chosenOne],maxValue[chosenOne]);
angle=map(result,minValue[chosenOne],maxValue[chosenOne],0,267);
*/
chosenOne=0;
if(chosenOne==0)
img.pushImage(0,0,240,240,gauge1);
if(chosenOne==1)
img.pushImage(0,0,240,240,gauge2);
if(chosenOne==2)
img.pushImage(0,0,240,240,gauge3);
if(chosenOne==3)
img.pushImage(0,0,240,240,gauge4);
if(chosenOne==4)
img.pushImage(0,0,240,240,gauge5);
if(chosenOne==5)
img.pushImage(0,0,240,240,gauge6);
if(chosenOne==5)
img.drawFloat(result/10.00,2,120,114);
else if(chosenOne==4)
img.drawString(String(result*100),120,114);
else
img.drawString(String(result),120,114);
//img.drawString(String(analogRead(22)), 30,10,2);
a1=angle-4;
a2=angle+4;
if(a1<0)
a1=angle-4+359;
if(a2>=359)
a2=angle+4-359;
if(result<=minValue[chosenOne]+4)
img.fillTriangle(x[angle],y[angle],x2[angle],y2[angle],x2[a2+2],y2[a2+2],TFT_RED);
else if(result>=maxValue[chosenOne]-4)
img.fillTriangle(x[angle],y[angle],x2[a1-2],y2[a1-2],x2[angle],y2[angle],TFT_RED);
else
img.fillTriangle(x[angle],y[angle],x2[a1],y2[a1],x2[a2],y2[a2],TFT_RED);
img.pushSprite(0, 0);
Serial.print("Value of chosenOne: ");
Serial.println(chosenOne); //Debug purpose only
}
Thank you for any help/advice gratefully received as I really want to solve this for future use.
Kind Regards,
Degs