Skip to content

ArminPP/ytGraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project logo

ytGraph

A scrollig and non flickering y/t-graph function set for Arduino/ESP µC





Table of Contents



About

This is a set of functions used to visualize 1 to 16 different time series data on one chart.
The diagram is fully scalable and can be freely positioned on the tft screen.

Project logo

Features

  • supports M5Stack and TFT_eSPI() (switch is #useM5STACK)
  • compiles under Arduino IDE and PlatformIO
  • fully scalable (at runtime you have to change #defines to variables)
  • flicker-free scrolling due to the use of sprites (but took up a little more memory)
  • the y-axis (time) updates the values ​​automatically (depending on the time format S | M | H | D)
  • up to 16 independent channels
  • for time series data (only)
  • contains a history view (of the size of one graph screen)
  • the x-axis is based on interger, only positive values are allowed
  • the y-axis is based on float and can be positive and negative


Getting started

Installing

PlatformIO:
Compile & upload the code into the controller. Watch the tft-screen.

Arduino IDE:
Copy the two files ytGraph.cpp/h into a project folder and the main.cpp.
Also copy version.h and ytG_logo.h into the project folder.
With Arduino IDE you have to rename the 'main.cpp' into 'main.ino'.
The folder name must be identical to the *.ino file, eg. "main".

Compile the demo and load it into the µC. Watch the tft-screen.

Functions in detail

There are separate functions for different tasks:

  • Draw the y-axis and the frame only once, using standard graphic functions
      void ytGraphDrawYaxisFrame(M5Display &d);
  • Draw the grid and x-axis only once, using two sprites to make it dynamic
      void ytGraphDrawGridXaxis(TFT_eSprite &Graph, TFT_eSprite &xAxis, int16_t &LastXGridLinePos);
  • Draw the dynamic grid seamless to the static one and animate the x-axis
      void ytGraphDrawDynamicGrid(TFT_eSprite &Graph, TFT_eSprite &xAxis, int16_t oox, int16_t &LastXGridLinePos);
  • Draw the values dynamically according to the sample count and sample rate
      void ytGraph(TFT_eSprite &Graph, uint16_t x, int16_t y, uint16_t LineColor, int16_t &ox, int16_t &oy);


Usage

All settings are done with #defines in the ytGraph.h file

The number of values ​​displayed in the graphic only depends on the number of SAMPLE_COUNT.
E.g. if there are 60 samples, they will be scaled along the x-axis. If there are only 3 samples, these will also be scaled this way.

To get a flicker-free scrolling, 2 independent sprites are used.

Settings

The settings are in ytGraph.h

Project logo

#define GRAPH_X_LEFT_POS 40                                   // (1)	
#define GRAPH_Y_BOTTOM_POS 150                                // (2)
#define GRAPH_WIDTH 240                                       // (3)
#define GRAPH_HEIGHT 120                                      // (4)

#define SPRITE_LEFT_X GRAPH_X_LEFT_POS                        // (1)
#define SPRITE_UPPER_Y (GRAPH_Y_BOTTOM_POS - GRAPH_HEIGHT)    // (7)
#define SPRITE_WIDTH GRAPH_WIDTH + 1                          // (3)
#define SPRITE_HEIGTH GRAPH_HEIGHT + 2                        // (4)

#define X_AXIS_WIDTH SPRITE_WIDTH + 50                        // (5)
#define X_AXIS_HEIGTH 15                                      // (6)
#define X_AXIS_LEFT_X GRAPH_X_LEFT_POS - 10                   // (8)
#define X_AXIS_UPPER_Y GRAPH_Y_BOTTOM_POS + 4                 // (2)

#define GRAPH_Y_AXIS_MIN 0.0                                 // (11)
#define GRAPH_Y_AXIS_MAX 60.0                                // (10)
#define GRAPH_Y_DIV 10                                       // (9)

//(same procedure at x-axis:)
#define GRAPH_X_AXIS_MIN 0
#define GRAPH_X_AXIS_MAX (SAMPLE_COUNT * SAMPLE_RATE) // (*)
#define GRAPH_X_DIV 5
// *) The last value of the x-axis is calculated with:   samples * rate   (e.g. 60 samples * 5 sec = 300 sec)


Acknowledgements

About

A set of ytGraph drawing functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published