1.8" TFT shield with joystick and SD card on chipKIT

Post Reply
User avatar
unexpectedly
Posts: 105
Joined: Fri Aug 23, 2013 2:31 am
Location: San Diego
Contact:

1.8" TFT shield with joystick and SD card on chipKIT

Post by unexpectedly » Mon Sep 02, 2013 6:49 am

I added it to the shields compatibility list, but thought I'd start a thread to talk about it, too, because I absolutely love this shield!

I made the Adafruit 1.8" TFT with the ST7735 using SPI work on my uC32. While I wasn't able to make it work on my own Uno32, it works out-of-box on majenko's Uno32. Much credit to majenko for picking up the pace on chipKIT-specific improvements as well as amazing advances in graphics performance on this TFT. He's done more for it than I think anyone thought to reach for!

I will maintain major changes to ada_dspi_tft_chipKIT_v1xx.zip attached to this first post. The best way to keep current is follow the Github repository for this project. (direct link to zip) I will be adding small UI improvements to TFTDemo.ino in ST7735/examples; small tricks I learn and develop for display of info, etc.
ada_tft_dspi_v104.jpg
ada_tft_dspi_v104.jpg (92.25 KiB) Viewed 4001 times
This shield is screwed to the face of my TPS test bench. Plastic was 3D printed from Airwolf 3D XL printer. CAD files of it are on GrabCAD.

With the chipKIT, I was able to convert the "PORT" commands from AVR-land into simple digitalWrite()s! On the AVR, the ST7735 library won't even run with all digitalWrite()s! This TFT shield uses the standard SPI pins ( 10, 12, 13 ) and additionally 8 as a DC / RS selector. The shield draws power from the +5V pin, but you can bypass its onboard logic shifter and go all 3.3V. People programming Netduinos for these shields figured this out and were able to get faster performance. Note: soldering and more work required if you're wanting to ditch the 5V altogether.

Analog 3 has a resistor network for the joystick, tested and working in the sample code as of 1.02 or 1.03.

Digital 4 is the chip select for the SD Card (which shares the SPI pins 11,12,13). SD Card functionality not yet implemented in the Hello World code. If I get a spare moment, I'll add the de rigueur put bitmap from SD Card onto screen. (note to self, I also need to add majenko's png-to-bmp php script to the project)

Anecdotal observations coming from AVR-land:
1) The AVR has delays added in the code and also had to use direct PORT accesses to twiddle pins 8 and 10 (DC and SS/CS) quickly enough to perform operations.
2) The first port converting everything to just using digitalWrite() in chipKIT resulted in performance slightly slower than using hardware SPI in Arduino. Once the delays were removed, WOW! Much faster than Arduino + HW SPI.
3) While I didn't bother with the software SPI implementation of the Adafruit class, majenko worked that into the code with version 1.05 via shiftOut(). On AVR, software SPI was slow enough, you could watch the pixels draw one by one.
4) chipKIT hardware SPI is so fast, the screen almost "blinks"!! At least 3x faster than AVR hardware SPI this class came from.
5) When using tft.print(), it actually erases the previous pixels where characters were. In the codebase we drew from, the background pixels of each character wouldn't clear, so overwriting the same place would ultimately result in solid blob. Now, new text overwrites old with the background.

Product link:
adafruit.com/products/802
Attachments
chipKIT_ST7735-master.zip
(96.16 KiB) Downloaded 170 times
Last edited by unexpectedly on Sat Sep 07, 2013 9:03 pm, edited 8 times in total.

User avatar
unexpectedly
Posts: 105
Joined: Fri Aug 23, 2013 2:31 am
Location: San Diego
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by unexpectedly » Wed Sep 04, 2013 7:33 am

Updated tft.ino to make the joystick work via a trivial menu handler. This should run and display the program name and version number in the "footer".

Lots of comments added in tft.ino.

Libraries: _GFX and _ST7735 removed. No changes to Libraries.
Attachments
ada_spi_tft_chipKIT_v101.zip
Added here for completeness.
(29.23 KiB) Downloaded 126 times
menus.zip
Sort-of the pre-v101 code (early days)
(28.25 KiB) Downloaded 142 times
ada_spi_tft_chipKIT_v102.zip
(16.36 KiB) Downloaded 151 times
Last edited by unexpectedly on Thu Sep 05, 2013 8:46 pm, edited 2 times in total.

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by majenko » Wed Sep 04, 2013 11:58 am

Well, I don't know about your Uno32 problems - I just plugged my TFT into my Uno32, installed the libs, and tft.ino, and it worked straight away.

Maybe your Uno32 is faulty?
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by majenko » Wed Sep 04, 2013 1:31 pm

Here is a tweaked version of the main control library which has been ported to DSPI and optimised for more efficient SPI usage.

It's set to 20Mbps SPI, and colour data is transferred as single 16-bit word transactions instead of 2 8-bit transactions.
Attachments
ST7735.zip
(6.16 KiB) Downloaded 133 times
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by majenko » Wed Sep 04, 2013 1:44 pm

