tag:blogger.com,1999:blog-75298078793318733942024-03-20T01:31:03.149-07:00Yikes!I'm addictive as hell, don't even think about quitting.Zachhttp://www.blogger.com/profile/02771148031495980767noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-7529807879331873394.post-62736526177597389302007-12-14T13:22:00.000-08:002007-12-14T14:14:47.486-08:00NES Controller -> Arduino<span class="Apple-style-span" style="font-size: small;">So I'm finally done with this semester and having trouble filling the hours. Went for a run, read a book, did some climbing...</span><div><span class="Apple-style-span" style="font-size: small;"><br /></span><div> </div><div><span class="Apple-style-span" style="font-size: small;">... and then found an NES controller buried in a box.</span></div><div><span class="Apple-style-span" style="font-size: small;"><br /></span></div><div> </div><div><span class="Apple-style-span" style="font-size: small;">Thanks to </span><a href="http://pinouts.ru/Game/snescontroller_pinout.shtml"><span class="Apple-style-span" style="font-size: small;">pinouts.ru</span></a><span class="Apple-style-span" style="font-size: small;">, I rigged up an NES controller adapter using the Arduino. Don't really have anything to use with it, but I suppose it's nice to have around.</span></div><div><span class="Apple-style-span" style="font-size: small;"><br /></span></div><div><a href="http://web.ics.purdue.edu/~zdicklin/NESController.c"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-weight: bold;">The code:</span> NESController.c</span></a></div><div><span class="Apple-style-span" style="font-size: small;"><br /></span></div><span class="Apple-style-span" style="font-size: small;"><img 0="" 10px="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheJNoQtIYxGMCsj7jeKGO79-_hyphenhyphenZLtAmkgjBjE6pp1j320O0-mLYwN0mnfwAcjfx-oPOJzyIv59Oed_XUaNtQxvzQ53NGGoZ8-l86efVAnpeMLgCUPZOk3RkIjhh-gerw-Z_UtLlzMsxg/s320/Photo+1.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5143943378333334370" /></span><div><span class="Apple-style-span" style="font-size: small;">The eight leds light up according to the buttons. NES controller plugged in according to this pinout:</span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style=" "></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><br /></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size: small;"> o 4</span></span></span></div><div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size: small;">1 o o 5</span></span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size: small;">2 o o 6</span></span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size: small;">3 o o 7</span></span></span></div><div><span class="Apple-style-span" style="font-size: small;"><br /></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">1. 5V</span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">2. Unknown</span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">3. Unknown</span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">4. GND</span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">5. CLK</span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">6. Latch</span></span></div><div><span class="Apple-style-span" style=" "><span class="Apple-style-span" style="font-size: small;">7. Data Out</span></span></div></div><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/m7cJz52om1Q"><embed src="http://www.youtube.com/v/m7cJz52om1Q" type="application/x-shockwave-flash" width="425" height="350"></embed></object><div><div><div><br /></div></div></div></div>Zachhttp://www.blogger.com/profile/02771148031495980767noreply@blogger.com0tag:blogger.com,1999:blog-7529807879331873394.post-52055549459868142222007-11-22T20:41:00.001-08:002007-11-23T08:33:51.158-08:00iTunes CacheSo my MacBook's partition map got screwed up yesterday. I'm pretty well backed up, so instead of recovering I decided to just start over from scratch. My biggest issue is dealing with music- I only have a 60GB hard drive, like 30GB of music, and Tiger is somehow like 15GB. With everything else I'm usually between 1GB and 4GB of free space. <div><br /></div><div>I instead of copying my whole library back over, I set up a simple music cache with Automator and Python.<br /><br />Working on the premise that I'm most likely to listen to music I've already listened to, the Automator script copies the current track from my external drive to the directory "~/Music/Local Cache/".<div><img style="cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEityPN5Jm9eSg2PX1vGEiBRqlIAvurAxNqZZPlfrRn49Oc1jT7N_I4Cqs6vJtlnYI5oLJFa84fwuO62kzHYFnmFKJaWXazCzMEUQ0RWXrPsI52rUQwHOGGEpv-trWj0WM1Q8FglKaXvVwk/s320/Picture+1.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5135892381252434370" /></div><div><br /><div> </div><div>I wrote a Python script to run the Automator script every 30 seconds. </div><div></div><div><br /><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size:x-small;">#! /usr/bin/env python<br />import os<br />import time</span></span></div><div><span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size:x-small;"><br />while(1):<br /> os.popen4("automator '~/Music/iTunes Cache/Scripts/iTunesCache.workflow'")<br /> time.sleep(30)</span></span><br /></div><div><br /></div><div> </div><div>Named it "iTunes Launcher.py" and saved it in "~Music/iTunes Cache/Scripts/" along with "iTunesCache.workflow"</div><div><br /></div><div> </div><div>Made it executable, changed the icon, and placed it in the dock:</div><div><img style="cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4RBlS_6W4D7-N4QRo5US5IY4yKO8rRGvCFFvhKc8OBcwuxROSNrscTFn2o2k1gLu7bfuS6AcsM23FmNaFoJjON-BGyGU0SvPgLglCQR7b-HGwznwnfE5JOd1DBMBoFtsjd9_iNKypdqA/s320/Picture+4.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5135894730599545298" /></div><div><br /></div><div>Run iTunes from the launcher, and your current songs are cached. The Automator script is set to load each copied song into the playlist "Local Cache." This places the song in my library twice, the local and external versions, so I can go back later and remove references to the external drive using iTunes "Show Duplicates" feature.</div><div> </div></div></div>Zachhttp://www.blogger.com/profile/02771148031495980767noreply@blogger.com0tag:blogger.com,1999:blog-7529807879331873394.post-19205744756210052362007-11-16T21:40:00.000-08:002007-11-16T21:44:51.253-08:00Touchpad + Arduino + Cocoa + Quartz, Part 2Touchscreen -> Arduino -> USB -> Cocoa (AMSerial, modified) -> Quartz<br /><br /><br /><a style="left: 0px ! important; top: 0px ! important;" title="Click here to block this object with Adblock Plus" class="abp-objtab-02794860336301761 visible ontop" href="http://www.youtube.com/v/ScqOmrnduBs"></a><a style="left: 0px ! important; top: 0px ! important;" title="Click here to block this object with Adblock Plus" class="abp-objtab-02794860336301761 visible ontop" href="http://www.youtube.com/v/ScqOmrnduBs"></a><object height="350" width="425"> <param name="movie" value="http://www.youtube.com/v/ScqOmrnduBs"> <embed src="http://www.youtube.com/v/ScqOmrnduBs" type="application/x-shockwave-flash" height="350" width="425"></embed> </object><br /></br><br /><br />Touchscreen -> Arduino -> PWM. Controlling a light source with the single axis, instead of the 3d cube.<br /></br><br /><object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/1u3WJB2yWvc"> </param> <embed src="http://www.youtube.com/v/1u3WJB2yWvc" type="application/x-shockwave-flash" width="425" height="350"> </embed> </object>Zachhttp://www.blogger.com/profile/02771148031495980767noreply@blogger.com0tag:blogger.com,1999:blog-7529807879331873394.post-310016204026229062007-11-16T19:13:00.000-08:002007-11-16T20:47:48.376-08:00Touchpad + Arduino + Cocoa + QuartzI bought a LCD off eBay about a year ago with a 4 wire touchscreen. Unfortunately, I'm unable to find the LCDs specs, but I'm still able to use the touchpad. One axis of the touchscreen is connected to the Arduino, which performs input, smoothing, and serial output. I modified the AMSerial Cocoa application from "Harmless Cocoa" ( <a href="http://www.harmless.de/cocoa.php">http://www.harmless.de/cocoa.php</a> ) to control a Quartz viewer with the incoming serial data.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpK-ni5IStCHOzjGN460JJC1ko-KqDv72O1QdT1J-pTXb-83BIC1KGdwprnJDwfDVaSeR_tsEj7z8bXU5AR5XLv5qRKbBsZkWP3MCW60kgK5SNqubpPn7TuDNu0VgVa2aIsT96ESZmxgc/s1600-h/Picture+3.jpg"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpK-ni5IStCHOzjGN460JJC1ko-KqDv72O1QdT1J-pTXb-83BIC1KGdwprnJDwfDVaSeR_tsEj7z8bXU5AR5XLv5qRKbBsZkWP3MCW60kgK5SNqubpPn7TuDNu0VgVa2aIsT96ESZmxgc/s400/Picture+3.jpg" alt="" id="BLOGGER_PHOTO_ID_5133646109061659026" border="0" /></a><br />The Cocoa application. I am a little unclear on USB drivers and how the AMSerial software works, so the Arduino application must be open with the serial monitor running in order to function. Right now this project is in the 'It works but I'm not really sure why' stage.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgstTpMregG5lYX53yq5VprWgwI1WSGcpqMEmXT0dG-pB8BfqOiZkjYngzh3d2haf9dIbMQeazaIhrwo-8VPoB1T34459vgx6blt2ZDNr9HLPZnwEFpDxAHMHfnjsC0VQbaBvL29xjNuWA/s1600-h/touchscreen_circuit.jpg"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgstTpMregG5lYX53yq5VprWgwI1WSGcpqMEmXT0dG-pB8BfqOiZkjYngzh3d2haf9dIbMQeazaIhrwo-8VPoB1T34459vgx6blt2ZDNr9HLPZnwEFpDxAHMHfnjsC0VQbaBvL29xjNuWA/s320/touchscreen_circuit.jpg" alt="" id="BLOGGER_PHOTO_ID_5133646813436295602" border="0" /></a><br />The touchscreen circ<span style="font-size:100%;">uit. I'll post schematics and references later. Only one axis is configured.<br /></span><br /><br />Snippet of code converts serial data (0 to 1024) to NSString representation of degrees, then sends data to the qcPatchController.<br /><span style="font-size:85%;"><span style="font-family:courier new;"><span style="font-weight: bold;">// data is NSData object taken from serial port. Converted to float</span><br /><span style="font-weight: bold;">// for rotation</span><br />NSString* rotString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];</span><br /><span style="font-family:courier new;">float rotVal = [rotString floatValue]/1024*400;</span><br /><br /><span style="font-weight: bold;font-family:courier new;" >// Only accept rotation values between 0 degrees and 400 degrees</span><br /><span style="font-weight: bold;font-family:courier new;" >// Reduces trackpad and serial read errors, since<br />// 0 <= rotVal <= 400. </span><span style="font-family:courier new;"><br />if(rotVal > 0 && rotVal < 400)<br />{<br /> rotString = [NSString stringWithFormat:@"%f",rotVal];<br /></span><span style="font-family:courier new;"> [qcController setValue:rotString forKeyPath:@"patch.yrot.value"];</span><br /><span style="font-family:courier new;"> lastRotVal = rotVal;</span><br /><span style="font-family:courier new;">}</span></span><br /><br /><span style="font-size:100%;"><a href="http://web.ics.purdue.edu/%7Ezdicklin/singleaxistouchpad.c">Arduino Single Axis Touchscreen Code (singleaxistouchpad.c)</a><br /><br /><a href="http://web.ics.purdue.edu/%7Ezdicklin/ArduinoTouchpad.zip">Arduino Touchpad (modified AMSerial) xCode project</a></span>Zachhttp://www.blogger.com/profile/02771148031495980767noreply@blogger.com1