Вы находитесь на странице: 1из 12

The Desktop Contemplator Craig A.

Lindley 11/11/2012
Introduction
I didn't start out to build a personal light show for my desk, but in the end that is what happened. It all
started when I saw a SainSmart 3.2 320 x 20 !"! #$% display with built in display &ontroller, tou&h
s&reen &ontroller and S% &ard interfa&e for sale on 'ma(on for )*+. I already had an 'rduino ,no on
hand so &onne&ting these two de-i&es seemed like a natural thing to attempt. .a-ing ne-er &onne&ted
an #$% display to a mi&ro &ontroller before I was anxious to do so. "inding a well written dri-er
library /see 0esour&es1 for this display put the i&ing on the &ake so I got to work wiring things together.
In an afternoon I wired the #$% display to the 'rduino, downloaded and installed the ,!"! dri-er on
my 2a& and &ompiled and ran the demos that &ame with the dri-er. I was ama(ed at how easy this
&ame together and I had the basis for my personal light show running in less than a day.
'fter seeing the demos I started thinking about what else I &ould make this #$% display do so I started
pulling out &ode I had written o-er the years and began porting it to the 'rduino ,no. "irst off the
2andelbrot set. 3hile the &ode worked and the results were beautiful it took a full fi-e minutes to
generate whi&h was 45 be&ause I wasn't in any hurry. !he long generation time was not to surprising
be&ause the 2andelbrot set re6uires a lot of floating point &al&ulations whi&h are time &onsuming on
any 7 bit pro&essor. 86ually as pretty and in general less pro&essor intensi-e are the &al&ulations of
9ulia sets. So this is what I tried next and some of the images produ&ed took my breath away. I was
starting to think this hardware &ombination had some merit so one thing lead to the next and pretty
soon I had about *+ different display patterns running in&luding: 2andelbrot set, 9ulia sets, plasma
patterns, numerous spirograph patterns, star burst patterns, &on&entri& s6uares and &ir&les and mu&h
more. ;ot being satisfied with stati& repeating imagery, I added a large dose of randomness into the
pattern generation pro&ess and with the addition of numerous palettes /some of whi&h also &ontain
randomness1 I was soon generating some -ery uni6ue images.
It was then that it hit me. I should pa&kage this thing up as a desktop de-i&e and let it generate images
ad infinitum. 'fter all the hardware &ost less than )0 so why not.
Sin&e ha-ing this de-i&e on my desk<ben&h, I ha-e found it helps me think. 3hen I get stu&k on
something I am working on I glan&e o-er at the display for a few minutes taking my mind off of things
whi&h sometimes helps in finding a solution. "or this reason I'-e de&ided to &all this de-i&e a =%esktop
$ontemplator.
The Hardware
>uilding a $ontemplator re6uires the ele&troni& &omponents shown in the parts list of "igure 4ne.
4n&e you ha-e gathered the re6uired &omponents, wiring the 'rduino ,no to the #$% display is easy
though rather tedious due to the number of wires in-ol-ed. ' lot of wires are re6uired be&ause I used a
*+ bit interfa&e between the 'rduino ,no and the #$% display. I &hose this instead of an 7 bit or serial
interfa&e in the interest of performan&e. ' draw ba&k to using the *+ bit interfa&e with the 'rduino ,no
is that it uses up e-ery a-ailable I<4 pin. !his means neither the tou&h s&reen &omponent nor the S%
&ard interfa&e a-ailable on the #$% display's ?$> &an be used. #u&kily neither were ne&essary for this
appli&ation.
'll re6uired &onne&tions between the 'rduino ,no and the #$% display are shown in !able 4ne and
?age *
The Desktop Contemplator Craig A. Lindley 11/11/2012
the #$% display &onne&tor pinout is shown in "igure "our. !ake your time when doing this wiring and
double &he&k your work when you're finished before applying power.
!he $ontemplator is programmed and powered -ia the ,S> &able plugged into the 'rduino ,no. 4n&e
programming is &ompleted a ,S> &harger &an be used to power the $ontemplator.
Optional Hardware
's I was writing this arti&le, I dis&o-ered SainSmart also sells an assembly &onsisting of an 'rduino
2ega2@+0, a shield for &onne&ting the #$% display to the 'rduino and the same #$% display we are
using here. !hey &all this the:
SainSmart Mega250 !oard"#.2 T$T LCD Mod%le Display"Shield &it $or Atmel Atmega A'(
1A) Atmega*)2
and it is a-ailable from their web site or on e>ay. If you were to buy this assembly at A)@@ you &ould
use it without ha-ing to do any wiring at all. ' minor software &hange /to be des&ribed shortly1 is
re6uired howe-er to run the $ontemplator sket&h on this hardware. ' maBor ad-antage to using this
hardware is that there are many more I<4 lines a-ailable whi&h allows a&&ess to the tou&h s&reen
&ontroller and the S% &ard interfa&e if these are important to your appli&ation. 'dditionally the
2ega2@+0 has four times the 0'2 /751 and eight times the flash /2@+51 whi&h would allow many
more display patterns to be de-eloped.
?age 2
The Desktop Contemplator Craig A. Lindley 11/11/2012
$ig%re +ne
,le-troni- .arts List
.arts /otes
'rduino ,no >oard 4ther 'rduino's &an be used but this will ne&essitate &hanges
in the software
.* break away male header pins Cou need enough of these pins to populate all of the female
I<4 &onne&tors on the 'rduino ,no
SainSmart 320x20 !"! #$% display 3.2 display although other SainSmart displays based on the
SS%*27D &ontroller will probably work as well.
,S> $able !he ,S> &able will be&ome a permanent part of the
$ontemplator if you pa&kage it like I did.
,S> $harger "or running the $ontemplator after programming is
performed.
.ook up wire #ight gauge flexible wire is best
2E ohm *<2 watt resistor !his is re6uired to power the #8% ba&k lights of the #$%
display. See !able 4ne.
The Software
!he $ontemplator re6uires two pie&es of software for its operation. !he first is the ,!"! dri-er library
for the #$% display and the se&ond is the 'rduino sket&h I wrote &alled Contemplator.ino /see
0esour&es for both1.
Installing the UTFT Library
Cou &an skip this se&tion if you already know how to install an 'rduino library. If you don't, read on.
*. 8xit the 'rduino I%8 if you ha-e it running.
2. %ownload the ,!"! library /,!"!.rar1 using the link spe&ified in 0esour&es.
3. 8xtra&t the library files dire&tory using whate-er file extra&tion tool appropriate for your
platform /windows, linux, osx, et&.1.
. $opy the ,!"! dire&tory to your arduino<libraries dire&tory. !he dire&tory stru&ture should be
arduino<libraries<,!"!.
@. !he library should now be installed
!o -erify &orre&t installation of the library start up the 'rduino I%8 and sele&t "ile<8xamples from the
menu. Cou should see the ,!"! entry listed.
4n&e you ha-e the hardware wired up, the ,!"! dri-er installed and the $ontemplator sket&h a-ailable
you &an download the sket&h -ia the 'rduino I%8 and wat&h the magi& happen.
Cou don't need to understand how the $ontemplator sket&h works in order to use and<or appre&iate it.
?age 3
The Desktop Contemplator Craig A. Lindley 11/11/2012
If, howe-er, you would like to know how the -arious graphi&s display patterns work or if you would
like to &hange the sket&h to add new display patterns or remo-e existing ones, more in depth
knowledge is re6uired. !he best way to gather this knowledge is by knowing how the $ontemplator is
supposed to work and by studying the $ontemplator sket&h.
Basic Operation
's mentioned in the introdu&tion, the $ontemplator pro-ides *+ display patterns for our -iewing
pleasure. $ode in the sket&h randomly sele&ts whi&h display pattern is displayed and makes sure that all
*+ patterns are displayed before any are allowed to repeat. !he flags array in the &ode &ontrols this. '
display pattern will be displayed for either 30 se&onds or the time it takes for the pattern to generate
and display itself, whi&he-er is shorter. If display pattern generation takes less than 30 se&onds some
patterns will repeat so you will see them numerous times in su&&ession.
!he software was designed so that the indi-idual display patterns do not need to &on&ern themsel-es
with display duration timing. 'll they need to do is to &all a fun&tion &alled checkForTimeout()
periodi&ally and if their display time period has expired, their exe&ution will &ome to an end and the
next display pattern will be in-oked. !he setjmp and longjmp me&hanism built into the 'rduino
programming language allows this work. Foogle these terms if you are interested in how.
'nother interesting aspe&t of the &ode is the use of an array /&alled patternFunctions in the &ode1 of
fun&tion pointers to the display pattern routines. ' display pattern is sele&ted and exe&uted -ia an index
into the array with this single line of &ode:
(*patternFunctions[index])();
' typi&al display pattern routine is shown below. !his &ode draws a series of &onne&ted line segments
until its time is up. 'ny display pattern routines you would write would resemble this &ode.
void linesPattern() {
int x, y, xPrev, yPrev;
// Pick a random palette
int paletteNumber = random(NUM!"P#$%&&%');
(eneratePalette(paletteNumber);
// Pick a random place to start )it*in t*e palette
int color+ndex = random(P#$%&&%'+,%);
xPrev = -+.&/$#N.'0#P% / 1;
yPrev = /%+2/&$#N.'0#P% / 1;
)*ile (true) {
3or (int i = 4; i 5 64; i77) {
lcd8set0olor(palette9color+ndex:8red, palette9color+ndex:8(reen, palette9color+ndex:8blue);
color+ndex77;
color+ndex ;= P#$%&&%'+,%;
x = random(M#<<$#N.'0#P%);
y = random(M#<=$#N.'0#P%);
lcd8dra)$ine(x, y, xPrev, yPrev);
?age
The Desktop Contemplator Craig A. Lindley 11/11/2012
xPrev = x;
yPrev = y;
delay(>4);
?
c*eck"or&imeout();
delay(@444 A B%&-%%NP#&&%CN.%$#='%0!N.');
lcd8clr'cr();
?
?
Important things to note about this &ode are:
!he palette from whi&h the &onne&ted lines will be &olored is sele&ted randomly.
!he &olor pi&ked for the first line is sele&ted randomly from the &olors &ontained in the palette.
' while loop is used used to &ontinually &y&le this display pattern.
!he checkForTimeout fun&tion is &alled within the while loop.
!here is a delay after all 70 lines ha-e been displayed. !hen the display is &leared and the
pro&ess starts o-er.
's mentioned, a software &hange is re6uired to the $ontemplator.ino sket&h if a SainSmart 2ega2@+0
is used instead of an 'rduino ,no. !he normal instantiation of the #$% dri-er for an 'rduino ,no is as
follows:
// Uncomment out next line )*en 'ainsmart $0. display connected directly to #rduino Uno
U&"& lcd(''.@16D, @D, @6, @E, @>, $#N.'0#P%);
If you are going to use the 2ega2@+0 you would &omment out the line abo-e and un&omment the
,!"! line below:
// Uncomment out next line )*en runnin( on 'ainsmart #rduino Me(a 1F>4 7 $0. s*ield 7 $0. display
// U&"& lcd(''.@16D, G6, GD, H4, H@, $#N.'0#P%);
'nd with that &hange you should be good to go. 2ake sure you &hange the board type in the I%8 to
refle&t whi&h 'rduino you are using.
Construction and Packaging
!he $ontemplator was designed to sit on my desk so I wanted to make it as small and unobtrusi-e as
possible. I also wanted to make it stru&turally sound so it would last a long time. !o this end I epoxied
four 3< wooden dowels /*<7 in diameter1 to the top &orners /&omponent side1 of the 'rduino ?$>. I
then inserted .* male header pins into all of the 'rduino's female headers to whi&h I would solder
wires from the #$% display's &onne&tor.
I then epoxied the other end of the four dowels glued to the 'rduino onto the ba&k of the #$% display's
?$> making sure to miss all of the &omponents and to orient the 'rduino so the ,S> &onne&tor was
opposite the &onne&tor on the #$% display. I made sure I left enough spa&e so I &ould solder to the
display's &onne&tor pins. I wrapped this assembly with a rubber band while the epoxy dried. 4n&e the
glue &ured and the assembly was stable, I soldered short wires from the display &onne&tor to the
?age @
The Desktop Contemplator Craig A. Lindley 11/11/2012
appropriate header pins on the 'rduino as spe&ified in !able 4ne.
I pa&kaged my $ontemplator in a &ustom wooden box but you &an pa&kage yours anyway you like. I
made my box out of ash and walnut for a ni&e &ontrast and a furniture like appearan&e. 4-erall the
dimensions are 3.E@ /wide1 x .E@ /tall1 x 2.2@ /deep1. !he parts list for the box is as follows:
0%antity Material Length 1idth Thi-kness $%n-tion
2 'sh .E@ *.@ 3<7 Sides
2 'sh 3 *.@ 3<7 !op >ottom
* 3alnut .E@ 3.E@ 3<7 "ront ?anel
3ith &utout for the #$% to protrude
* 3alnut .E@ 3.E@ 3<7 0ear ?anel
3ith hole drilled for ,S> &able
>rass G+ s&rews for holding the ba&k on
Flue "or gluing the box together
'fter &ompleting the box, I ga-e it a &ouple of &oats of natural finishing oil and, when dry, steel wooled
it and then rubbed it with paste wax. !he finish turned out -ery smooth and ni&e. See the photos.
!he &utout for the #$% display in the front panel was si(ed so that the a&tual display fit through the
&utout but the display's ?$> did not. %uring final assembly I put a small amount of sili&on &aulking
onto ea&h &orner of the display's ?$> and pressed the display into the &utout. 4n&e dried, the sili&on
holds the display<'rduino assembly in pla&e but it &ould easily be remo-ed for ser-i&ing.
I had to modify a ,S> &able to make it work for this appli&ation. I &ut off the end of the &able that
plugs into the 'rduino, remo-ed the plasti& en&apsulation around the &onne&tor and then unsoldered the
wires from the &onne&tor /taking note of whi&h &olor wire went where1. I then passed the &able through
the hole drilled in the rear panel of the box, stripped and tinned the wires and re&onne&ted them to the
,S> &onne&tor. "inally the ,S> &onne&tor was plugged into the 'rduino.
't this point I downloaded &ode into the 'rduino to make sure e-erything was still working. 4n&e I
was satisfied all was well, I pla&ed some 3<7 foam on the ba&k of the 'rduino's ?$>, put the rear
panel in pla&e and s&rewed it on. !he foam pro-ided Bust enough thi&kness to gently hold the
display<'rduino assembly in pla&e. "inally, be&ause the frame around the #$% is white, I &ut pie&es of
bla&k &ardboard and glued them onto the white frame to &o-er it. 3ith that the $ontemplator was
&omplete and has been setting on my workben&h<desk e-ery sin&e.
Conclusions
"lashing #$% displays and other blinky things are not for e-eryone. >ut for me, ha-ing a personal light
show on my desk is a treat. !here is something neat about ha-e a little de-i&e with its one purpose in
life to &ontinually generate images to &alm and ama(e me. 3hen I get stu&k on something I am
working on I look o-er at the $ontemplator and many times the &hange in fo&us is enough to get me
?age +
The Desktop Contemplator Craig A. Lindley 11/11/2012
going again. I think this might work for you as well.
Resources
!he following links may be of interest to those seeking more information on the topi&s des&ribed in this
arti&le.
!he offi&ial sour&e of 'rduino information is: http:<<arduino.&&.
!he free and open sour&e 'rduino de-elopment tools for 3indows, 4SH and #inux are a-ailable for
free at: http:<<arduino.&&<en<2ain<Software. I used -ersion *.0.* to de-elop this software.
!he 'rduino ,no is a-ailable from numerous sour&es in&luding: 'dafruit, 0adio Sha&k, Spark"un,
e>ay, et&.
!he #$% display is a-ailable at: http:<<www.sainsmart.&om<module<l&dImodule<tftIl&dI
module<sainsmartI3I2ItftIl&dIdisplayItou&hIpanelIp&bIadapterIsdIslotIforIarduinoI2@+0.html. It is also
sold through 'ma(on.
!he &ombination of an 'rduino 2ega2@+0, a display shield and #$% display is a-ailable at:
http:<<www.sainsmart.&om<homeIpageI-iew<sainsmartImega2@+0IboardI3I@ItftIl&dImoduleIdisplayI
shieldIkitIforIatmelIatmegaIa-rI*+auIatmega7u2.html and through 'ma(on.
!he 'rduino sket&h des&ribed in this arti&le is a-ailable from the ;uts and Jolts website and is &alled
$ontemplator.ino.
Information about the ,!"! #$% dri-er written by .enning 5arlsen is a-ailable at:
http:<<www.henningkarlsen.&om<ele&troni&s<library.phpKidL@*
Author BIO
$raig has been interested in the produ&tion of lights<sounds<musi& with &omputers for a -ery long time.
.is most re&ent book is =%igital 'udio with 9a-a published by ?renti&eI.all. .e li-es in the
mountains of $olorado and &an be &onta&ted at &alhBhMgmail.&om. 3hen not messing around with
ele&troni&s, &omputer proBe&ts, wood working or beer brewing, he does a solo musi&al a&t around
$olorado Springs.
?age E
The Desktop Contemplator Craig A. Lindley 11/11/2012
$ig%re T2o
SainSmart #203240 T$T LCD display
$ig%re Three
An Ard%ino )no
$ig%re $o%r
SainSmart #203240 T$T LCD Display Conne-tor .ino%t
?age 7
The Desktop Contemplator Craig A. Lindley 11/11/2012
Ta5le +ne
LCD Display to Ard%ino )no Conne-tions 6or 1 !it Data 7nter6a-e
LCD Display
.in /%m5er
LCD Display
Signal /ame
Ard%ino )no
Signal /ame
/otes
2* %>0 %7 *+ bit data
22 %>* %D *+ bit data
23 %>2 %*0 *+ bit data
2 %>3 %** *+ bit data
2@ %> %*2 *+ bit data
2+ %>@ %*3 *+ bit data
2E %>+ '0 *+ bit data
27 %>E '* *+ bit data
E %>7 %0 *+ bit data
7 %>D %* *+ bit data
D %>*0 %2 *+ bit data
*0 %>** %3 *+ bit data
** %>*2 % *+ bit data
*2 %>*3 %@ *+ bit data
*3 %>* %+ *+ bit data
* %>*@ %E *+ bit data
0S '@ %ata<$ommand Sele&tor
@ 30 ' 3rite 8nable /a&ti-e low1
+ 0% @J 0ead 8nable 0% /a&ti-e low1
tied to @J
*@ $S '3 $hip Sele&t /a&ti-e low1
*E 08S! '2 $hip 0eset
*D #8%I' @J #$% signal tied to @J through
2E ohm resistor
* F;% F;% Fround
2 J$$ @J ?ower
;ote: there are no I<4 lines left o-er to &onne&t the 'rduino ,no to the tou&h s&reen &ontroller or S% &ard interfa&es so
these aspe&ts of the &ir&uitry are not a-ailable.
?age D
The Desktop Contemplator Craig A. Lindley 11/11/2012
.hoto +ne
The Desktop Contemplator
.hoto T2o
The Desktop Contemplator
?age *0
The Desktop Contemplator Craig A. Lindley 11/11/2012
.hoto Three
The Desktop Contemplator
.hoto $o%r
The Desktop Contemplator Display .attern
?age **
The Desktop Contemplator Craig A. Lindley 11/11/2012
.hoto $i8e
The Desktop Contemplator Display .attern
.hoto Si3
The Desktop Contemplator Display .attern
?age *2

Вам также может понравиться