Arduino - TFT Display of Bitmap Images From An SD Card - All
Arduino - TFT Display of Bitmap Images From An SD Card - All
Explore(/tag/typeid/)
Login(/account/login)
Publish(/about/create.jsp)
| SignUp(/account/gopro?sourcea=header)
AboutThisInstructable
License:
8 17,035views
20favorites
(/file/F2WWWQFI7SVVUWH/)
Bodmer
(/member/Bodmer/)
FollowingonfrommyotherInstructablesontheArduinoandTFTdisplayhereis
anupdatedlibraryandSketchtodrawbitmaps(BMPorRaw)storedonanSD
CardontotheTFTdisplay.
Follow
(/member/Bodmer/)
MorebyBodmer:
MostoftheavailableTFTdisplayshaveaSDCardslotontheback,the
connectionstothisareusuallyseparatetothedisplayinterfacesomustbe
wiredup.
ThisinstructablewilltellyouhowtowireanArduinoUNOtoa2.2"TFT320x240
displaythatincorporatestheILI9341driverchip.Thesedisplaysareavailableat
lowcostoneBay.
ThelibraryandfunctionshouldworkOKwithotherdisplaysthatusethatdriver
chip.
ByusinganoptimizedversionoftheAdafruit_GFXlibraryandanefficient
functionaraw320x240fullcolourbitmapcanbeplottedtothescreenin660ms,
notbadforahumbleUNO.
44
(/id/ArduinoTFT
displayoficonsandimagesfrom
FLASH/)
(/id/Arduino
TFTdisplayofbitmapimagesfroman
Step1:Connectingitup
SDCa/)
(/id/Arduino
analogueringmeteroncolourTFT
display/)
Tags:
TFT(/tag/typeid/keywordTFT/)
graphicslibrary(/tag/typeid/keywordgraphics%20library/)
fonts(/tag/typeid/keywordfonts/)
fonts(/tag/typeid/keywordfonts/)
SDcard(/tag/typeid/keywordSD%20card/)
SDcard(/tag/typeid/keywordSDcard/)
Bitmap(/tag/typeid/keywordBitmap/)
Arduino(/tag/typeid/keywordArduino/)
ILI9341(/tag/typeid/keywordILI9341/)
(/file/F84SB62I7SVVW60/)
Related
ArduinoTFTdisplayandfont
library(/id/ArduinoTFT
displayandfontlibrary/)
byBodmer(/member/Bodmer/)
(/id/Arduino
(/id/Arduino
(/id/Arduino
(/file/FB18ASGI7SVVW8E/)
ConnectionsaredifferenttothoseinmyotherInstructables(thisisformy
convenience!)youcanchangethepinallocations,butdousethehardwareSPI
pins:
UNO+5Vtodisplaypin1(VCC)
UNO+5Vthrougha56Ohmresistortodisplaypin8(LED)
UNO0V(GND)todisplaypin2(GND)
UNOdigitalpin7througha1K2resistortodisplaypin4(RESET),adda1K8
resistorfromdisplaypin4toGND
UNOdigitalpin8througha1K2resistortoSDcardSD_CS,adda1K8
resistorfromSD_CStoGND
UNOdigitalpin9througha1K2resistortodisplaypin5(DC/RS),adda1K8
resistorfromdisplaypin5toGND
UNOdigitalpin10througha1K2resistortodisplaypin3(CS),adda1K8
resistorfromdisplaypin3toGND
UNOdigitalpin11througha1K2resistortobothdisplaypin6(MOSI)and
SDcardpinSD_MOSI,adda1K8resistorfromdisplaypin6toGND
UNOdigitalpin12directtoSDcardSD_MISO(orvia1K2,seebelow)
UNOdigitalpin13througha1K2resistortobothdisplaypin7andSDcard
pinSD_SCK,adda1K8resistorfromdisplaypin7toGND
OtherpinoutsattheArduinocanbeusedbyadaptingthesketchshouldyou
haveadisplayfromanothersupplierorwishtouseanexistingsetup.
Youmaywishtoputaninline1K2(orthereabout)resistorinserieswiththe
MISOsignalline(betweenUNOpin12andSD_MISO)thiswillhelpprotectthe
SDCardincaseyouaccidentallyswitchtheUNOpin12tooutputa+5Vlogic
1...TheSDcardmightsurvivesuchabusebutyoumaynotbelucky...andthe
resistorwilllimitthecurrentintothedevicetoacoupleofmA.
BearinmindthedisplayIhaveincorporates10Kpullupstothe+3.3Vsupplyon
theSDCardSPIlines,thismeansthatusinghighervalueresistorsinthe
voltagedivider(thesedroptheUNO5Vlevelstoaround3Vlogic)willnot
achieveareliablelogiczeroanditwon'twork!Ideallywewouldusealogiclevel
converterbutresistorsaresocheapandtheyworkfineatthesefrequencies
becausethestraycapacitanceofthelineswearedrivingisnotthatsignificant.
Thedisplayisquitegreedyonpowersothedissipationintheresistorsisnot
thatsignificantincomparison.
DonotinsertandremovetheSDcardwhentheArduinoispowered,thiscan
(does!)corruptthecardanditwillneedreformatting!
(/id/head
(/id/Arduino
ArduinoTFTdisplayof
iconsandimagesfrom
FLASHmemory(/id/Arduino
TFTdisplayoficonsand
imagesfromFLASH/)
ArduinoserialUART
scrollingdisplayterminal
usinga2.2"TFT
(/id/ArduinoserialUART
scrollingdisplayterminal
headgear(/id/headgear/)
byhydronics
(/member/hydronics/)
Arduinoanalogue'ring'
meteroncolourTFTdisplay
(/id/Arduinoanaloguering
meteroncolourTFT
display/)
Step2:Librariesandexamplesketches(updated2/4/15)
YouwillneedthelibrariesintheattachedzipfileandtheSdFatlibrary(included
forconvenience).ThestandardSDlibrarycanbeusedbutthisrequiresminor
changestothesketchandwillrunslower.
ThemainchangestotheILI9341libraryaretoenhancespeedandtoaddthe
pushColors()function,onetohandleintegerarrays(forBMPdrawing)andone
forbytearrays(rawimages).
Inthezipfileyouwillfindafoldercontainingimages,puttheseonaFAT
formattedSDcardfortheArduinotoread(notinadirectory!).Youcanmodify
theSDlibraryexamplestousetheabovepinstocheckasketchcanaccessthe
filesandthewiringisgood.Ifintroublepostapleaforhelp...Imayhavemade
amistakeormaybeabletohelpyougetyoursetupgoing,bearinmindthatitis
difficulttodebugmajorproblemsbyexchangingafewmessages...
MostoftheimagefilesareinBMPformat,soitisleftasanexercisetoconvert
themtorawformat,amendthesketchandseetheimproveddrawingspeed.
Theexample"ILI9341_draw_bitmap"(intheAdafruit_ILI9341_ASfolder)
sketchuses90%ofUNOFLASHand54%ofRAMfordynamicstoragewhen
compiledunderIDE1.6.1.
OnlyenableFont2(orothersmallfontfile)ortheUNOwillrunoutof
FLASHmemory!
IusethecompilerO2optionasinmyInstructablehere
(http://www.instructables.com/id/ArduinoIDE16xcompileroptimisationsfaster
code/).ThestandardOsoptionwillmakesmallercodeimagesbutitruns
slower(whenIDE1.6.1used).IDE1.0.6compiledsketchesmaynotfitinan
UNOastheoldversionoftheGCCcompilerproducesfastbutquitelarge
executables.
InthecopiesofthelibrariesinthezipfilesF_AS_Tisdisabledandonly
Font2isenabled,beawareofthisifyoutryothersketchexamples!
Theimagedrawingfunctionispartofthesketchnotthelibrary,thisisdeliberate
asitisalltooeasytocreateaheavyweightmemoryhungryfeaturerichlibrary
thatputsastrainontheAVRbasedArduino'scapability!Wellthat'smyexcuse
)Somefolksolvethisbymakingasimplewrapperlibrarythatcontainsthese
functionsandcallslowerlevellibraries,sothisisanoptionforthefuture.You
cancutthedrawBMP()functionoutandjustusedrawRAW()tosavesome
space.
Themaindrawfunctionprototypesare:
voiddrawBMP(char*filename,int16_tx,int16_ty,booleanflip)
Thefilenamemustbeinthe8.3format,seetheSDlibrarydocumentation.x
andyarethecoordswherethetopleftpixeloftheimagewillbedrawn.Seethe
lastStepofthisInstructableforthefunctionoftheflipflag.Thewidthandheight
oftheimageareextractedfromtheBMPfile.
Theequivalentoneforrawbitmapsis:
voiddrawRAW(char*filename,int16_tx,int16_ty,int16_trawWidth,
int16_trawHeight)
Asthereisjustpixeldatainthisfilethewidthandheightoftheimagemustbe
providedtothefunction.
ThelibraryandsketchistargettedatAVRprocessors(UNO,Megaetc).Idonot
haveaDUE,sodonotplanatthemomenttomakeitcompatiblewithARM
processors.IfsomeonedoesgetthesketchrunningonaDUEIwouldbe
interestedtoherehowitperforms,iftheSPIcanberunat48MHzthenanentire
screenupdatecouldprobablybeperformedinlessthan100ms...ToruntheSPI
atthisfrequencyyouwouldprobablyneedadigitallogiclevelconverters.
Note:On2/4/15thelibrarysketchhasbeenupdatedtofurtherimprove
performance.
3/4/15:Minorbugfix
TFTSDbitmapv6.zip(/files/orig/FAU/RCDS/I800ZREN/FAURCDSI800ZREN.zip)
Step3:Addingimages
(/file/F831GDJI7SVVUXK/)
(/file/FZW0MQOI7SVVWAH/)
(/file/F87XGK8I7SVW53I/)
Ifyouaddyourownimagesmakesuretheyare24bitcolorBMPfilesandthey
haveawidthandheightcompatiblewiththedisplay.InWindowsthefreePaint
softwarecanbeusedtocrop,resize,flipandsaveimagesin24bitBMPformat.
Thereislittleerrorcheckinginthecode,soimagescanbecorruptedbydrawing
offthescreenedgeandmaynotgetdrawnatallifthefilecannotbefoundor
formatiswrongetc,buttheArduinoshouldkeepgoingandIhavenothada
crashyet.Ihaveremovedalldebuggingprintstatementstoreducethecode
size,butSerialiscalledupinsetup().
Paintcanalsobeusedtopickcoloursoffimagestoseethe24bitRGBvalue,
thesecanbeconvertedusingacalculatororalibraryfunctiontothe16bit565
formatusedforthedisplay.
RawimagefilesarequickertodrawandcanbecreatedstraightfromtheBMP
fileusingautilitycalled"ImageConverter565.exe",thiscomeswiththeUTFT
fileusingautilitycalled"ImageConverter565.exe",thiscomeswiththeUTFT
library(http://www.rinkydinkelectronics.com/library.php?id=51)andisinthetools
folderofthelibrary.Usethe".raw"option,loadafileandsaveit.Thefilewillbe
~2/3thesize.Thepixelorderingmeanstheydrawtopdowntoo,thisimage
converterisagreatlittleutilitythatsavesmewritingasketchfortheUNOto
seekBMPfilesandconvertthem(Imightdothatanyway!).
Yes,Ihadtoincludeapictureofacat,atleastit'sa"proper"one)anda
mouse.
Step4:BMPfileformatandgraphicsoverlay
(/file/F7CMLPLI7SVVW2I/)
ThecommonBMPformatistostoretheimageinrasterfashionfromthebottom
upwardsbutthegraphicsandplotwindowingexpectsanimagetobedrawntop
down.Manipulatingfilepointerstodrawtoptobottomslowsdownimage
renderingsignificantly,sothedrawingroutineandlibraryusesthehardwareTFT
SGRAMrotationfeature,thismeanswecanquicklydrawfrombottomtotop.
Afterplottingtheimagethedisplayisreturnedtothenormaltopleftis0,0
orientation.
Ifyouvisuallyprefertodrawtopdownthenfliptheimagetoptobottombefore
puttingitontheSDcardandusethe"TopDown"TD_BMPflaginthefunction
insteadoftheBottomUpBU_BMPflag.Thishasbeendoneinsympathywith
thecapabilitiesoftheUNObysacrificinganeater(butbiggerandslower)
softwareimplementationandstyleforasignificantperformanceadvantage!The
pricetopayisacoupleofmouseclickswhenpreparingtheimage(justflip
verticallybeforesavinginPaint).
Thedisplayedimagesareniceandcrispwithvibrantcolours,sothescreen
shotsmadewithmywebcamdon'tdoitfulljustice.Therawbitmapimagesare
morerepresentativeofwhatyouwillseeonthedisplay.
StandardGFXfunctions(linedrawing,text,etc.)canbeusedandoverlaidon
thedrawnimages.AsatrivialexampletheTerminatoreyesaremadetoglow
morebrightlyredintheILI9341_tftbmpdemosketchbyplottingbrightredcircles
intheappropriateplace.AgainPaintcanbeusedtohelpworkoutthe
coordinateswhenplottingoverimages.
Step5:Rawbitmapdrawing
(/file/FD1CXHOI7SVW5CG/)
(/file/F0ZJA3AI7SVW4RB/)
ItissurprisinghowquicklythehumbleUNOcanplotSDCardimagestothe
screenwhenthecodeloopsarekeptshortandsweet.Thespeedisquitegood
whenusing16bitrawimagesinaTFTfriendlyformatbecausethisavoidsthe
tediousconversionof24bitsinto16bitwordsandonly2/3rdsofthenumberof
bytesneedstoberead.Infactthislibraryandsketchcanfetchanimagefrom
theSDCardanddrawitonscreeninlesstimethansomegraphicslibrariestake
tojustclearthescreen...
Thelibraryandsketchhasbeentestonthenew1.6.2IDE
(http://arduino.cc/en/main/software).(whichIhaveonlyjustnoticedhasbeen
released!)
OnFLASHsizewearepushingtheboundariesforanUNOandonlyIDE1.6.x
willcreateasmallenoughfilewithasingleFont2(orsmaller)loaded.Iuse
optimisationlevel02asinmyInstructablehere
(http://www.instructables.com/id/ArduinoIDE16xcompileroptimisationsfaster
code/).forspeedbutthestandardOshelpsatadwithsmallersizeatthe
expenseofa35%speedreduction.
Theselibrariesarehighlyoptimisedversionoflibrariescreatedbyothershence
theAdafruitlabel.Allgraphicsdrawingfunctionsarestilltheirunderthebonnet
("hood"forreadersintheUSA).Thelinedrawingalgorithmhasbeenoptimised
andrunsmuchfasterthanthebasicBressenhammethodbecauseitusesthe
factthatshortmultipixelhorizontalandverticallinesegmentscanbedrawn
muchmorequicklythatindividualpixels.Thefurthertheangleawayfrom45
degrees(nomultipixellinesegments)thefasteralinewilldraw.Anexample
modifiedUTFTgraphicstestsketchisincludedtoshowtheimpressivespeed
improvement:)
ThankyouforreadingmyInstructables,ithasbeengratifyingtogetsuch
positivefeedback.ThemessagereportingserviceonInstructablesseemstobe
alittleunreliableforsomereason,sosometimesIdonotseenewposts,bear
thisinmind!
TTFN
Step6:Libraryevolutionsandspeedenhancements
ArduinoTFTdisplayofbitmapimagesfromanSDCard by
Bodmer(/member/Bodmer/)
Download(/id/ArduinoTFTdisplayofbitmapimagesfromanSDCa/?download=pdf)
h(/id/ArduinoTFTdisplayofbitmapimagesfromanSDCa/)
7Steps
.
Collection
(/file/FI83QY7I82VS7MP/)
TheAdafruit_xxx_ASlibrariesassociatedwiththisInstructablehavebeen
enhancedsignificantlybymyselffromtheoriginalsproducedbyAdafruit.Itcould
(unintentionally)bethecasethatthelibrariesarenolongercompatiblewith
Adafruitproducts,sobearthisinmindanddoNOTcontactAdafruitifyou
haveaproblem!
Asthechangesmadearenowquitesignificantitistheintenttorenamethis
libraryinfuturewhilstkeepingtheacknowledgementtoAdafruitwithin.Ifthis
changedoeshappenthenIwillcreateanassociatedInstructable.
Thetableshowshowsignificanttheperformanceimprovementsare,these
improvementsarearesultofadaptingthesoftwaretothecapabilitiesofthe
processoranddisplays.TherearenoplanstomigratetheLibrarytoARM
processors(DUEetc)asIdonothavetheneed,theprojectsIhaveplanned
onlyneedtoupdatethedisplayinfrequently(everyfewseconds)asthe
parametersbeingmonitoreddonotchangequicklyandbywritingthesoftware
efficientlytoonlyupdatetheareasofthescreenthatchangemeansIcanget
flickerfreeupdates.
Theresultforthe5.2ximprovementreportedforlinedrawingand6.2xfor
triangleoutlinesisduetoenhancementstotheBresenhamlinedrawing
algorithm.Essentiallymakinguseofthefactthatshorthorizontalandvertical
linesegmentsareinthelines(apartfromonecaseat45degrees),these
segmentscanbedrawnmuchmorequicklythanplottingindividualpixels.
The2ximprovementsaresimplymadebymakingtheSPIsendloopstighter
IMadeit!
Favorite
Share
The2ximprovementsaresimplymadebymakingtheSPIsendloopstighter
andmoreefficient.
Step7:Thefuture...
F_AS_T
IhavetestedtheF_AS_ToptionwhichusesdirectportaccessonanUNOand
thisisnowworkingfine.Uncommenttheline:
#defineF_AS_T
inthe"Adafruit_ILI9341_FAST.h"filewhenusingAtmega328(UNO/Micro
Pro/Nano)processors.Put//commentinfronttodisableforotherprocessors.
RunLengthEncoding
Oneofmynextgraphicsprojectswilluseicons,thesearesimpleimagessuch
asthermometers,compassdialsetcthatgenerallyusefewcolourswith
relativelylargeareasofthesamecolour,thismakesthemsuitablefor
compressionwithaRunLengthEncoding(RLE)algorithm.RLEisquitesimple
andfasttocompress/decompresssoisgreatfortheAVR.Thiswillmakepulling
themofftheSDcardandplottingthemevenfasterasthetypicallytheRLE
compressedfileswillbesignificantlysmallerthanarawbitmap.Potentially
iconscouldalsobestoredinFLASHaswell.Asanexamplearawimageof60x
60pixeliconis7200bytes,RLEofasimplegraphicofawarningtrianglecould
beonly1000bytes.
RLEoffonts
TheGFXlibrarycontainsfontsandthelargeroneslendthemselvestoRLE,this
willmeanthataUNOwillbeabletohavemorefontsresidentinFLASH.Watch
thisspace""!
Wehaveabenicecommentpolicy.
Pleasebepositiveandconstructive.
wIMadeit!
AddImages
HarryDutch(/member/HarryDutch)
PostComment
8daysago
Reply
3monthsago
Reply
Hi,
Thanksfor
thisgreatlibrary!It'sreallyveryuseful.
Insteadofthe
"Adafruit_ILI9341_AS"libraryItriedtouseyour
`TFT_ILI9341"
libraryfromyourGitHubbecauseit'salotfasterandleaves
morespaceformy
sketches.It'skindofworkingtomysurprise,butonlythe
coloursandthe
screenalignmentarenotcorrect.Idon'tknowifyoure
planningtoreplace
theAdafruitlibrarybyyourTFT_ILI9341forthisinstructable
butifyoudoI
wouldbeveryhappy.Anyway,thanksagainforyourgreat
work!!
RobertoV1(/member/RobertoV1)
SDwasnotworkingwithsdfullspeed.Onlysdhalfspeed
worked.
worked.
|
8
Bodmer(/member/Bodmer)(author) . RobertoV1(/member/RobertoV1)
Doyouusearesistordividerlogiclevelshifter,ifsowhat
valueresistorsdoyouuse?
Reply
3monthsago
RobertoV1(/member/RobertoV1) . Bodmer(/member/Bodmer)
Reply
Thanksforthereply!Iusedtheschematicandpindescribed 3monthsago
inthisinstructables,1.2kand1.8k
|
8
Bodmer(/member/Bodmer)(author) . RobertoV1(/member/RobertoV1)
Reply
OK,someSDCardslikefasttransitionsbetweenlogiclevels. 2monthsago
Try470Ohmsand1Kinsteadof1K2and1K8.Checkyour
displaydoesnotalreadyhave1Kinlineresistorsconnected
totheSDCard,orpostapictureofthebackofthedisplay
boardsoIcanhavealookforyou.
intriq8(/member/intriq8)
9monthsago
Reply
/mecontinuestoenthusiastically"watchthisspace"for
RLEfontdevelopments...)
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
Reply
Goodnews!Ihavetriedvariousencodingmethodsandfound 9monthsago
thatthebasicrunlengthencodingisagoodcompromise
betweenreducingthefontfilesandmakingtherenderingof
fontstoscreenfaster.AtthemomentIhavetheadapted
graphicslibrariesrunningwitha480x320displaywiththe
HX8357driver.Icanadaptotherdriverlibraries,ifyouwishto
trythenewencodedfontfilesthenletmeknowwhichTFT
driverchipyouareusing,thenIcancreateademoforyouto
tryout.
TTFN
intriq8(/member/intriq8) . Bodmer(/member/Bodmer)
8monthsago
Reply
Great,excitedtohearit.
So,asyoufound,asweetspotwiththeTFTsintermsofpriceisthose
ili93412.22.8inchTFTmodules.the2.4and2.6inparticularbalance
priceandsizewell.Theyareavailablewithtouchscreenchipforaround
$7delivered.ThetouchchipsworkwithuTouchlibraryapparently,i
startedonthetouchlessones,thoughmytouchversionhavearrivednow.
Irecentlysawthose480x320onesat$12though,verynice,almost
boughtit.Itakeisyou'reusingamega/stm32forthoseright?16bit
interfaceright?Ishouldtryoneofthose,looklikegreatvalue.thoughsee
thisone:
Incheap480x320,ifyoudidn'tseeit,youmightwanttocheckoutthe
HX8352Aone,http://www.ebay.com.au/itm/190871667912
(http://www.ebay.com.au/itm/190871667912)asithasatouchscreen,$1
orsomore.
Anotherinterestingone:a3.6"400x240ili9327forunder$10:(withtouch
apparently)http://www.ebay.com.au/itm/141648004699
(http://www.ebay.com.au/itm/141648004699).(8bitinterface).Iordered
one.
IshiftedmyTFTprojecttothe$5mapleminiusingtheSTM32duinocore,
feelinglimitedwithlackofspaceandramonthefavourite328p...Ilike
smoothbigfonts.
IspentquiteabitoftimemakingauniversalTFTcontroller[328p]with
yourlibrary,iwroteanicescrollinggraphingfunction,yourringmeters
modified/moreparameterised,optimisedserialcontrol,withsetupof
pages/elements/labels,dataupdates,etc..allpromptedbytheneedfor
morespaceforgraphicscodeandfonts,andthewishtohavethiswork
beuniversalandreusableinvariousprojects.Inthiscaseevenmovingto
adedicated328pwasnotenough,IfoundIwantedtobufferalotofstuff
inramforthedataloggingandgraph,andsdbitmapswereoutofthe
question,anddrawingcouldalwaysbefaster,soImovedagaintothe
stm32f1.
BUT:Istillwanttouse328pwiththeIli9341whereideal.Having
compressedfonts,andflashchips,makesthatSOmuchmorepossible.
Andcompressionandflashwillmakethestm32evermoreuseful.
Iseesomeofyourili9341workisportedinthatstm32arduino
repository,thoughifoundtheportedili9341duelibrarythereismuch
fasterthanyoursonalloperationsbutfillscreenandfillrect,interestingly.
Yourlibrarystillseemstobethekingfor328p,ifusingf_as_tmode.
So,inanswertoyourquestiononwhati'musing:,ili9341for328pand
stm32.Andthenanyoftheotheronesimentioned,likethat480x320one
yougot.Soyoucould/shouldputitinyourlibfortheilli9341onAVRat
least,andItwouldbeappreciatedinthestm32arduinorepositoryilli9341
driverstoo..
Here'sanidea:atsomepoint,you/I/weportitintothegTextlibrarythat
theili9341dueuses.thatappearstobeanicelibrary/fontstardardtouse,
ifwe'regoingtohavethespacesavingstobealittlemoreindulgentwith
fontchoice.Ithasmanyfontsalreadyimported,toolstoimport,etc..Oris
thatlibtoobulky/cumbersomeforyourtaste?
I'msuperhappywiththediscovery/useofthemaplemini,oftenwanting
morepower/spacethana328p,butnotwantingtobudgetthebulkier$13
mega2560+intoeverythingthatcoulduseit..
Whenitstartsapproachingthepriceofthecheapestandroidphone,you
havetorethinkwhatyou'redoingprogramminghardware.Afterallfor$40
or$50,yougeta700mhz+arm,withbattery,highrescapacitivetouch
screen,wifi,bluetooth,storage,gsm,etc.andmaturedevelopmenttools
andcommunity.Couldinterfacetothisfromyourmcuanumberofways.
Soirecon$2025isthesanitychecklevelforMCU+TFTforarduino..
Thanksagainforyourwork.thisisgreat,ifthere'sanythingicandoto
helpyoudeveloporrefineit,letmeknow.
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
Reply
TheHX8352Adisplayinthelinkdoesnotappeartohavethe 8monthsago
5Vto3.3Vlogicleveltranslatorssowouldneedanextra
board.Ihaveacoupleofthese:
http://www.ebay.co.uk/itm/301454650227
(http://www.ebay.co.uk/itm/301454650227)
TheseusetheHX8357driverandIcreatedadriverlibraryfor
itfortheArduinoMega.TheseuseHC245levelconverter
IC'ssoworkwellwithSDCards.Thereisaemptyfootprintfor
aSPIFLASHdevicetoothatlooksWinbondcompatible!It
sitsclosedownontheMegawhichmeanstheboardmustbe
dismountedtogetattheSDCardandtheotherMegapins
arenoteasilyaccessible.ButitmakesanicecheapTFT
assemblywithaMegaclone.BanggoodsellthenwithaMega
cloneforabout11:
http://www.banggood.com/Mega2560R3BoardWithUSB...
(http://www.banggood.com/Mega2560R3BoardWithUSB
Cable3_0InchTFTLCDDisplayModulep967224.html)
Ialsohavethe400x240displayyoumention,ithasresistor
basedlevelconverters.TheemptyFLASHdevicefootprint
doesnotlookWinbondcompatiblethough.Typicallythese
screensareadvertisedwiththewrongdriverbutareILI9327
based.Ihaveadapted/createdasimpleTouchlibraryforit
(astheUTFTUtouchlibraryhasreliabilityissueswiththat
display).Iamnotafanofthecheapresistovetouchscreens
thoughastheplasticonthescreeniseasilymarked.
Iseewethinkalongthesamelines,Ihaveacheapandroid
phonethathasneverbeenusedasaphone...insteadIuse
phonethathasneverbeenusedasaphone...insteadIuse
theWiFi,Bluetooth,webbrowserandtouchscreenfeatures
tocomplimentmyArduinoprojects!
IwilltidyuptheRLEsketchesatcandadaptaILI9341library
todisplaytheRLEfonts.Itmaytakemeaweekortwotoget
thisdoneasIamratherbusywithpaidworkatthemoment!
OKIthinkIhaveprobablycoveredallyourquestions!
TTFN
X
8
uhclem(/member/uhclem) . Bodmer(/member/Bodmer)
7monthsago
Reply
WhereisyourdriverfortheHX8357?IhaveonemountedtoaDue,
whereperformanceisprettybadconsideringwhattheDueiscapableof.
Thanks!
|
8
Bodmer(/member/Bodmer)(author) . uhclem(/member/uhclem)
Youcouldtrytheattached.Thisisa16bitinterfacelibrary
thatIusewitha480x320displayandaMega.Itmightnot
workforyouthough.
Reply
7monthsago
HX9357_480x320_libraries_v1.zip
(http://www.instructables.com/files/orig/FXH/UG0Q/ICJLZ5OE/FXHUG0QICJLZ5OE.zip)
X
8
uhclem(/member/uhclem) . Bodmer(/member/Bodmer)
7monthsago
Reply
8monthsago
Reply
Thanks!I'lltryit.
intriq8(/member/intriq8) . Bodmer(/member/Bodmer)
Iwanttoconvertthemanybig/fullfontsfromtheuTFTorgTextformatto
thisnewformat.AnythoughtsonhowI/weshouldapproachthat?
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
IlookedatafewoptionswhenIwantedtocreatealibrary
thatwassmallfortheUNO/328,forexampletruetypefont
convertersandreusingfontsfromotherlibrariesbutthenI
cameacross"CosmicVoid's"fonteditorsoftware:
https://forum.crystalfontz.com/showthread.php?3619...
(https://forum.crystalfontz.com/showthread.php?3619Bitmap
fonteditorforgraphicLCD)
Thisisalittleflakyandcrasheswheneditingsometimes:(...
butthereallynicefeatureisitencodesthefontsintoa
convenientCcodefriendlyformat.Thisisconfigurableand
theoutputisaniceindividualcharacterarraytextfileformat
thatisinanalmostreadytouseform(minoreditsneeded)to
compilewiththeArduinoIDE.Italsocreatestheproportional
spacingwidthtableforeachcharactertooandthefontrelated
variables(heightetc).Thismakesthingssomucheasier!Itis
alsoquitehumanreadableandpermitsindividualcharacters
tobereplacedaseachcharacterisanarraywiththeASCII
codeinthearrayname.
Thesoftwarehassomefontsincluded,Ijustwanteda
proportionalspaceHelveticastylenonseriffontwhich
fortunatelyithasinthesetinafewdifferentsizes,bold,italic
etc.Itwillalsoproduceoutlinecharacterfonts.
AsIamfamiliarwiththatsoftware(andtheminoredits
needed)IcannowcreateanewfontfileandtestitwithaTFT
displayinabout30minutes.So...toanswerthequestion,
nowIhavegonedownthatrouteIamnotsureIwouldbother
Reply
8monthsago
toconvertfontsfromotherlibraries,thoughIcanseewhythis
mightbeofgeneralinterest.
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
Thanksforyourpatience.
Reply
8monthsago
Ihavereleasedalibraryforyoutotry.SeeStep8ofmy
Instructable:
"ArduinoTFTdisplayandfontlibrary"
ThelibrarywithRunLengthEncodedfontsandexamplesis
attachedtothatstepasaZipfile.
TTFN
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
Reply
ItriedRunLengthEncodingthefontswithasimple"normal" 9monthsago
runlengthmethodbuttheresultswerenotasgoodashoped.
Compressionratiosintheorderof2to3wereobtained.Here
isaneditedreportproducedbythesketch:
Font2RLE
Fontcount=1568bytes
RLEcount=2534(biggerastherearesofew"long"pixel
runs!)
Font4RLE
Fontcount=6422bytes
RLEcount=4655
1767bytessavedwith7bitRLcounter
2032bytessavedwith3bitRLcounter
Font6RLE
Fontcount=2976bytes
RLEcount=1481
1495bytessavedwith7bitRL
1048bytessavedwith3bitRL
Font7RLE
Fontcount=2208bytes
RLEcount=1275
933bytessavedwith7bitRL
721bytessavedwith3bitRL
Font8RLE
Fontcount=6150bytes
RLEcount=2085
Difference=4065
Aswouldbeexpectedthebiggerfontshavebetter
compressionratiosastheyhavemuchlongerpixelruns.
ButInowhaveabettermethodtotry,whichisahybrid
methodwhereshortrunsarestoredasrawbytesandonly
longerpixelrunsarestoredrunlengthencoded.
IalsohaveaworkingArduinosketchforcompressingbigger
imagebitmapsstoredonanSD
cardwiththenewRLEhybridmethod,andfordisplaying
themafterwards.Thatiscurrentlywrittenas
moreofademoasthesoftwarehassomedebugstuffinit
andhasnotbeenoptimisedyet,butIamgettingcompression
ratiosintherange4:1to10:1forsuitableimages/icons.I
haveyettoadaptthesamemethodtothefonts.
Ihavesome1MbyteSPIFLASHchipsonordertooasIsee
thisasapotentialmethodforstoringthecompressedfonts
andicons,thiswillavoidthefilingsystemoverheadsimposed
byusingSDCards.
Soitisa"workinprogress"...continuetowatchthisspace""!
intriq8(/member/intriq8) . Bodmer(/member/Bodmer)
8monthsago
Reply
Excellent!Ihavebeenworkingonthisabittoo,onpaper.Myrough
calculationsthat3bitcanworkforthesmallfontsappearconfirmedby
yourtests,sweet.
Mystudiesbroughtmetothesameconclusion:aflagforliteralscouldbe
ideal.Also:
1.DidyouconsiderHuffmancoding,atreeperfont,tofurtheroptimise
theencodingofrunlengths?Doyouthinkthere'saneffiecientwayto
decodethehuffmanvalueswithoutimpactingrenderspeedseverely?It
wouldofcoursemeanyou'dhavetopackthestreamwithallthedifferent
bitlengths,itwouldnolongerbeonneat4or8bit(3+1and7+1)
boundaries.Butthehuffmanencodedvalueshavethatsurprising
unambiguousqualityastheydecode.
Howaboutsomethinglike,forexample,generatealookuptableofthe
huffmancodingforafont:
7bits,so128x2bytearray,costing256bytes,
or3bitsforsmallfonts8x2bytearraycosting16bytes,storedaspartof
thefont.
Doyouthinkthathuffmanencodingwouldbeworthwhile,ifimplemented
optimally?
Doyouknowtheproper/betterwaytostoreahuffmantreefordecoding
values?
Whenyoulookattherunlengths,haveyounoticedadistributiontrend?
[Lookingthestructureofafont,itwouldstandtoreasonalotofthe
stems/risersarethesamewidth,andtherearemanycasesofsame
lengthblackwraparoundtotherisers.]
[IthoughtIsawaniceunevendistributiononthefewsmallcharsiwas
playingwithonpaper....Ivereallygottomovethistocode.I'lllookatyour
library....]
2.AnotheroneIsawwastousetheflagbittoindicatearunofalternating
bits/vssamebits.Thisisn'ttoousefulforfontsIguess.Mightbeuseful
onabitstreamwithmanyalternatingruns.
3.LZSS?orsomethingLZish?IsawsomeonemadealightweightLZ
libraryforarduino..
4...oranythingalongthelinesofthetechniqueofcreatingarunning
dictionary,whichoptimisesforlongerwordsasitgoes.
i.e.itstartswithadictionaryofminimumdatawidth(soinourcasejust
theentries0and1.,looksthethenextunknownsequenceintheinput
stream,e.g.
input0=match,solookatnextbit:
nextbit0again,nomatchfor00,soaddtodictionary.andsoon,with
limits.
Couldtheneitherjustencode/outputthe00,add00tothedictionary,and
storethewholefinaldictionary,oryoucanencodethe0,thenadd00to
thedictionary,andtheusethedecodetimecreationofthedictionaryby
thesamerulesmethod,whichwouldhavetobeperchar,butwouldbe
prettysmalldictionary..mightstillwork.
Thattypeofscheme,itseemstome,couldbequitegoodforthekindof
patternsinthefontdata,especiallyappliedacrossthewholething.
5."Ihavesome1MbyteSPIFLASHchipsonorder"mmm,ihave4mbyte
winbondonesonorder,50ceachdelivered,samepriceasthose1Mbyte
Q80s,whichimistakenlyboughtfirst)
"Iseethisasapotentialmethodforstoringthecompressedfontsand
icons,thiswillavoidthefilingsystemoverheadsimposedbyusingSD
Cards."
YES.!!!exactly.nottomentionthey'rewaycheaperthananSDcard,and
youcanusethemforaudio,otherprogramdata,datalogging,etc..
Ifthis"fontcompressiononarduino"thingisdonewell,thisshouldbe
incorporatedinallarduinofont/gfxlibs,asitisverysorelyneeded.
I'mkeentocontributehoweverican.
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
Reply
8monthsago
Wow,somanythingstodiscuss!
Usingliteralisfontsonlygavebettercompressionforsmall
fontsandisapaintorenderatspeedbecausetheoriginal
ideabehindusingRLEisthatwegetarasterscanfeed
immediatelyasanoutputwithoutanyprocessingalgorithms
needed.Soitisfasttorender,andthisindeedisthecase.
Witha16bitinterfacefontrenderingtoscreenachievesover
1Megapixelpersecondasitisonlynecessarytosetthe16
bitcolourattheportandthengeneratetheN(whereNisrun
count)writestrobes.Thismeansalarge(48point)font
charactercanbedrawninafewmillisecondswhenpulled
fromtheArduinoFLASHmemory.
Thereisalotofscopeforfurthercompression,inparticular
therearealotofrepeatingsequences,forexampleforthe
letter"l"butitcomesdowntowhatIneedformyownprojects
andIfindthebasicRLEisgoodenoughandIliketokeep
thingssimple!IndeedIworkedoutthatonsomeprojectsthe
bestwaytoreducefontspaceistoonlyincludethe
charactersIuseratherthanthingslike"#^&"etc,soatthe
momentIamlookingatasimplerwayofincludingfont
charactersubsets(thisisalreadydoneforlargefontsasI
onlyincludednumeralsandthecharactersIwantedlike
":,a,m,p"fortimedisplays.)becauseeventheword"Hello"in
alargewillnotfitonthescreensIliketouseduetolackof
screenrealestate...butIdoliketodisplaynumeralslargeas
theyrepresentsensorreadings.
IhaveimplementedRLEwithliteralsfor16bitgraphics
images,asatestIextractedthe13framesasBMPsfromthe
GIFbelow(GIFsarenicelycompressed!),reducedthexand
yby50%togetimages122x93pixels(30KBeachBMP,
23KBfor16bitraw),encodedusingmyimageRLEsoftware
to~3KBytesperframe,savedthe13imagestoFLASHinan
ArduinoMegaandplottedtoTFT(16bitparallelinterface)as
ananimation...whichthenranmuchtoofastat11msper
frame(90framespersecond)!Thismeansthesimpleimage
(clearlymostoftheareaisjustonecolourandhencegoodfor
RLE,butthegolferimagewasantialiased)wasbeingpulled
fromflashANDplottedatover1Megapixelpersecond.Inthe
endIputa150msdelaybetweeneachframetogetthe
animationrunningatroughlytherightspeed.
AsyousaythemultiMegabitSPIFLASHchipsarecheap,
especiallyfromAliexpressetc.AtthemomentIam"playing"
withthe1Mbytechipsin8pinDILformatforaprojectbutwill
begettinglargercapacitycheaperSOIConestofitonthe
vacantspotonthebackofsomeofmyTFTdisplays.
(http://cdn.instructables.com/FCD/F05I/IAEJNSYK/FCDF05IIAEJNSYK.LARGE.gif)
intriq8(/member/intriq8) . Bodmer(/member/Bodmer)
8monthsago
Reply
8monthsago
Reply
Yes,somanypoints)
Thanksforallyourreplies!
intriq8(/member/intriq8)
Question:WhynoF_AS_Tformega?
It'sdirectportmanipulationright?Sotheport/pinmasks
aredifferentforthemega...Whatisitthatiamnaively
aredifferentforthemega...Whatisitthatiamnaively
overlookingwhenithinkthatitsjustamatteroflookingup
therelevantmegaport/pindirectmanipulationequivalents
anddoingasearchandreplace?Doesitworkdifferently?
Wouldbeevenmorehandyifitworkedfastwithmegatoo.
[Thoughcoolerthanmegawouldbeifyouoptimisedfor
stm32duino/maplemini.]
Onunoit'sonlyfasterthanthecurrentadafruitonewhen
f_as_tmodeisenabled.
|
8
Bodmer(/member/Bodmer)(author) . intriq8(/member/intriq8)
Reply
Asyousaythisispossible,thesimplereasonisthatIhave
notneededthisfacilitymyself,Iamusing16bitparallel
interfacesonmyMegaprojectswhichcanclearthescreenat
2Megapixelspersecond(weonlyneedtosetupthe16bit
colourthengeneratewritestrobesfast).TheSPIonthese
MegaprojectsisjustusedforSDcardandSPIFLASH
access.AsthedisplayisaboutthesamesizeastheMega
thelargePCBisnotanissue.Thelibrariespostedherewere
reallydevelopedjustformyownArduinoUNO/Micropro
projects(MicroproclonesfromChinaareonlyabout$2
each...)andhencetheintentwasnottodevelopan"official"
library.SothelibraryfeaturesarejuststuffIneedformy
projectsreally.TheSTM32isofinterestbutIhavenot
actuallygotaroundtobuyinganyboardsyet...
intriq8(/member/intriq8) . Bodmer(/member/Bodmer)
8monthsago
8monthsago
Reply
heheh,sorry,didn'tmeantocomeoffalldemanding,wasjustcurious
whatitinvolved,asImaybeablemakethechangesmyself.
Ok,wellifitdoesworkthewayiassume,ifidoupdateyourlibraryfor
directportmanipulationonthemega,I'llbesuretopostbackthe
changes.)
Ah,sotheworkofyoursisawoveratstm32duinowas"ported"overby
someone..
gdmuscle(/member/gdmuscle)
10monthsago
Reply
HasanyonebeenabletogetanimationontheTFTlike
gifanimationgoing?
|
8
Bodmer(/member/Bodmer)(author) . gdmuscle(/member/gdmuscle)
Reply
TheUNOcanpullpixelsofftheSDcardanddrawonscreen 10monthsago
about100pixelspermillisecond.Ananimationthatupdates
at25framespersecondgives40millisecondsperframe,in
thistimetheUNOcoulddraw100x40pixels,thusasetof
rawimagesof65pixelssquarewouldanimatequitewell.
TheGIFimagesarecompressedandtheUNOdoesnot
havetheprocessingpowertodecompressthemanddrawto
screenquickly,thustheonlysimplewayofcreatingan
animationwouldbetocreateasetofrawimages,each
beingoneframeoftheanimation.
gdmuscle(/member/gdmuscle) . Bodmer(/member/Bodmer)
Ohok,sotodothisdon'tputatimedelaybetweenthe
imagesdisplayedontheSDbitmapimages?
|
8
Reply
10monthsago
Bodmer(/member/Bodmer)(author) . gdmuscle(/member/gdmuscle)
Yes,correct.Adelaywouldonlybeneededtoslowdown
theanimationframerate.
Reply
10monthsago
gdmuscle(/member/gdmuscle) . Bodmer(/member/Bodmer)
Yeahtriedthatnotmuchofasmoothdisplaythoughgotit
workingusingbmpfilesnotsureiftheoriginaltft2bmpisfast
enough.
gdmuscle(/member/gdmuscle)
Reply
10monthsago
10monthsago
Reply
Thestrangethingisthatmydisplayshowsnothingyet
thereissomethingonthere.ItestedtheSdcardreader
it'sreadingfinebutforsomeoddreasonthetestimages
don'tshow?
|
8
Bodmer(/member/Bodmer)(author) . gdmuscle(/member/gdmuscle)
Reply
10monthsago
DoyouhavetheLEDbacklightworkingOK?
gdmuscle(/member/gdmuscle) . Bodmer(/member/Bodmer)
Reply
YeahIhookedituptoPin5highoutputalsotriedtohookit 10monthsago
directlyto3.3vnothing.Thepictureshowsthecolourgrey
swipedownleftrightbutnobmporrawimages.
RmiG(/member/RmiG)
10monthsago
Reply
Hello,
Itrythislibforshowtext,butican'trunit,yhavealotof
errorwithSPCR,SPDR,SPIFvaribalenotdeclared:(
C:\ProgramFiles
(x86)\Arduino\libraries\Adafruit_ILI9341_AS\Adafruit_ILI9341_AS.cpp:394:13:
error:'SPSR'wasnotdeclaredinthisscope
while(!(SPSR&_BV(SPIF)))
Thanks.
|
8
Bodmer(/member/Bodmer)(author) . RmiG(/member/RmiG)
Reply
ThesedefinitionsareinastandardAVRheaderfilecalledup 10monthsago
duringcompilation.AreyouusinganAVRprocessor....!
WhichIDEversionandArduinoboardareyouusing?
RmiG(/member/RmiG) . Bodmer(/member/Bodmer)
10monthsago
Reply
ItryonArduinoDUEwhichisnotAVRIthink
CPU:AtmelSAM3X8EARMCortexM3
IDE:1.6.2
|
8
Bodmer(/member/Bodmer)(author) . RmiG(/member/RmiG)
OK,IdonothaveDUEsocannothelpadaptthelibraryfor
thatplatform.YoumaybeabletogethelpontheArduino
forumastheproblemsinportingtotheDUEarelikelytobe
commonwithotherlibrariesandsketches.SorrybutuntilI
getaDUEIcannothelp!
Reply
10monthsago
RmiG(/member/RmiG) . Bodmer(/member/Bodmer)
10monthsago
Reply
Ok,noproblemeiwillcheckonarduinoforumandcomebackifihavean
answer.
FEATURED CHANNELS
HomeRepair
Knitting
(/tag/type
id/category
Survival
(/tag/type
workshop/channel id/category
home
outside/channel
improvement/)
Newsletter
survival/)
Breakfast
(/tag/type
Minecraft
(/tag/type
(/tag/type
id/category
id/category
id/category
craft/channel
food/channel
play/channel
knittingand
breakfast/)
minecraft/)
crocheting/)
USB
(/tag/type
Comics
(/tag/type
id/category
id/category
usb/)
comics/)
Join2million+toreceiveinstant
inspirationinyourinbox.
enteremail
I'min!
Mobile
Downloadourapps!
Android(https://play.google.com/store/apps/details?id=com.adsk.instructables)
iOS(https://itunes.apple.com/app/instructables/id586765571)
Windows(http://apps.microsoft.com/windows/enus/app/7afc8194c771441a959054250d6a8300)
AboutUs
FindUs
WhoWeAre(/about/)
Facebook(http://www.facebook.com/instructables)
Advertise(/advertise/)
Youtube(http://www.youtube.com/user/instructablestv)
Contact(/about/contact.jsp)
Twitter(http://www.twitter.com/instructables)
Jobs(/community/PositionsavailableatInstructables/)
Help(/id/howtowriteagreatinstructable/)
Pinterest(http://www.pinterest.com/instructables)
Google+(https://plus.google.com/+instructables)
Tumblr(http://instructables.tumblr.com)
Resources
ForTeachers(/teachers/)
ArtistsinResidence(/air)
GiftProAccount(/account/give?sourcea=footer)
Forums(/community/)
Answers(/tag/typequestion/?sort=RECENT)
Sitemap(/sitemap/)
TermsofService(http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21959721) |
PrivacyStatement(http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21292079) |
LegalNotices&Trademarks(http://usa.autodesk.com/legalnoticestrademarks/) | MobileSite(http://m.instructables.com)
(http://usa.autodesk.com/adsk/servlet/pc/index?id=20781545&siteID=123112)
2015Autodesk,Inc.
WinterDrinks
technology/channel
costumes/channel (/id/Holiday
Drinks/)
Weddings
(/howto/weddings/)