Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

(solved) ILI9341 2.2" TFT timelapse/scrolling graph, could use help!

Status
Not open for further replies.

fezder

Well-Known Member
So, I'm making scrolling graph for my car computer instead of "boring" digit display only. I have working sketch on 128x32 OLED display, but turns out, OLED screen is way different to control than TFT. TFT I control now with teensy 3.2, oled worked with pro mini. I have gotten TFT to work with pro mini also with level shifters & resistos.
So this appearance is goal:
code for it:
C:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
int count;
int sensorArray[128];
long previousMillis = 0;  // will store last time LED was updated



void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  //display.invertDisplay(true);
  for (int count = 0; count <= 128; count++) //counts up from 0 to 159
  {
  sensorArray[count] = 0; //this 'zeros' all array elements(?)
  }
}


void loop()
{
  display.drawLine(0, 0, 0, 32, WHITE);
  display.drawLine(80, 0, 80, 32, WHITE);

  display.drawLine(80, 0, 75, 0, WHITE);
  display.drawLine(80, 10, 75, 10, WHITE);
  display.drawLine(80, 20, 75, 20, WHITE);
  display.drawLine(80, 30, 75, 30, WHITE);

  display.drawLine(0, 0, 5, 0, WHITE);
  display.drawLine(0, 10, 5, 10, WHITE);
  display.drawLine(0, 20, 5, 20, WHITE);
  display.drawLine(0, 30, 5, 30, WHITE);


  display.drawPixel(10, 0 , WHITE);

  display.drawPixel(20, 0, WHITE);
  display.drawPixel(30, 0, WHITE);
  display.drawPixel(40, 0, WHITE);
  display.drawPixel(50, 0, WHITE);
  display.drawPixel(60, 0, WHITE);
  display.drawPixel(70, 0 , WHITE);

  int drawHeight = map(analogRead(A0), 0, 1023, 0, 32 );
  sensorArray[0] = drawHeight;

  for ( int count = 1; count <= 80; count++ )
  {
  display.drawPixel(count, 32 - sensorArray[count - 1], WHITE);

  //display.drawLine(count, 1, count, 32 - sensorArray[count - 1], WHITE);
  }
  display.setCursor(90, 0);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.print(drawHeight);
  display.setCursor(90, 8);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.print("KM/h");
  display.display();  //needed before anything is displayed
  display.clearDisplay(); //clear before new drawing
  //delay(1000);

  /*unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > 375)
  {
  previousMillis = currentMillis;
*/
  for (count = 80; count >= 2; count--) // count down from 160 to 2
  {
  sensorArray[count - 1] = sensorArray[count - 2];
  }
  //}

}
And this I have thus far in TFT:
There is two different drawing methods I experimented, first one draws on top of previous one, and latter one clears screen after each sweep, both methods are seen in video.
and current TFT code:
C:
/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
****************************************************/


#include "SPI.h"
#include "ILI9341_t3.h"

// For the Adafruit shield, these are the default.
#define TFT_DC  9
#define TFT_CS 10
#define screenx 240
#define screeny 320
int count;
int sensorArray[128];
long previousMillis = 0;  // will store last time LED was updated

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

void setup()
{
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);

  for (int count = 0; count <= 128; count++) //counts up from 0 to 159
  {
  sensorArray[count] = 0; //this 'zeros' all array elements(?)
  }
}


