Go Down

Topic: Graph a single line from analog read in a TFT (Read 244 times) previous topic - next topic

PaulDLCMx

Oct 20, 2018, 05:57 am Last Edit: Oct 20, 2018, 06:10 am by PaulDLCMx Reason: I forgot to attach the picture
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.


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


DaveEvans

#1
Oct 20, 2018, 06:44 am Last Edit: Oct 20, 2018, 06:46 am by DaveEvans
Just draw pixels at the appropriate points instead of lines.

PaulDLCMx

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  :smiley-cry:

DaveEvans

What parameters does the library require for drawPixel?

PaulRB

#4
Oct 20, 2018, 09:18 am Last Edit: Oct 20, 2018, 10:27 am by PaulRB


Try this (untested):
Code: [Select]
#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);
}

PaulDLCMx

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)'


AWOL

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

So, lose the float.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

PaulRB

#7
Oct 20, 2018, 06:04 pm Last Edit: Oct 20, 2018, 06:10 pm by PaulRB
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.

PaulDLCMx

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

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

PaulRB

#9
Oct 20, 2018, 08:02 pm Last Edit: Oct 20, 2018, 08:06 pm by 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

Go Up