How can print float to a TFT display

Hi,

I would like to display output from INA219 sensor to a ILI9225 display. Anyone can support with code?

What have you tried?

What were the results?
"it didn't work" is not acceptable answer.

Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Hi bro..

I have tried using tft.drawText, it shows error.

float x = 1.2;
tft.print(x);

If you are reading a floating point number, why do you think drawText() will work? You have to convert your floating point number to a string before you can use drawText().

Since you won't post any code, only you know that answer

Post the code that you tried in code tags. The entire code.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Without seeing the code and the error message I don't see how we can help.

Please find the project details

Purpose - An equipment for testing the Wheel Speed Sensor
Measuring parameter - Current -mA
Test Range : 4.5 - 8.5 mA
Test Voltage -12 VDC
Components

  1. Arduino Uno
  2. INA 219 current / Voltage sensor
  3. 2.2 Inch TFT display (ILI9225 driver IC)

Problem Facing - Unable to display the measure value on the TFT
Code

#include <TFT_22_ILI9225.h>
#include <SPI.h>

#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;

float numReadings = 50;
float readings[50];
int index = 0;
float sensorMax = 0;
float sensorMin = 0;

// display setting

#include <../fonts/FreeSans12pt7b.h>
#include <../fonts/FreeSans24pt7b.h>
#define TFT_RST 8
#define TFT_RS 9
#define TFT_CS 10 // SS
#define TFT_SDI 11 // MOSI
#define TFT_CLK 13 // SCK
#define TFT_LED 3 // 0 if wired to +5V directly

#define TFT_BRIGHTNESS 200 // Initial brightness of TFT backlight (optional)

// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED, TFT_BRIGHTNESS);
// Use software SPI (slower)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED, TFT_BRIGHTNESS);

// Variables and constants
uint16_t x, y;
boolean flag = false;

// display setup completed

void setup(void)
{
tft.begin();
tft.clear();

Serial.begin(115200);
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);

float maximum = 0;
float minimum = 1023;

}

uint32_t currentFrequency;

Serial.println("Hello!");

// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
if (! ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) {
delay(10);
}
}
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
ina219.setCalibration_16V_400mA();

Serial.println("Measuring voltage and current with INA219 ...");

sensorMax = digitalRead(SDA);
sensorMin = sensorMax;
}

void loop(void)
{

float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;

shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);

// MEASUREMENTS
// every iteration of loop makes one additional measurement,
// so the first 10 readings will display too low average
float value = current_mA;
readings[index] = value;
index++;
if (index >= numReadings) index = 0;

// DO SOME MATH
if (value > sensorMax) sensorMax = value;
if (value < sensorMin) sensorMin = value;

// OUTPUT TO SERIAL

if (sensorMax >20 )
{
Serial.print ( "NG" );
Serial.print ( " Cable Short" );
while(true);
}
else if (sensorMin<.3)
{
Serial.print ( "NG");
Serial.print ( " Cable Open" );
while(true);
}
else
{
Serial.print("\tI LOW:\t");
Serial.print(sensorMin);
Serial.print("\tI MAX:\t");
Serial.print(sensorMax);

Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power:         "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");

tft.drawRectangle(10, 10, tft.maxX() - 1, tft.maxY() - 1, COLOR_WHITE);
tft.setFont(Terminal6x8);
tft.drawText (10, 10, sensorMin );

delay(5000);

}}

Please post code in code tags. Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Arduino: 1.8.16 (Windows 7), Board: "Arduino Uno"





















C:\Users\Ganesh Babu\Desktop\display\display.ino: In function 'void loop()':

display:135:35: error: no matching function for call to 'TFT_22_ILI9225::drawText(int, int, float&)'

   tft.drawText (10, 10, sensorMin );

                                   ^

In file included from C:\Users\Ganesh Babu\Desktop\display\display.ino:1:0:

C:\Users\Ganesh Babu\Documents\Arduino\libraries\TFT_22_ILI9225\src/TFT_22_ILI9225.h:269:19: note: candidate: uint16_t TFT_22_ILI9225::drawText(uint16_t, uint16_t, String, uint16_t)

         uint16_t  drawText(uint16_t x, uint16_t y, STRING s, uint16_t color = COLOR_WHITE);

                   ^~~~~~~~

C:\Users\Ganesh Babu\Documents\Arduino\libraries\TFT_22_ILI9225\src/TFT_22_ILI9225.h:269:19: note:   no known conversion for argument 3 from 'float' to 'String'

exit status 1

no matching function for call to 'TFT_22_ILI9225::drawText(int, int, float&)'



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The error clearly tells you you need to pass STRING you are passing float. Convert float to string first.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.