# 2.4 TFT LCD helpp

Think about it. You are reading the voltage at A5. And it is 2.62V

Your Solar Battery has a voltage of 10.48V.
Your 30k, 10k resistors divide it by 4. Hence you read 2.62V

If you want to see the human-readable voltage:

``````    float voltage = readVal * ((5.0 / 1024) / (10000 / (10000 + 30000));  //scale it to volts
``````

You could calculate the scaling value yourself. If you leave the resistor values in the expression, the Compiler does the maths for you.

The important lesson is: do you understand how to calculate from a potential divider? i.e. resistor values.
And do you understand how to calculate a voltage from the ADC value?

You must write the explanation into your thesis.

The other lesson is: float maths keeps the fractional remainder. integer maths loses the remainder.

David.

I’m trying to measure the voltage of a 9V battery before I connect it to our generator, the rating from the voltmeter must be equal to the rating made by arduino right?

I used, R1 = 30.2kohms and R2 = 9.75kohms , Vin = 9.38 when I tested it using voltmeter

Vout = (9.75 / (9.75 + 30.2) ) * 9.38 = 0.244V

I’m having a hard time displaying the same voltage as the input,

I tried the code from arduino…

``````/*
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0) / 0.2440550688 ;
// print out the value you read:
Serial.println(voltage);
delay(1000);
}
``````

attached also is the result…

Nothing is ever perfect. Your DMM will have a tolerance for reading resistors. And a better tolerance for reading voltage.

Then put those values into your calculations. It is common practice to take multiple ADC readings and average them. All the same your "single" values range from 9.85 to 10.17V. If your actual voltage is 10.01V your readings are -1.5% to +1.5% accurate. I would be happy with that.

You have probably noticed that if your "5.0V" is nearer 4.6V, all the calculations become nearer 9.0V

In practice, you check the "5.0V" with the BandGap reference.

David.

I tried using 4.6V, the results are more nearer with the DMM.

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

/*
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

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

unsigned long time;

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:

tft.reset();
tft.begin(ID);
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {

for(uint8_t rotation=0; rotation=1; rotation++) {
tft.setRotation(rotation);
testText();
delay(1000);

}
}

unsigned long testText() {
tft.fillScreen(WHITE);
unsigned long start = micros();

tft.setCursor(0, 0);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print(" ");
tft.println(" ");
tft.println(" ");

Serial.print("Voltage Rating: ");
time = micros();
float voltage = readVal * (4.6 / 1023) / 0.25;

Serial.println(voltage);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("   VOLTAGE RATING :" );
tft.println(voltage);
}
``````

I tried this code… but is this result normal? … thank you so much david!

You should study your textbooks and lecture notes.
Google and Wikipedia are very useful. Many Wikipedia technical articles are better written than the top textbooks.

You and your colleagues can discuss your project. It would be wrong for us to do the work for you.

David.

haven’t tried that yet. but I will now. thank you.

David, I'm done with measuring the voltage, I'm satisfied with what I'm getting now. but my problem is measuring the current, do I need to use a current sensor? If yes, where do I need to put the pins? pin A0-A5 is already used. Thanks!

Jack.

A Uno clone with SMT AVR has extra Analog pins: A6, A7
This gives you extra channels.

If you have a DIP-28 AVR, you would need to have a manual switch to select different sources to A5.

You can measure current by reading the voltage across a resistor.

I am sure that you can Google for similar projects. See how other people do it.

However you choose to design your project, understanding and documenting the design is the most important part of a thesis.

I would appreciate it if you answered my questions in #16.

David.

Running the LCD_ID again this was the result..

Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 77 83 ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 00 00 00 Manufacturer ID
reg(0x0009) 00 00 00 00 00 Status Register
reg(0x000A) 00 00 Get Powsr Mode
reg(0x000C) 00 00 Get Pixel Format
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x0070) 00 FF Panel Himax HX8347-A
reg(0x00A1) 00 00 00 00 00 RD_DDB SSD1963
reg(0x00B0) 00 00 RGB Interface Signal Control
reg(0x00B4) 00 00 Inversion Control
reg(0x00B6) 00 12 00 12 00 Display Control
reg(0x00B7) 00 00 Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 00 00 00 00 00 00 00 00 Panel Control
reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA
reg(0x00CC) 24 47 Panel Control
reg(0x00D0) 00 00 00 Power Control
reg(0x00D2) 00 00 00 00 00 NVM Read
reg(0x00D3) 00 00 00 00 ILI9341, ILI9488
reg(0x00DA) 00 00 RDID1
reg(0x00DB) 00 00 RDID2
reg(0x00DC) 00 00 RDID3
reg(0x00E0) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA-P
reg(0x00E1) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA-N
reg(0x00EF) 00 00 00 00 00 00 ILI9327
reg(0x00F2) 00 00 00 00 00 00 00 00 00 00 00 00 Adjust Control 2
reg(0x00F6) 00 01 00 01 Interface Control

Is this correct?

`````` float current = (voltage / 0.25);
tft.println(" ");
tft.println(" ");

Serial.println(current / 38950);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("  CURRENT RATING :" );
tft.print(current/38950);
tft.println("mA");
``````

but in the serial monitor it only shows zero...

Thanks for the readreg output. This makes a lot more sense than your earlier report in #5.

You have an ST7781 controller which is (or was) fairly common.

I suggest that you post a schematic of your "current reading" circuit.

Most importantly, you should explain how you derived your calculations.

David.

Hi david this is how I got my calculation… pardon for my writing erasures…

Think about it. You charge batteries with Solar cells.
You want to know the voltages produced by the Solar cells.
You want to know the battery voltage.
You want to know the charging current from the Solar to the battery.
You want to know the load current supplied from the battery to your actual appliances.

The current in the measuring circuit is trivial i.e. 225uA. Your battery is probably going to self-discharge faster without any load at all.

Draw the whole circuit. Then draw arrows with a pencil. i.e. where each current flows in the network.
Then think about how to do the measuring. Where to place any sense resistors.

I presume that you have all been studying for your University degrees. You should be able to analyse networks. Do Ohm's Law and Kirchoff's Law calculations. Your whole group should sit down together. Discuss how to do your project.

The Internet is very useful. Read App Notes from Solar Cell and battery manufacturers. Read projects from other students. It is your job to do the studying.
It will also help when you get your first paid job. i.e. how to find and learn from other peoples' work.
It is no good expecting people to do your school project for you.