void loop(void)
{

  /*
  for(int i =0; i<240; i++)
  {
  int height = map(analogRead(A0), 0, 1023, 0, 240);
  tft.fillRect(i, 280 - height, 1, height, ILI9341_GREEN);
  tft.fillRect(i, 280 - 240, 1, 240 - height, ILI9341_RED);
  delay(100);
  }*/


  //  tft.fillScreen(ILI9341_BLACK); //this line switches between clear/write-on-top


  for (int i = 320; i > 40; i--)
  {

  int height  = map (analogRead(A0), 0, 1023, 0, 220);
  sensorArray[0] = height;

  //start of screen
  tft.drawLine(20, 40, screenx, 40, ILI9341_RED);
  tft.drawLine(20, 112, screenx, 112, ILI9341_RED);
  tft.drawLine(20, 168, screenx, 168, ILI9341_RED);
  tft.drawLine(20, 224, screenx, 224, ILI9341_RED);
  tft.drawLine(20, 280, screenx, 280, ILI9341_RED);
  tft.drawLine(20, 320, screenx, 320, ILI9341_RED);


  tft.drawLine(20, 40, 20, screeny, ILI9341_RED);
  tft.drawLine(76, 40, 76, screeny, ILI9341_RED);
  tft.drawLine(132, 40, 132, screeny, ILI9341_RED);
  tft.drawLine(188, 40, 188, screeny, ILI9341_RED);
  tft.drawLine(240, 40, 240, screeny, ILI9341_RED);
  //end of screen

  tft.fillRect(20, i, 240 - height, 1, ILI9341_GREEN); //these could be lines alse
  tft.fillRect(240 - height, i, 240, 1, ILI9341_BLUE);

  delay(100); //determines speed of drawing
  }
}
Also FFT on TFT is on-to-do list, but that'd require whole screen to be drawn "instantly", I do have working FFT on OLED.
 
Made at least observation that those menu thingies isnide loop take LOT of time, screen updates LOT faster when I take those out, and allows instant update of screen :) So slight process.
Oh yes, here's FFT on 2.2" TFT:
 
Last edited:
Good work. I love these displays.

I know the arduino isn't the fastest at this, but I'm wondering how optimized these drivers are. I know I'm using drivers that someone optimized before hand. You can do some tricks, like sending the largest SPI values available rather than just 8bit blocks. I'm not using the arduino, though.
 
Lude, in fact i got scroling working now. Here's code bits:
C:
int count;
int sensorArray[330];
  sensorArray[0] = height;  //most up-to-date data shows up at first element

  for ( int count = 1; count <= 320; count++ )  //quick loop for scrolling peak-meter
  {
  tft.drawLine(0, 320 - count, 240 - sensorArray[count - 1], 320 - count, ILI9341_BLACK); //these work in sorta push-pull manner, two different colour lines to combat each other
  tft.drawLine(240 - sensorArray[count - 1], 320 - count, 240, 320 - count, ILI9341_GREEN); //tft.drawLine(Startx, Starty, Endx,Endy, COLOUR), remember, to make perpendicular line, starty==endy OR startx==endx, depending how you want to screen to draw, this can be confusing at first
  }

  for (count = 320; count >= 2; count--) //small routine for moving data inside array
  {
  sensorArray[count - 1] = sensorArray[count - 2];
  }

This was part of bigger project, for clarity I don't post full code as 80% of code is irrelevant for this problem :) Oh, and I use teensy 3.2 so speed is not issue.
 
Another problems arised, well buddy suggested improvements; logharitmic scaling for FFT and spectrogram. There is now linear scaling on FFT between 46hz-16khz, and all relevant information is at other end of screen. Indeed, log-scale would make more sense
 
I got one of these displays about 2 months ago and found them great, so I started basing some projects around them.

I've made this PCB that fits right on the back of the LCD display. My purpose is to make this into a touch screen remote. Simple home automation stuff. Talk to dimmers and my gas fireplace and whatever else I can think of. The board and display is pretty versatile though. I have another non-touch one I'll be using as a graph and display showing power usage and environment stuff for my camper/trailer.

Unfortunately I put all the pins upside down for the display. This PCB is supposed to have the components face the inside and have a blank board on the outside. I ordered a new set of boards with the correct pin orientation.
lcd-touch-remote_20160504-1.jpg


lcd-touch-remote_20160504-2.jpg


 
Hmm, I now have working skect, test, for making array of logharitmic scale-values (-3db for testing)
Now then, issue is to find closest value from array.
In final project there are 240 values in array, so if/else or switch case are pretty much no-go, at least hard-typed.
I read about bit search and other methods but I really don't understand them :O
C:
float array[10] = {};  //array to store values


void setup()
{
  array[0] = 100.0;  //first array value set for calculating
  for (int i = 1; i < 10; i++)
  {
  array[i] = array[i - 1] / 2; //fill array with roughly -3db/step values
  }
  Serial.begin(9600);
}

void loop()
{
  for (int i = 0; i < 10; i++)
  {
  Serial.println(array[i]);  //show contents of each array element
  delay(1000);
  }
}
 
No worries, got log-scaling slowly sorted, I'm now making also spectrogram for this: (still quite rough....)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top