Hi there,
I am making a small sketch that will show value's of a Adafruit INA219 on a ILI9325 TFT LCD.
I already have a picture on the screen and now i wanted to print the value's that the INA219 measured.
Now the problem is that i get a value of 465 on my screen (the voltage it measures is 4.65) but now i want to add a comma/dot to make it easier to read.
like for example i have 13.42 Volts, the arduino will print on the display 1342 and if i would for example put 4.65 volt on the module it would display me 465. Now there is nothing wrong with the measured value's since the serial monitor outputs it all correctly but its just the display that wont show it correctly.
I am using the UTFT GLUE library that was included in the MCUFRIEND_kbv library that i use for my ILI9325 display. And i am also using adafruit's INA219 and GFX library.
The sketch & a picture is included (for some reason the picture doesn't want to upload correctly, a link to the picture is http://imgur.com/a/09WTI )
Any help would be appriciated 
getcurrent.ino (3.17 KB)
Why are you using UTFTGLUE?
It looks as if most of your calls are to Adafruit_GFX style methods.
I suggest that you stick to one style or the other. Obviously the GFX methods are available to you because the GLUE class inherits them.
But if you simply want to print LoadVolt as a float instead of an integer, you would say:
float floatVolt = loadVolt * 0.01;
tft.printNumF(floatVolt, 2, 30, 45); //2 decimal places
tft.printNumF(floatVolt, 2, 30, 45, ',', 5, ' '); //2 decimal places with full format
I am not sure how well earlier versions of UTFTGLUE handle the formatting of printNumF()
If you want to use a comma instead of a period, I doubt if I support that.
David.
Thanks David!
It worked perfectly 
And the answer to why i am using UTFT GLUE is that was the only library that i could get working with my LCD. The normal UTFT library should support it since it is in the list of supported devices but for some reason i only get a white display, which it normaly does when it gets power.
But i have gotten used to the UTFT GLUE library so that is why i use it
And again thanks! 
If you have some legacy UTFT programs, UTFTGLUE is a very handy way to run them on MCUFRIEND_kbv displays.
But seriously, please do the job properly. e.g. start with tft.InitLCD()
If it is a new program, I would use the Adafruit_GFX methods. They are far more intuitive.
I note that you are forcing ID=0x9325. What controller ID do you actually have?
David.
i am forcing 9235 since i have that controller and if i dont force it but make it auto detect it wont see the driver properly and i just get a unknown driver back.
And sadly the code you send me works, As long if i dont go over 320mA (yes it measures mA too).
If i go over it the measurements start to do weird stuff. it will often jump into the minus. it there a overflow happening in my code?
You should always get the correct ID with tft.readID()
and if you are using UTFTGLUE, tft.InitLCD(LANDSCAPE) will read the ID and initiliase any class variables correctly.
Your current_mA = ina219.getCurrent_mA();
statement uses an f-p variable. So I can't see any problems.
When you get unexpected minus signs, this generally means that you have overflowed an int16_t expression.
I do not know your ina219 library. What values are displayed on your Serial Terminal.
Incidentally, if you used regular Adafruit_GFX methods, it would give you identical results to the Serial Terminal. Because GFX and Serial both inherit from the same Stream class.
Seriously, for a small project like yours, I would rewrite it exclusively with GFX methods. (i.e. regular MCUFRIEND_kbv library)
David.
When it goes into the minus the serial monitor still shows me the correct values.
And also the mW values are going nuts when the mA goes over a sertain value.
If i only use like 20mA the watt calculations are 100% accurate. but when it goes over a sertain value the mW meter goes into the minus and displays like -80 to -100. So i think a overflow is happening somewhere. but i dont know where and i am also not 100% sure if it is a overflow.
But in short the values are correct in the serial monitor and not on the display.
Oh and the mW value is not properly displayed on my display and serial monitor when it goes over a sertain value.
A new version of the sketch is included with this message
getcurrent.ino (3.84 KB)
Well, it is obvious.
current_mA = ina219.getCurrent_mA();
...
int LoadAmp = current_mA * 100;
...
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
...
float floatAmp = LoadAmp * 0.01;
tft.printNumF(floatAmp, 2, 40, 90, ',', 5, ' ');
It would have been useful to paste the Serial Terminal together with the wrong TFT values.
Think about it. If current_mA is > 327mA you will get negative values for LoadAmp. And floatAmp will just reflect this.
Since you have already got "good" values from the ina219, I would use these values. It is when you do inappropriate integer conversions that we go wrong.
And think how much more intuitive it would be to say tft.print(current_mA) in the first place. GFX methods would know it is f-p.
David.
I did what you told me. But sadly this will only show me a part of the value.
If the current is like for example 19.90 it will only show me 19 on the tft
What should i do to show the intire value?
Rubbish.
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
tft.printNumF(loadvoltage, 2, 30, 45, ',', 5, ' ');
tft.printNumF(current_mA, 2, 40, 90, ',', 5, ' ');
tft.printNumF(loadvoltage * current_mA, 2, 40, 135, ',', 5, ' ');
Note that you can always choose 0 for the number of decimals. e.g. if you just want to display an integer result. This method will do the proper rounding. If you just cast a f-p to an int, it always truncates.
Thank you! 
Now it works perfectly and it isnt going in the minus again!
Thank you again! 