And here's a tweaked GFX library which has support for displaying 16-bit bitmaps, with or without crude transparency.

Code: Select all

// 8x8 image
const uint16_t pic[8*8] = {
	0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
	0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF,
	0xFFFF, 0x0000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0xFFFF,
	0xFFFF, 0x0000, 0x8000, 0xF000, 0xF000, 0x8000, 0x0000, 0xFFFF,
	0xFFFF, 0x0000, 0x8000, 0xF000, 0xF000, 0x8000, 0x0000, 0xFFFF,
	0xFFFF, 0x0000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0xFFFF,
	0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF,
	0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,	
};

tft.drawRGB(10, 10, pic, 8, 8); // Drawn at 10,10 as is
tft.drawRGBA(10, 10, pic, 8, 8, 0x0000); // Drawn at 10,10 with colour 0x0000 transparent
Now to write a graphical menu system with icons ;)
Attachments
GFX.zip
(7.83 KiB) Downloaded 121 times
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by majenko » Wed Sep 04, 2013 2:52 pm

And here's a little PHP script for converting PNGs to raw data:

Code: Select all

#!/usr/bin/php
<?php

$file = $argv[1];

$img = ImageCreateFromPNG($file);

$width = ImageSX($img);
$height = ImageSY($img);

print "// Image width: $width pixels\n";
print "// Image height: $height pixels\n";

print "const uint16_t image[$width*$height] = {\n";

$count = 0;
for ($y = 0; $y < $height; $y++) {
    for ($x = 0; $x < $width; $x++) {
        $color = ImageColorAt($img, $x, $y);
        $a = 127 - (($color >> 24) & 0x7F);
        $r = (($color >> 16) & 0xFF) * $a / 127;
        $g = (($color >> 8) & 0xFF) * $a / 127;
        $b = ($color & 0xFF) * $a / 127;
        $r = $r >> 3;
        $g = $g >> 2;
        $b = $b >> 3;
        $newcol = $r << 11 | $g << 5 | $b;
        printf("0x%04X, ", $newcol);
        $count++;
        if ($count == 8) {
            print "\n";
            $count = 0;
        }
    }
}

print "};\n";
And what you can do with it:
IMG_20130904_144757.jpg
IMG_20130904_144757.jpg (146.28 KiB) Viewed 4035 times
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by majenko » Wed Sep 04, 2013 9:09 pm

Damn, I have been trying to make a buffered version of the library, but my Uno32 just can't cut it. I don't want to limit it to the bigger boards really.

I was looking at a 7-bit framebuffer (with 128 entry palette) limiting you to 128 colours on screen at once, but with a much more efficient display routine. Bit 7 of the buffer (making it an 8-bit buffer) was to be a "modified" flag, and when a pixel was drawn on the screen, if it differed to what was there already, it was changed and the "modified" flag was updated. Then an update function would scan through the whole framebuffer finding pixels that had changed and just update the display with those pixels (looking up the colour in the palette), resetting the modified flags as it went.

It would have been fast, and made it look even more flash :)

But... 160x128 at 8 bits is 20480 bytes, and the Uno32 only has 16K :(

So bang goes that idea, unless I limit it to the bigger boards. I think a uC32 would do it though...
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
unexpectedly
Posts: 105
Joined: Fri Aug 23, 2013 2:31 am
Location: San Diego
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by unexpectedly » Wed Sep 04, 2013 9:49 pm

Wow! So the tweaked LIBs might take up lots of SRAM? Part of what I'm doing is so I can build a bitmap to output to the thermal printer (using 19k of RAM), so I might need to pass on the uber-nifty display for this...

DANGIT

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by majenko » Wed Sep 04, 2013 9:56 pm

Only the tweaked tweaked lib. The one up there with the bitmap support uses no more (maybe slightly less) than your version.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
unexpectedly
Posts: 105
Joined: Fri Aug 23, 2013 2:31 am
Location: San Diego
Contact:

Re: 1.8" TFT shield with joystick and SD card on chipKIT

Post by unexpectedly » Thu Sep 05, 2013 1:02 am

Hmmmm, I ran the DSPI code in my test bench and it worked... so I took apart the "doghouse" that holds the TFT, Proto shield, and uC32 and tried the Uno32. Didn't work.

Double checked I had the Uno32 board selected and chose the other COM port, too. :?

So then while I had it apart, I moved the power input connector for the uC32 from +12V to +9V. For this, I just moved the wire on the proto shield that feeds the power plug from the 12V for the easy driver stepper board to the printer's 9V. Put it all together, doesn't work. :oops: Tried SPI. Nope. Grrrr... The only thing I can imagine is that my front panel piece bends the TFT shield if over tightened. I removed the shield from the faceplate and it's now ok. :roll:

... redesigning the face plate so it can be printing tonight...

Picture is of my uC32 (rev A) and Uno32 (rev C):
uC32revA_Uno32revC.jpg
uC32revA_Uno32revC.jpg (165.36 KiB) Viewed 4018 times

Post Reply