Go Down

Topic: 2.4 TFT LCD helpp (Read 2023 times) previous topic - next topic

JacksonJoe21

Thank you for your big help david! :) Appreciate all your help. God bless you :)

david_prentice

I am pleased that your TFT is working now.   You should always plug the Shield into the Uno.
What ID is reported by the graphictest_kbv.ino sketch? 
Please run the LCD_ID_readreg.ino sketch again.    An ID of 0x0501 is very unusual.
Which ID worked best for you?

It is very likely that someone else has the same Display Shield as you.    The information would help others.

David.

JacksonJoe21

Hi david.. I will run the LCD_ID_readreg.ino later, I also found out that the problem is some ports are not properly connected because of the cover of the arduino uno.. I'm at school.. but anyway I have another problem.. I'm trying to display the rating of a 9V battery with the voltage divider using 3-30kohms and 1-10kohms but I get a rating of 0. This is my code..

#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

david_prentice

First off.   Please edit your post to use CODE tags i.e. the select the text,  click the icon on top left.

1.   Any TFT program needs to call tft.begin(ID) with the controller ID e.g.
Code: [Select]

    uint16_t ID = tft.readID();  //identify your controller
    tft.begin(ID);   //configure for the correct controller
    ...


2.   Most Analog read values need to be converted to a human readable form.
Code: [Select]

    uint16_t readVal = AnalogRead(5);   //read integer value
    float voltage = readVal * (5.0 / 1024);  //scale it to volts


Think about my scaling method.   Then look at your statement.   Take a pencil and paper and do the calculation yourself.   Note that an integer divide always produces an integer result.  i.e. it thows away any remainder.

David.

JacksonJoe21

Hi david.. I update my code to this..

 
Code: [Select]
  #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) {
   
  tft.reset();

  uint16_t ID = tft.readID();
  tft.begin(ID); 
 
  Serial.begin(9600);

}


void loop(void) {

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


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

 
  Serial.print("Voltage Rating: ");
  time = micros();
  uint16_t readVal = analogRead(5); 
  float voltage = readVal * (5.0 / 1024);
   
   
  tft.setCursor(0, 0);
  tft.setTextColor(BLACK); 
  tft.setTextSize(2);
  tft.print(" ");
  tft.println(" ");
  tft.println(" ");
   
  Serial.println(voltage);
  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.print("   VOLTAGE RATING :" );
  tft.println(voltage);
}
 



I'm now also using 1-30.2kohms and 3-kohms for my voltage divider, found out that the resistances are not exactly 10kohms and 30kohms.. I'm now getting this value(attached).. but my input voltage is 9.45V.. What must be the problem?

david_prentice

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:
Code: [Select]
    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.

JacksonJoe21

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...

Code: [Select]


/*
  ReadAnalogVoltage
  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:
  int sensorValue = analogRead(A5);
  // 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..

david_prentice

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

You can read the battery voltage with the DMM.   Read the voltage at  the ADC pin.   Read the VCC for your Arduino.

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.

JacksonJoe21

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

Code: [Select]


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

/*
  ReadAnalogVoltage
  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();
  uint16_t ID = tft.readID();
  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();
  uint16_t readVal = analogRead(5); 
  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!

david_prentice

It is your thesis and your education.

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.

Have you tried averaging 4 ADC readings?

David.

JacksonJoe21

haven't tried that yet. but I will now. thank you. :)

JacksonJoe21

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.

david_prentice

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.
Nowadays,  Google skills are probably as important as basic Maths.

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.

JacksonJoe21

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

JacksonJoe21

Is this correct?



Code: [Select]


 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...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy