3.2TFT display sensor data

I have a Mega 2560 with the sainsmart 3.2TFT display and shield. It all works fine with the UTFT but now I would like to expand it's use and display a sensors data. I have tried "modifying" the UTFT_ViewFont sketch to no avail. Below is the example I used where I tried replacing a list of fonts with "potval" but I keep getting "invalid conversion from char to const char*" error.

Any help is appreciated.

// UTFT_ViewFont (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the included fonts.
//
// This demo was made for modules with a screen resolution 
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

#include <UTFT.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT myGLCD(ITDB32S,38,39,40,41);   // Remember to change the model parameter to suit your display module!


int pot = A0;         //potentiometer attached to pin A0
char potval = 0;  //value to store sensor reading


void setup()
{
  myGLCD.InitLCD();

  myGLCD.clrScr();
}

void loop()
{
  char val = analogRead(pot);     
  
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);

  myGLCD.setFont(BigFont);
  myGLCD.print(" !\"#$%&'()*+,-./", CENTER, 0);
  myGLCD.print("0123456789:;<=>?", CENTER, 16);
  myGLCD.print("@ABCDEFGHIJKLMNO", CENTER, 32);
  myGLCD.print("PQRSTUVWXYZ[\\]^_", CENTER, 48);
  myGLCD.print("`abcdefghijklmno", CENTER, 64);
  myGLCD.print("pqrstuvwxyz{|}~ ", CENTER, 80);

  myGLCD.setFont(SmallFont);
  myGLCD.print(" !\"#$%&'()*+,-./0123456789:;<=>?", CENTER, 120);
  myGLCD.print("@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_", CENTER, 132);
  myGLCD.print("`abcdefghijklmnopqrstuvwxyz{|}~ ", CENTER, 144);

  myGLCD.setFont(BigFont);
  myGLCD.print((char)potval, CENTER, 190);     //insert potval here

  while(1) {};
}

Bill

Try printnumI instead of print. Or use sprint to format potval as a string.

wildbill,

Tried both suggestions, I get "class UTFT has no member named 'sprint'" . Same for printnuml.

  myGLCD.sprint(potval, CENTER, 190);

oops - autocorrect. I meant sprintf. It's a standard C library function, not a class member.

I got printNumI from here: Electronics - Henning Karlsen

I did some more searching and reading and found this sketch by HazardousMind. It works plus has an analog gauge. :slight_smile: Thanks wildbill. I'll try sprintf as well and see if it works.

#include <UTFT.h>
//#include <ITDB02_Graph16.h>
extern uint8_t BigFont[];
//UTFT myGLCD(ITDB32S, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
//ITDB02 myGLCD(A1,A2,A0,A4,A5,2);
UTFT    myGLCD(ITDB32S,38,39,40,41);

double pi = 3.14159265;
double x = 0, oldx = 50; // setting variable to 0 is not needed, it will be written over anyways, it just looks good.
double y = 0, oldy = 50;// same as above
int rad = 50; // radius 50 pixels
void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setBackColor(50, 50, 50);
  myGLCD.setFont(BigFont);
  myGLCD.setColor(125,255,255);
  myGLCD.fillRect(50,50,150,100);
  delay(1);
}

double mD(double data, double in_min, double in_max, double out_min, double out_max)//Map double
{
  return (data - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void drawNeedle(int sensor,int pos_x, int pos_y){
  double cur = mD(analogRead(A0),0,1023,0,pi);
  x = pos_x + sin(cur + (pi/2)) * rad;
  y = pos_y + cos(cur + (pi/2)) * rad;

  if(x != oldx && y != oldy)
  {
    myGLCD.setColor(125,255,255);
    myGLCD.drawLine(oldx, oldy,pos_x,pos_y);  
    myGLCD.setColor(255,0,0);
    myGLCD.drawLine(x, y,pos_x,pos_y); // (cx, cy, calculated x, calculated y)
    oldx = x; 
    oldy = y;
    myGLCD.printNumF(cur,2,CENTER,10);//used for debugging  
  }
}

void loop(){
  drawNeedle(A15,100,100);
  //delayMicroseconds(30000);//Added to reduce flickering
}

Bill

Thought I would post the actual code I am using to print an analog value to the screen. Maybe some will find it useful.

#include <UTFT.h>

extern uint8_t UbuntuBold[];
UTFT    myGLCD(ITDB32S,38,39,40,41);

const int pot = A0;
byte potval = 0;

void setup()
{
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setBackColor(50, 50, 50);
  myGLCD.setColor(255,255,0);
  myGLCD.setFont(BigFont);
  myGLCD.print("Temp",CENTER,85);
  delay(1);
}



void loop(){

  int potval = map(analogRead(pot),0,1023,-41,312);
  myGLCD.setFont(UbuntuBold);
  myGLCD.printNumI(potval,CENTER,50);//used for debugging  
  delay(25);
  myGLCD.print("   ",CENTER,50);


}

Bill

If and when you ultimately place your value into a float data type, beware of using sprintf on that floating point number, it is not supported in the Arduino environment. It just quietly fails, no error message, no string output (IIRC it just dumps some characters where you number should be in the string).

There is a work-around. http://www.gammon.com.au/forum/?id=12153#trap6