It will take around 1 minute 20 seconds to draw an image to the display at a resolution of 320x240 because of SPI Data Rate
I've implimented some basic encoding Int to Hex and back again via the microcontroller which will speed things up a very tiny bit but it helps :)
I doubt i can get it any faster due to the limits of the SPI transfer speed or it might be the library which is slowing down the transfer, it's unknown to me however it's pretty fast and 1 minute aint that long unless you need real time video LOL
What we're doing is capturing the desktop and converting each pixel to 16bit RGB and sending them over the serial to the display.
Arduino code:
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#define _sclk
#define _miso
#define _mosi
#define _cs 10
#define _dc 9
#define _rst 8
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
String inputString = "";
boolean stringComplete = false;
void setup()
{
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.fillRect(0,0,320,240,0xF000);
}
int x = 0;
int y = 0;
void loop()
{
if (stringComplete)
{
if(x > 320)
{
x = 0;
y++;
}
if(y > 240)
{
y = 0;
x = 0;
}
tft.drawPixel(x,y,(int)strtol(&(inputString[0]), NULL, 16));
x++;
Serial.flush();
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
Vb.NET Code: (REQUIRES - 1 Button)
Imports System.Drawing.Imaging
Public Class Form1
Dim hval = 0
Dim wval = 0
Dim done As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Thread this sub so that it does not lock up the UI
Dim x As Threading.Thread
x = New Threading.Thread(AddressOf TakeImage)
x.SetApartmentState(Threading.ApartmentState.MTA)
x.Start()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
SerialPort1.BaudRate = 115200
SerialPort1.Open()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
SerialPort1.Close()
Catch
End Try
End
End Sub
Public Sub TakeImage()
'Take a screenshot and resize the image to 320 by 240 pixels
Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
g.ScaleTransform(321, 241)
End Using
Dim Img = New Bitmap(screenGrab, 321, 241)
Dim microSeconds As Integer = 0
Dim sw As Stopwatch = New Stopwatch
For h = 0 To 240
For w = 0 To 320
done = False
Do Until done = True
Try
SerialPort1.WriteLine(Hex(Convert.ToInt32(((Convert.ToByte(Img.GetPixel(w, h).R) \ 8) << 11) Or (Convert.ToByte(Img.GetPixel(w, h).G) \ 8)) Or ((Convert.ToByte(Img.GetPixel(w, h).B) \ 4) << 5).ToString().PadLeft(4, "0"c)))
done = True
Catch : End Try
Loop
Next
Next
End Sub
Private Sub SerialPort1_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ListBox1.Items.Add(SerialPort1.ReadLine)
End Sub
End Class
FEEL FREE TO UPLOAD IF YOU CAN MAKE IMPROVEMENTS.