Displaying voltage rating to 2.4 TFT LCD

Good day! I just wanna ask for you help guys about what’s wrong with my code and connection. I’m trying to display a voltage rating of a 9V battery. I used 3-30kohm resistor and 10kohm resistor for the voltage divider to get an answer of 0.1xVi. I’m just getting a hard time coding it and making the 2.4 lcd display the rating.Can you help me please? thank you! Attached are our schematic,design of the system generator and actual connections of voltage divider. thank you :slight_smile:

VD.PNG

Attached are our schematic,design of the system generator and actual connections of voltage divider.

But, no code. This IS the Programming section, where we talk about CODE!

PaulS:
But, no code. This IS the Programming section, where we talk about CODE!

Sorry sir i forgot to upload the code. Haha… here’s what im working on…

#include <Adafruit_GFX.h> // Core graphics library
#include <MCUFRIEND_kbv.h> // Hardware-specific library
MCUFRIEND_kbv tft;

// The control pins for the LCD can be assigned to any digital or
// analog pins…but we’ll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
// #define LCD_CS A3 // Chip Select goes to Analog 3
// #define LCD_CD A2 // Command/Data goes to Analog 2
// #define LCD_WR A1 // LCD Write goes to Analog 1
// #define LCD_RD A0 // LCD Read goes to Analog 0

// #define LCD_RESET A4 // Can alternately just connect to Arduino’s reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
// D0 connects to digital pin 8 (Notice these are
// D1 connects to digital pin 9 NOT in order!)
// D2 connects to digital pin 2
// D3 connects to digital pin 3
// D4 connects to digital pin 4
// D5 connects to digital pin 5
// D6 connects to digital pin 6
// D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF

// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// SWTFT tft;

unsigned long time;

void setup(void) {

Serial.begin(9600);

}

void loop(void) {
Serial.print("Voltage Rating: ");
time = micros();
int readVal = analogRead(5);
float voltage = (readVal/1024)5;
Serial.println(voltage);
tft.setCursor(2, 2);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.println(voltage
10);
}

I got
Voltage Rating = 0 …
Voltage Rating = 0 …
Voltage Rating = 0 …
Voltage Rating = 0 …
Voltage Rating = 0 … in the serial monitor

readVal is an int, with a value in the range 0 to 1023.

0/1024 is 0 1023/1024 is 0.

So, the code is working perfectly.

0/1024.0 is 0 1023/1024.0 is 0.999

But there's no display on my 2.4 TFT sir? Its just a white screen.. Is also trying to get a rating of 9V not possible? I'm trying to make my arduino a voltmeter, is what I'm doing right? Thank you for help. Appreciate it sir.

But there's no display on my 2.4 TFT sir?

How am I supposed to know that?

If you are seeing nothing on the TFT, the problem is not with the code you posted. I'm sure that the library comes with examples. Run one of them. Do you see anything on the screen?

Is also trying to get a rating of 9V not possible?

You are not supplying 9V to the Arduino. At least, I hope you aren't. You appear to be supplying up to 9V to a voltage divider that supplies 1V to the Arduino. Why you assume that 1V means 5V is beyond me.

Yes sir I tried running some of the examples from the library, and they worked. But right now I'm getting a white screen. I don't know what's wrong with this..

I get it sir thank you. are there things to change on my code to display the actual battery rating of the battery?

Thank you for help sir.

Looks to me like you need to talk to this guy. From his posts, it looks like MCUFRIEND_kbv.h is his code.

-jim lee