Graph a single line from analog read in a TFT

Hello, thanks for view my post.

I'm triyng to make a graph in a 3.5 TFT LCD SHIELD from an analog read and what I get is a bis section of the screen being filled with the line, but I need a single line, could be just a pixel of width.

The graph I try to see must be between 19 mm and 19 mm, just in the middle of the Y axis, actually I have solved this but the graph fills half of the screen and I can't get how to make just a line, just like when you open the Serial Plotter. I'm using a TFT that has the ILI9486/ILI9488 chip, and I made this run with the MCUFRIEND_kbv.h library. I attach the code and a picture of how my graph is.

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

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

int xPos = 0;
int n=0;

int16_t ht = 16, top = 3, line, lines = 15, scroll;

void setup(){
  tft.reset();
    uint16_t id = tft.readID();
    tft.begin(id);
    tft.setRotation(1);
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE); 
     }

void loop(){
  float sensor = analogRead(A5);
  float volt=sensor*5/1024;
  //If chnages to map(sensor,0,1023....) it will fill all the pot ohm value
  float graphHeight = map(sensor,410,614,0,tft.height());
  tft.drawLine(xPos, tft.height() - graphHeight, xPos, tft.height(),WHITE);
  if (xPos >= 480) {
    xPos = 20;
    tft.fillScreen(BLACK);
    tft.setCursor(120,10);
    tft.print("Seismic Wave Sensor");
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
   tft.setCursor(120,300);
  tft.print("INGENIERIA GEOFISICA");
  tft.drawLine(20,60,20,260,WHITE);
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.setCursor(30,50);
  tft.print("19 mm");
  tft.setTextSize(2);
  tft.setTextColor(WHITE);
  tft.setCursor(30,260);
  tft.print("19 mm"); 
  } 
  else {
    xPos++;
      }
   delay(16);
}

I think my problem could be in the part of graphHeight or the tft.drawLine, but I have been using Arduino for short time, and I know you are experts in this. Please I really need help :frowning:

Just draw pixels at the appropriate points instead of lines.

Do you mean that I should use the tft.drawPixel instead of tft.drawLine? I just did it,but I really don't realize how to modify this part:

float graphHeight = map(sensor,0,1023,0,tft.height());
tft.drawPixel(xPos, tft.height() - graphHeight, xPos, tft.height(),WHITE);

Of course, the library requires other parameters :sob:

What parameters does the library require for drawPixel?

Try this (untested):

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

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

int xPos = 20, xPosPrev = 20;
int n = 0;
int graphHeightPrev = 0

int16_t ht = 16, top = 3, line, lines = 15, scroll;

void setup() {
  tft.reset();
  uint16_t id = tft.readID();
  tft.begin(id);
  tft.setRotation(1);
  tft.fillScreen(BLACK);
  tft.setTextColor(WHITE);
}

void loop() {
  int sensor = analogRead(A5);
  //If chnages to map(sensor,0,1023....) it will fill all the pot ohm value
  int graphHeight = map(sensor, 410, 614, 0, tft.height());
  tft.drawLine(xPosPrev, tft.height() - graphHeightPrev, xPos, tft.height() - graphHeight, WHITE);
  graphHeightPrev = graphHeight;
  if (xPos >= 480) {
    xPos = 20;
    xPosPrev = 20;
    tft.fillScreen(BLACK);
    tft.setCursor(120, 10);
    tft.print("Seismic Wave Sensor");
    tft.setTextSize(2);
    tft.setTextColor(WHITE);
    tft.setCursor(120, 300);
    tft.print("INGENIERIA GEOFISICA");
    tft.drawLine(20, 60, 20, 260, WHITE);
    tft.setTextSize(2);
    tft.setTextColor(WHITE);
    tft.setCursor(30, 50);
    tft.print("19 mm");
    tft.setTextSize(2);
    tft.setTextColor(WHITE);
    tft.setCursor(30, 260);
    tft.print("19 mm");
  }
  else {
    xPosPrev = xPos;
    xPos++;
  }
  delay(16);
}

DaveEvans:
What parameters does the library require for drawPixel?

It requires: no matching function for call to 'MCUFRIEND_kbv::drawPixel(int&, float, int&, int16_t, unsigned int)'

no matching function for call to 'MCUFRIEND_kbv::drawPixel(int&, float, int&, int16_t, unsigned int)'

So, lose the float.

AWOL:
So, lose the float.

I'm not sure that's the problem. The code in the OP compiled ok, and I would not expect drawLine() to accept a float and drawPixel() not accept a float, so I think an implicit conversion to int must have been going on.

I think it's the number of parameters that is the problem. drawPixel() expects 2 fewer parameters than drawLine() I would imagine.

@Paul did you try my code from post #4?

@AWOL I removed the uneccessary use of float in my suggested code changes.

YES PaulRB!!! It really works!
Thank you so much!! and sorry for takin a lot of time to answer!! :smiley:

So for that, the last code is the one you gave me!


Thank me by working out for yourself what changes I made and, for any that you don't understand, asking me why, and then taking the time to understand them yourself

i have used this code mr.paul rb but i have not received the single analog graph
can you please guide me to get the output as u get.

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

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

int xPos = 20, xPosPrev = 20;
int n = 0;
int graphHeightPrev = 0

int16_t ht = 16, top = 3, line, lines = 15, scroll;

void setup() {
tft.reset();
uint16_t id = tft.readID();
tft.begin(id);
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
}

void loop() {
int sensor = analogRead(A5);
//If chnages to map(sensor,0,1023....) it will fill all the pot ohm value
int graphHeight = map(sensor, 410, 614, 0, tft.height());
tft.drawLine(xPosPrev, tft.height() - graphHeightPrev, xPos, tft.height() - graphHeight, WHITE);
graphHeightPrev = graphHeight;
if (xPos >= 480) {
xPos = 20;
xPosPrev = 20;
tft.fillScreen(BLACK);
tft.setCursor(120, 10);
tft.print("Seismic Wave Sensor");
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(120, 300);
tft.print("INGENIERIA GEOFISICA");
tft.drawLine(20, 60, 20, 260, WHITE);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(30, 50);
tft.print("19 mm");
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(30, 260);
tft.print("19 mm");
}
else {
xPosPrev = xPos;
xPos++;
}
delay(16);
}

PaulRB:


Thank me by working out for yourself what changes I made and, for any that you don't understand, asking me why, and then taking the time to understand them yourself

can you please help me out this problem

Please do not post code without using code tags. Modify your post above and correct it.