Printing Floats on 1.7" TFT ? Help

Hi all.

I recently purchased on of these. http://arduino.cc/en/Main/GTFT

All the code I have written for my project is currently for use with the 16X9 LCD I had gotten with a kit.
I have now purchased the screen mentioned above and am having trouble/inexperience porting the information onto this screen.

after much much reading I am aware that I can indeed change a float to a string to a char-array!! Numerous way at that.
Problem is I haven't a clue how to do it.

Iv referenced Arduino Playground - FloatToString wich directs me to this avr-libc: <stdlib.h>: General utilities. among'st others

I cannot find where to actually download the library. Even if I did I feel as if iv come as far as I can with the basics and this is going into a trickier territory!!

Also in the tft example( char sensorPrintout[4] :wink: what does the 4 within the square brackets mean. is this a reference to ascii codes?

Here is my code at the moment for the LCD. there is two voltages being displayed and two temperatures.

any help very much appreciated

#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>


int thermoCLK = 7;
int thermoCS = 8;
int thermoDO = 9;
int thermoCS1= 13;
const int diverters =  37;      // the number of the relay 17 pin  (NORMALLY OPEN SOLINOID)
const int pump = 39;  // the number of relay 2 pin 16          (THE PUMP)
const int heater = 6; // The heater relay
const int sensorPin1 = A0; // pressure transducer
const int sensorPin2 = A1; // presseure select by potentiometer
const int buttonPin = 10; // Trigger

const int tankvalve = 31; //solinoid valve 220 ~ V/AC
const int highlevel = 33;//Float switch N/O
const int lowlevel = 35;//Float switch N/O

unsigned long now = millis ();  // time now
//"ALWAYS use unsigned long for timers, not int"
//(variable declaration outside setup and loop, of course)
unsigned long Timer = 3000 ; // number doesnt need to be here ?? makes no difference!!

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS, thermoDO);
Adafruit_MAX31855 thermocouple2(thermoCLK, thermoCS1, thermoDO);
// each of the adafruit thermocouples. Differintialized by the CS PINS

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int trigger = 0;         // variable for reading the trigger status
int fulltank = 0; // initiall states
int emptytank = 0; // initiall states


void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  lcd.print("MAX31855 test");
  // wait for MAX chip to stabilize

  pinMode(diverters, OUTPUT);      
  pinMode(pump, OUTPUT);   
  pinMode(heater, OUTPUT);      // all of these are stating which of he pins are, ins or outs :)
  pinMode(buttonPin, INPUT); 
  pinMode(highlevel,INPUT);
  pinMode(lowlevel,INPUT);
  pinMode(tankvalve,OUTPUT);

  delay(50);
}

void loop() {

  int sensorVal1 = analogRead(sensorPin1);// read the value on AnalogIn pin 0 and store it in a variable

  int sensorVal2 = analogRead(sensorPin2);// read the value on AnalogIn pin 1 and store it in a variable


  float voltage = (sensorVal1/1024.0) * 5.0;  // convert the ADC reading to voltage
  float Pressure = ((voltage-0.5)/.45) ;

  float voltage2 = (sensorVal2/1024.0) * 5.0;  // convert the ADC reading to voltage
  float Pressureselect = ((voltage2-0.5)/.45) ;

  lcd.setCursor(0, 0); 
  // Print a message to the LCD.
  lcd.print("Bar=");
  // set the cursor to column 0, line 1
  // line 1 is the second row, since counting begins with 0
  lcd.print(Pressure,2);
  lcd.print (" ");
  lcd.setCursor(9, 0);  
  lcd.print ("SP="); // Set poinit
  lcd.print (Pressureselect,1);
  lcd.print (" ");

  double blocktemperature = thermocouple1.readCelsius(); //storing what is read in a float/double so it can be used
  double steamtemperature = thermocouple2.readCelsius(); //storing what is read in a float/double so it can be used

  lcd.setCursor(0, 1);
  lcd.print("T(B)="); //actuall wrighting on lcd screen
  lcd.print(blocktemperature,0); //Float value too be printed
  lcd.print (" ");
  lcd.setCursor(9, 1);
  lcd.print("T(H)="); //actuall wrighting on lcd screen
  lcd.print(steamtemperature,0); //Float value too be printed
  lcd.print (" ");

  Serial.println(blocktemperature); 
  Serial.println(steamtemperature);
  Serial.println(voltage);
  Serial.println(voltage2);


  // read the state of the trigger value:
  trigger = digitalRead(buttonPin);
  fulltank = digitalRead(highlevel);
  emptytank = digitalRead(lowlevel);

#define TEMPSETPOINT 705  // Setting the temperature to a value@ #°C
#define TEMPDEADBAND 10 // # refers to #°C
#define PRESSUREDEADBAND 0 // 1 = 1 BAR etc

  if (isnan( blocktemperature))  // isnan means if ther is nothing present in its brackets it can be used to do something
  {
    digitalWrite(heater, LOW); // heaters will not turn on
  }

  if (blocktemperature < TEMPSETPOINT - TEMPDEADBAND)
  { 
    digitalWrite (heater, HIGH);
    //digitalWrite (pinout, HIGH); // this is for when I have more outputs. led or high output for another system
  } 
  else if
    ( blocktemperature > TEMPSETPOINT)
  {
    digitalWrite (heater, LOW);

  }
  if (fulltank == HIGH && emptytank == HIGH) {
    digitalWrite (tankvalve, LOW);
  }

  else if (fulltank == LOW && emptytank == HIGH){
    digitalWrite (tankvalve, HIGH);
  }
  else if (fulltank == LOW && emptytank == LOW){
    digitalWrite (tankvalve, HIGH);
  }

  if (trigger == LOW || (emptytank == LOW)|| isnan(steamtemperature)||(steamtemperature >300)|| ( blocktemperature < 20) ) {     //If any of these statements are true. the pump or valve will not activate.
    // turn diverters off:    
    digitalWrite(diverters, LOW); // this is telling pin  to go LOW ie. Off
  }
  else if (trigger == HIGH && (voltage < voltage2 - PRESSUREDEADBAND)){ 
    // turn relay's sequence:
    digitalWrite(diverters, HIGH); 
    digitalWrite (pump, HIGH);
    (Timer = millis()); // timer is compared to arduino clock and if greater than before it will allow the timer to start once trigger is low
  }
  else if ((voltage > voltage2 - PRESSUREDEADBAND)|| isnan(steamtemperature)||(steamtemperature >300)|| ( blocktemperature < 20)||(emptytank == LOW)){
    digitalWrite (pump, LOW);
  }
  if (Timer> 0 && millis () - Timer > 2000 ) // Time is in milliseconds. 1000 = 1 SECOND.
  {
    digitalWrite (pump, LOW);
  }


  delay(5);
}

.

Here is my code below

Hi.

I have managed to put together this from a few sources. Im quite tired and not quite sure how its working.

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8  

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1 

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char tmp[18] ;
const int pinSensor = A0;
void setup() {
  Serial.begin(9600);
  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);

  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255,255,255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ",0,0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(1);
}

void loop() {

  int potValue = analogRead(pinSensor);
  float volts = 5*(float)potValue/1023;
  String strLab = "Pot Voltage = ";
  char tmp[10];
  dtostrf(volts,1,2,tmp);
  String strOut = strLab + tmp;

  Serial.println(strOut);

  strOut.toCharArray(tmp, 18);
  
  // set the font color
  TFTscreen.stroke(255,255,255);
  // print the sensor value
  TFTscreen.text(tmp, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0,0,0);
  TFTscreen.text(tmp, 0, 20);
}

Hope this helps anyone who has the same problem. Also within this code. i am getting the "pot voltage = #" i a single string. how can i print a static Pot Voltage text and the Variable voltage on its own.

Thanks again.

I am not sure what you mean by this:

Also within this code. i am getting the "pot voltage = #" i a single string. how can i print a static Pot Voltage text and the Variable voltage on its own.

Can you show a template of what you want ?
ie: ["Pot Voltage= "] [SPACE] [VOLTAGE]