Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TFT_eSPI
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
TFT_eSPI
Commits
046e48f8
Commit
046e48f8
authored
Nov 25, 2018
by
Bodmer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete legacy example
parent
0f630b37
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
917 deletions
+0
-917
examples/320 x 240/TFT_Screen_Capture/TFT_Screen_Capture.ino
examples/320 x 240/TFT_Screen_Capture/TFT_Screen_Capture.ino
+0
-188
examples/320 x 240/TFT_Screen_Capture/processing_sketch.ino
examples/320 x 240/TFT_Screen_Capture/processing_sketch.ino
+0
-535
examples/320 x 240/TFT_Screen_Capture/screenServer.ino
examples/320 x 240/TFT_Screen_Capture/screenServer.ino
+0
-194
No files found.
examples/320 x 240/TFT_Screen_Capture/TFT_Screen_Capture.ino
deleted
100644 → 0
View file @
0f630b37
/*
This sketch has been written to test the Processing screenshot client.
It has been created to work with the TFT_eSPI library here:
https://github.com/Bodmer/TFT_eSPI
It sends screenshots to a PC running a Processing client sketch.
The Processing IDE that will run the client sketch can be downloaded
here: https://processing.org/
The Processing sketch needed is contained within a tab attached to this
Arduino sketch. Cut and copy that tab into the Processing IDE and run.
This sketch uses the GLCD, 2, 4, 6 fonts only.
Make sure all the display driver and pin comnenctions are correct by
editting the User_Setup.h file in the TFT_eSPI library folder.
Maximum recommended SPI clock rate is 27MHz when reading pixels, 40MHz
seems to be OK with ILI9341 displays but this is above the manufacturers
specifed maximum clock rate.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
#########################################################################
*/
// Created by: Bodmer 5/3/17
// Updated by: Bodmer 10/3/17
// Version: 0.06
// MIT licence applies, all text above must be included in derivative works
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI
tft
=
TFT_eSPI
();
// Invoke custom library with default width and height
unsigned
long
targetTime
=
0
;
byte
red
=
31
;
byte
green
=
0
;
byte
blue
=
0
;
byte
state
=
0
;
unsigned
int
colour
=
red
<<
11
;
// Colour order is RGB 5+6+5 bits each
void
setup
(
void
)
{
Serial
.
begin
(
921600
);
tft
.
init
();
tft
.
setRotation
(
0
);
tft
.
fillScreen
(
TFT_BLACK
);
randomSeed
(
analogRead
(
A0
));
targetTime
=
millis
()
+
1000
;
}
void
loop
()
{
if
(
targetTime
<
millis
())
{
targetTime
=
millis
()
+
1500
;
// Wait a minimum of 1.5s
tft
.
setRotation
(
random
(
4
));
rainbow_fill
();
// Fill the screen with rainbow colours
tft
.
setTextColor
(
TFT_BLACK
);
// Text background is not defined so it is transparent
tft
.
setTextDatum
(
TC_DATUM
);
// Top Centre datum
int
xpos
=
tft
.
width
()
/
2
;
// Centre of screen
tft
.
setTextFont
(
0
);
// Select font 0 which is the Adafruit font
tft
.
drawString
(
"Original Adafruit font!"
,
xpos
,
5
);
// The new larger fonts do not need to use the .setCursor call, coords are embedded
tft
.
setTextColor
(
TFT_BLACK
);
// Do not plot the background colour
// Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
tft
.
drawString
(
"Font size 2"
,
xpos
,
14
,
2
);
// Draw text centre at position xpos, 14 using font 2
tft
.
drawString
(
"Font size 4"
,
xpos
,
30
,
4
);
// Draw text centre at position xpos, 30 using font 4
tft
.
drawString
(
"12.34"
,
xpos
,
54
,
6
);
// Draw text centre at position xpos, 54 using font 6
tft
.
drawString
(
"12.34 is in font size 6"
,
xpos
,
92
,
2
);
// Draw text centre at position xpos, 92 using font 2
// Note the x position is the top of the font!
// draw a floating point number
float
pi
=
3.1415926
;
// Value to print
int
precision
=
3
;
// Number of digits after decimal point
int
ypos
=
110
;
// y position
tft
.
setTextDatum
(
TR_DATUM
);
// Top Right datum so text butts neatly to xpos (right justified)
tft
.
drawFloat
(
pi
,
precision
,
xpos
,
ypos
,
2
);
// Draw rounded number and return new xpos delta for next print position
tft
.
setTextDatum
(
TL_DATUM
);
// Top Left datum so text butts neatly to xpos (left justified)
tft
.
drawString
(
" is pi"
,
xpos
,
ypos
,
2
);
tft
.
setTextSize
(
1
);
// We are using a font size multiplier of 1
tft
.
setTextDatum
(
TC_DATUM
);
// Top Centre datum
tft
.
setTextColor
(
TFT_BLACK
);
// Set text colour to black, no background (so transparent)
tft
.
drawString
(
"Transparent..."
,
xpos
,
125
,
4
);
// Font 4
tft
.
setTextColor
(
TFT_WHITE
,
TFT_BLACK
);
// Set text colour to white and background to black
tft
.
drawString
(
"White on black"
,
xpos
,
150
,
4
);
// Font 4
tft
.
setTextColor
(
TFT_GREEN
,
TFT_BLACK
);
// This time we will use green text on a black background
tft
.
setTextFont
(
2
);
// Select font 2, now we do not need to specify the font in drawString()
// An easier way to position text and blank old text is to set the datum and use width padding
tft
.
setTextDatum
(
BC_DATUM
);
// Bottom centre for text datum
tft
.
setTextPadding
(
tft
.
width
()
+
1
);
// Pad text to full screen width + 1 spare for +/-1 position rounding
tft
.
drawString
(
"Ode to a Small Lump of Green Putty"
,
xpos
,
230
-
32
);
tft
.
drawString
(
"I Found in My Armpit One Midsummer"
,
xpos
,
230
-
16
);
tft
.
drawString
(
"Morning"
,
xpos
,
230
);
tft
.
setTextDatum
(
TL_DATUM
);
// Reset to top left for text datum
tft
.
setTextPadding
(
0
);
// Reset text padding to 0 pixels
// Now call the screen server to send a copy of the TFT screen to the PC running the Processing client sketch
screenServer
();
}
}
// Fill screen with a rainbow pattern
void
rainbow_fill
()
{
// The colours and state are not initialised so the start colour changes each time the funtion is called
int
rotation
=
tft
.
getRotation
();
tft
.
setRotation
(
random
(
4
));
for
(
int
i
=
tft
.
height
()
-
1
;
i
>=
0
;
i
--
)
{
// This is a "state machine" that ramps up/down the colour brightnesses in sequence
switch
(
state
)
{
case
0
:
green
++
;
if
(
green
==
64
)
{
green
=
63
;
state
=
1
;
}
break
;
case
1
:
red
--
;
if
(
red
==
255
)
{
red
=
0
;
state
=
2
;
}
break
;
case
2
:
blue
++
;
if
(
blue
==
32
)
{
blue
=
31
;
state
=
3
;
}
break
;
case
3
:
green
--
;
if
(
green
==
255
)
{
green
=
0
;
state
=
4
;
}
break
;
case
4
:
red
++
;
if
(
red
==
32
)
{
red
=
31
;
state
=
5
;
}
break
;
case
5
:
blue
--
;
if
(
blue
==
255
)
{
blue
=
0
;
state
=
0
;
}
break
;
}
colour
=
red
<<
11
|
green
<<
5
|
blue
;
// Draw a line 1 pixel wide in the selected colour
tft
.
drawFastHLine
(
0
,
i
,
tft
.
width
(),
colour
);
// in this example tft.width() returns the pixel width of the display
}
tft
.
setRotation
(
rotation
);
}
examples/320 x 240/TFT_Screen_Capture/processing_sketch.ino
deleted
100644 → 0
View file @
0f630b37
This diff is collapsed.
Click to expand it.
examples/320 x 240/TFT_Screen_Capture/screenServer.ino
deleted
100644 → 0
View file @
0f630b37
// Reads a screen image off the TFT and send it to a processing client sketch
// over the serial port. Use a high baud rate, e.g. for an ESP8266:
// Serial.begin(921600);
// At 921600 baud a 320 x 240 image with 16 bit colour transfers can be sent to the
// PC client in ~1.67s and 24 bit colour in ~2.5s which is close to the theoretical
// minimum transfer time.
// This sketch has been created to work with the TFT_eSPI library here:
// https://github.com/Bodmer/TFT_eSPI
// Created by: Bodmer 27/1/17
// Updated by: Bodmer 10/3/17
// Version: 0.07
// MIT licence applies, all text above must be included in derivative works
//====================================================================================
// Definitions
//====================================================================================
#define BAUD_RATE 250000 // Maximum Serial Monitor rate for other messages
#define DUMP_BAUD_RATE 921600 // Rate used for screen dumps
#define PIXEL_TIMEOUT 100 // 100ms Time-out between pixel requests
#define START_TIMEOUT 10000 // 10s Maximum time to wait at start transfer
#define BITS_PER_PIXEL 16 // 24 for RGB colour format, 16 for 565 colour format
// File names must be alpha-numeric characters (0-9, a-z, A-Z) or "/" underscore "_"
// other ascii characters are stripped out by client, including / generates
// sub-directories
#define DEFAULT_FILENAME "tft_screenshots/screenshot" // In case none is specified
#define FILE_TYPE "png" // jpg, bmp, png, tif are valid
// Filename extension
// '#' = add 0-9, '@' = add timestamp, '%' add millis() timestamp, '*' = add nothing
// '@' and '%' will generate new unique filenames, so beware of cluttering up your
// hard drive with lots of images! The PC client sketch is set to limit the number of
// saved images to 1000 and will then prompt for a restart.
#define FILE_EXT '%'
// Number of pixels to send in a burst (minimum of 1), no benefit above 8
// NPIXELS values and render times: 1 = 5.0s, 2 = 1.75s, 4 = 1.68s, 8 = 1.67s
#define NPIXELS 8 // Must be integer division of both TFT width and TFT height
//====================================================================================
// Screen server call with no filename
//====================================================================================
// Start a screen dump server (serial or network) - no filename specified
boolean
screenServer
(
void
)
{
// With no filename the screenshot will be saved with a default name e.g. tft_screen_#.xxx
// where # is a number 0-9 and xxx is a file type specified below
return
screenServer
(
DEFAULT_FILENAME
);
}
//====================================================================================
// Screen server call with filename
//====================================================================================
// Start a screen dump server (serial or network) - filename specified
boolean
screenServer
(
String
filename
)
{
Serial
.
end
();
// Stop the serial port (clears buffers too)
Serial
.
begin
(
DUMP_BAUD_RATE
);
// Force baud rate to be high
delay
(
0
);
// Equivalent to yield() for ESP8266;
boolean
result
=
serialScreenServer
(
filename
);
// Screenshot serial port server
//boolean result = wifiScreenServer(filename); // Screenshot WiFi UDP port server (WIP)
Serial
.
end
();
// Stop the serial port (clears buffers too)
Serial
.
begin
(
BAUD_RATE
);
// Return baud rate to normal
delay
(
0
);
// Equivalent to yield() for ESP8266;
//Serial.println();
//if (result) Serial.println(F("Screen dump passed :-)"));
//else Serial.println(F("Screen dump failed :-("));
return
result
;
}
//====================================================================================
// Serial server function that sends the data to the client
//====================================================================================
boolean
serialScreenServer
(
String
filename
)
{
// Precautionary receive buffer garbage flush for 50ms
uint32_t
clearTime
=
millis
()
+
50
;
while
(
millis
()
<
clearTime
&&
Serial
.
read
()
>=
0
)
delay
(
0
);
// Equivalent to yield() for ESP8266;
boolean
wait
=
true
;
uint32_t
lastCmdTime
=
millis
();
// Initialise start of command time-out
// Wait for the starting flag with a start time-out
while
(
wait
)
{
delay
(
0
);
// Equivalent to yield() for ESP8266;
// Check serial buffer
if
(
Serial
.
available
()
>
0
)
{
// Read the command byte
uint8_t
cmd
=
Serial
.
read
();
// If it is 'S' (start command) then clear the serial buffer for 100ms and stop waiting
if
(
cmd
==
'S'
)
{
// Precautionary receive buffer garbage flush for 50ms
clearTime
=
millis
()
+
50
;
while
(
millis
()
<
clearTime
&&
Serial
.
read
()
>=
0
)
delay
(
0
);
// Equivalent to yield() for ESP8266;
wait
=
false
;
// No need to wait anymore
lastCmdTime
=
millis
();
// Set last received command time
// Send screen size etc using a simple header with delimiters for client checks
sendParameters
(
filename
);
}
}
else
{
// Check for time-out
if
(
millis
()
>
lastCmdTime
+
START_TIMEOUT
)
return
false
;
}
}
uint8_t
color
[
3
*
NPIXELS
];
// RGB and 565 format color buffer for N pixels
// Send all the pixels on the whole screen
for
(
uint32_t
y
=
0
;
y
<
tft
.
height
();
y
++
)
{
// Increment x by NPIXELS as we send NPIXELS for every byte received
for
(
uint32_t
x
=
0
;
x
<
tft
.
width
();
x
+=
NPIXELS
)
{
delay
(
0
);
// Equivalent to yield() for ESP8266;
// Wait here for serial data to arrive or a time-out elapses
while
(
Serial
.
available
()
==
0
)
{
if
(
millis
()
>
lastCmdTime
+
PIXEL_TIMEOUT
)
return
false
;
delay
(
0
);
// Equivalent to yield() for ESP8266;
}
// Serial data must be available to get here, read 1 byte and
// respond with N pixels, i.e. N x 3 RGB bytes or N x 2 565 format bytes
if
(
Serial
.
read
()
==
'X'
)
{
// X command byte means abort, so clear the buffer and return
clearTime
=
millis
()
+
50
;
while
(
millis
()
<
clearTime
&&
Serial
.
read
()
>=
0
)
delay
(
0
);
// Equivalent to yield() for ESP8266;
return
false
;
}
// Save arrival time of the read command (for later time-out check)
lastCmdTime
=
millis
();
#if defined BITS_PER_PIXEL && BITS_PER_PIXEL >= 24
// Fetch N RGB pixels from x,y and put in buffer
tft
.
readRectRGB
(
x
,
y
,
NPIXELS
,
1
,
color
);
// Send buffer to client
Serial
.
write
(
color
,
3
*
NPIXELS
);
// Write all pixels in the buffer
#else
// Fetch N 565 format pixels from x,y and put in buffer
tft
.
readRect
(
x
,
y
,
NPIXELS
,
1
,
(
uint16_t
*
)
color
);
// Send buffer to client
Serial
.
write
(
color
,
2
*
NPIXELS
);
// Write all pixels in the buffer
#endif
}
}
Serial
.
flush
();
// Make sure all pixel bytes have been despatched
return
true
;
}
//====================================================================================
// Send screen size etc using a simple header with delimiters for client checks
//====================================================================================
void
sendParameters
(
String
filename
)
{
Serial
.
write
(
'W'
);
// Width
Serial
.
write
(
tft
.
width
()
>>
8
);
Serial
.
write
(
tft
.
width
()
&
0xFF
);
Serial
.
write
(
'H'
);
// Height
Serial
.
write
(
tft
.
height
()
>>
8
);
Serial
.
write
(
tft
.
height
()
&
0xFF
);
Serial
.
write
(
'Y'
);
// Bits per pixel (16 or 24)
Serial
.
write
(
BITS_PER_PIXEL
);
Serial
.
write
(
'?'
);
// Filename next
Serial
.
print
(
filename
);
Serial
.
write
(
'.'
);
// End of filename marker
Serial
.
write
(
FILE_EXT
);
// Filename extension identifier
Serial
.
write
(
*
FILE_TYPE
);
// First character defines file type j,b,p,t
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment