tag:blogger.com,1999:blog-36235155925517807702024-03-17T23:00:53.498-04:00Max Thrun's Project BlogMax Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-3623515592551780770.post-65948824441361636502013-07-26T00:16:00.000-04:002016-03-09T16:37:34.042-05:00BeagleBone GamingCape<table border="0">
<tr>
<td valign="top">
<br>
<b>TEAM MEMBERS</b>
<br><br>
Max Thrun<br>
<br>
<b>PROJECT DESCRIPTION</b>
<br><br>
Older brother of the <a target="new"
href="http://bear24rw.blogspot.com/2012/07/msp430-launchpad-gamingpack.html">LaunchPad
GamingPack</a>, the BeagleBone GamingCape transforms your
BeagleBone into a full fledged hand-held gaming console capable of
playing all the classics such as NES, Gameboy, Sega GameGear, and
even Doom. Just drop in 4 AAA batteries and you'll be playing your
favourite games <strike>discretely at work</strike> in no time.
<br><br>
<b>PROJECT FEATURES</b>
<br><br>
- 320x240 16Bit Color TFT LCD<br>
- Analog joystick + 2 Thumb Buttons<br>
- 3D Gyro, 3D Accelerometer, 3D Magnetometer<br>
- Headphone Out + Mic In<br>
- Supports:
<ul>
<li>NES</li>
<li>GameBoy</li>
<li>GameBoy Color</li>
<li>GameBoy Advance</li>
<li>Sega Master System</li>
<li>Sega Game Gear</li>
<li>Doom</li>
</ul>
</td>
<td valign="top">
<p style="text-align:center;"><img src="http://i.imgur.com/drChce4.png" alt="" border="0"></p>
</td>
</tr>
</table><br>
<h1>Video</h1>
<hr>
<br>
<center>
<object width="640" height="360"><param name="movie" value="//www.youtube.com/v/wj1T84orbeY?hl=en_US&version=3&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/wj1T84orbeY?hl=en_US&version=3&rel=0" type="application/x-shockwave-flash" width="640" height="360" allowscriptaccess="always" allowfullscreen="true"></embed></object>
</center>
<br>
<a target="new" href="http://www.youtube.com/watch?v=wj1T84orbeY">http://www.youtube.com/watch?v=wj1T84orbeY</a>
<br><br>
<h1>Cape Design</h1>
<hr>
<br>
The GamingCape is a conglomerate of existing, open source, BeagleBone capes all
brought together in a handheld game console form factor inspired by the
original Nintendo Gameboy. The four designs that I primarily leveraged are the
<a target="new" href="http://circuitco.com/support/index.php?title=BeagleBone_LCD3">LCD3</a>,
<a target="new" href="http://circuitco.com/support/index.php?title=BeagleBone_Audio">Audio </a>, and
<a target="new" href="http://circuitco.com/support/index.php?title=BeagleBone_Battery">Battery</a>
capes from CircuitCo and <a target="new" href="http://beagleboard.org/CapeContest/entries/Interacto/">Interacto</a> by Chris Clark.
<br>
<br>
<center>
<table>
<tr>
<td> <a target="new" href="http://i.imgur.com/ehuqfwy.png"><img src="http://i.imgur.com/tEB53DM.png"></a> </td>
<td> <a target="new" href="http://i.imgur.com/DAtoOsY.png"><img src="http://i.imgur.com/6MgR1qs.png"></a> </td>
</tr>
</table>
</center>
<center>
<table>
<tr>
<td> <a target="new" href="http://i.imgur.com/n7OqGxZ.png"><img src="http://i.imgur.com/EIJHDqT.png"></a> </td>
<td> <a target="new" href="http://i.imgur.com/yg4bmKk.png"><img src="http://i.imgur.com/bX5gkbL.png"></a> </td>
</tr>
</table>
</center>
<br>
<br>
<center><img width="700px" src="http://i.imgur.com/G9jPJKe.png" alt=""></center>
<br>
<br>
Doing the layout was a little tricky because I had to be aware of all the areas
where the case would touch the PCB. This led to some tight layouts such as the
5V power supply stuff (top layer, right below the switch). I also had to
completely re-layout the 3D gyro and accelerometer components once because I
had the keep-out layers disabled and didn't realize the space I was in was
going to be hit.
<br>
<br>
<center>
<table>
<tr>
<td> <a target="new" href="http://i.imgur.com/glyBazc.png"><img src="http://i.imgur.com/tBIrMwV.png"></a> </td>
<td> <a target="new" href="http://i.imgur.com/3q1Vahc.png"><img src="http://i.imgur.com/W53IrpW.png"></a> </td>
</tr>
</table>
</center>
<br>
<br>
<center><a target="new" href="http://i.imgur.com/tBiCI8c.jpg"><img src="http://i.imgur.com/U8vwIJS.jpg"></a></center>
<br>
<br>
<center><a target="new" href="http://i.imgur.com/PB13X2R.jpg"><img src="http://i.imgur.com/c8zK4cz.jpg"></a></center>
<br>
<br>
The schematic capture and PCB layout were done in <a target="new" href="http://www.cadsoftusa.com/">CadSoft EAGLE</a> and the PCBs were fabricated by <a target="new" href="http://silvercircuits.com/">Silver Circuits</a>
<br>
<br>
Schematics, layout, and <a target="new"
href="http://www.cadsoftusa.com/">CadSoft EAGLE</a> file can be found <a
target="new" href="https://github.com/bear24rw/gamingcape">here</a> and the
bill of materials can be found <a target="new" href="https://docs.google.com/spreadsheet/ccc?key=0Ageqs0usQsoRdFVYVWVuUVZUZWY2LVRaTkxnU3pneUE&usp=sharing">here</a>.
<br>
<br>
<h1>Case Design</h1>
<hr>
<center>
<a target="new" href="http://i.imgur.com/SYXc7pF.jpg"><img src="http://i.imgur.com/B4zCWzd.jpg"></a>
</center>
<br>
The whole system was completely modelled in Autodesk Inventor before most of
the PCB layout was even started. This was necessary as parts of the case sit
directly on the PCB and their dimensions needed to be known in order to keep out
of those areas while doing the layout. Rodney Hill of <a
target="new" href="http://logicsupply.com/">Logic Supply</a> was kind enough to provide
me with a great, accurate, model of the BeagleBone Black which was an enormous
help.
<br>
<br>
The case is designed as a stack-up of 11 laser cut pieces of Delrin. I chose
Delrin over ABS because of the two sample pieces I ordered from <a
target="new" href="http://www.mcmaster.com/#">McMaster</a> the Delrin seemed to be "more
black".
<br>
<br>
<center><a target="new" href="http://i.imgur.com/8EbyHXv.png"><img src="http://i.imgur.com/kgVTsWU.png"></a></center>
<br>
An exploded view of the stack up:
<center><img src="http://i.imgur.com/0ExsquX.png"></center>
<br>
<br>
The case is locked together by screws on either side which thread into a hex
standoffs. The standoffs are locked into place and prevented from spinning by
hex cutouts in the first 4 plates under the PCB.
<br>
<br>
<center>
<a target="new" href="http://i.imgur.com/FZ4db2A.png"><img src="http://i.imgur.com/5YYZ8qP.png"></a>
</center>
I was fortunate enough to have access to a 3D printer and was able to print the whole case and ensure
all of my dimensions were 'close enough' before I paid for it to be laser cut.
<br>
<br>
<center>
<a target="new" href="http://i.imgur.com/QVS7FyS.jpg"><img src="http://i.imgur.com/nHRdwPd.jpg"></a>
</center>
<br>
<br>
In order to reduce fabrication costs it was important to use as few different
thicknesses as possible. All pieces in my design are cut from 1/8" and 1/32"
sheets. The layouts that I sent to get cut are for 24"x12" sheets and yield
enough pieces to build two cases:
<br>
<br>
<center>
<a target="new" href="http://i.imgur.com/uunEBz3.png"><img src="http://i.imgur.com/My2FyO1.png"></a>
<br>
<a target="new" href="http://i.imgur.com/fm2RVn4.png"><img src="http://i.imgur.com/s4rPGV9.png"></a>
<br>
</center>
<br>
All the layers required for one case:
<br>
<br>
<center><a target="new" href="http://i.imgur.com/1Sm7Kro.jpg"><img src="http://i.imgur.com/hmrvrV8.jpg"></a></center>
<br>
<center>
<table>
<tr>
<td> <a target="new" href="http://i.imgur.com/ypKCo5U.jpg"><img src="http://i.imgur.com/SuzHmnf.jpg"></a> </td>
<td> <a target="new" href="http://i.imgur.com/fcyoBkB.jpg"><img src="http://i.imgur.com/ylefHEd.jpg"></a> </td>
</tr>
</table>
</center>
<br>
<br>
<center>
<a target="new" href="http://i.imgur.com/BK8nRUo.jpg"><img src="http://i.imgur.com/C93sOYI.jpg"></a>
</center>
<br>
<br>
<center>
<a target="new" href="http://i.imgur.com/NKhqh2n.jpg"><img src="http://i.imgur.com/2qvDoz0.jpg"></a>
</center>
<br>
<br>
All of the 3D design files can be found here: <a target="new" href="https://github.com/bear24rw/gamingcape/tree/master/enclosure">https://github.com/bear24rw/gamingcape/tree/master/enclosure</a>
<br>
<br>
<h1>Games</h1>
<hr>
<br>
Getting the emulators up and running on the BeagleBone proved to be a little
challenging. It seems that a lot of the Linux emulators aren't actively
maintained and wont even compile. Lucky, Gentoo maintains patches for a few of
them and I was able to use portage to fetch a patched source tree.
<br><br>
For the NES emulator, fceux, I was able to fetch, unpack, and patch the source
on my Gentoo host and then send it to the BeagleBone where I compiled it
natively. Fceux seems to work fine although I did have to patch it to center
the screen:
<br>
<a target="new" href="https://github.com/bear24rw/gamingcape_fceu/commit/ac1555d7d562ee15479374c4be103a994670e4ab">https://github.com/bear24rw/gamingcape_fceu/commit/ac1555d7d562ee15479374c4be103a994670e4ab</a>
<br><br>
For the Gameboy emulators it seemed that VisualBoyAdvance was the go-to. Again
I got a patched version from portage and tried to compile it on the BeagleBone
but it not only took ages but also ate up an enormous amount of RAM. At one
point I was using a USB flash drive as swap space. Needless to say it failed to
compile. I ended up just cross compiling it which seemed to work okay even
though I didn't really setup a proper environment and was using my hosts
systems header files.
<br><br>
For Doom I was lucky enough to find a <a target="new" href="https://github.com/aserebryakov/sdl_doom">SDL port</a> that pretty much "just worked"
which was refreshing after I tried half a dozen others which wouldn't even build.
<br><br>
For Osmose I found a <a target="new" href="http://www.raspberrypi.org/phpBB3/viewtopic.php?f=78&t=23550">forum post</a> where someone had gotten it to run on a
Raspberry PI. It pretty much "just worked" too.
<br><br>
The common issue that all the emulators share is that they are using SDL to
render and the BeagleBone doesn't really support OpenGL. This means that it's
really expensive to scale the screen up in non-integer units. You'll notice in
my video that all the emulators were running at the original systems native
resolution.
<br><br>
All the emulators that I patched and got working are hosted on my github:
<br>
<br>
<a target="new" href="https://github.com/bear24rw/gamingcape_osmose">https://github.com/bear24rw/gamingcape_osmose</a>
<br>
<a target="new" href="https://github.com/bear24rw/gamingcape_vba">https://github.com/bear24rw/gamingcape_vba</a>
<br>
<a target="new" href="https://github.com/bear24rw/gamingcape_fceu">https://github.com/bear24rw/gamingcape_fceu</a>
<br>
<a target="new" href="https://github.com/bear24rw/gamingcape_doom">https://github.com/bear24rw/gamingcape_doom</a>
<br><br></p>
<h1>Resources</h1>
<hr>
<p>
<a target="new" href="https://github.com/bear24rw/gamingcape">https://github.com/bear24rw/gamingcape</a><br>
<a target="new" href="http://hipstercircuits.com/enable-serialuarttty-on-beaglebone-black/">
http://hipstercircuits.com/enable-serialuarttty-on-beaglebone-black/
</a><br>
<a target="new" href="http://azkeller.com/blog/?p=62">
http://azkeller.com/blog/?p=62
</a>
<br>
<a target="new" href="http://wiki.beyondlogic.org/index.php/BeagleBoneBlack_Building_Kernel">
http://wiki.beyondlogic.org/index.php/BeagleBoneBlack_Building_Kernel
</a>
<br>
<a target="new" href="http://www.armhf.com/index.php/using-beaglebone-black-gpios/">
http://www.armhf.com/index.php/using-beaglebone-black-gpios/
</a>
<br>
<a target="new" href="http://beaglebone.cameon.net/home/reading-the-analog-inputs-adc">
http://beaglebone.cameon.net/home/reading-the-analog-inputs-adc
</a>
<br>
<a target="new" href="https://github.com/beagleboard/kernel/tree/3.8">
https://github.com/beagleboard/kernel/tree/3.8
</a>
<br>
<a target="new" href="http://www.eewiki.net/display/linuxonarm/BeagleBone+Black#BeagleBoneBlack-InstallBootloaders">
http://www.eewiki.net/display/linuxonarm/BeagleBone+Black#BeagleBoneBlack-InstallBootloaders
</a>
<br></p>
Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com240tag:blogger.com,1999:blog-3623515592551780770.post-37271232506713734212012-07-28T11:16:00.000-04:002012-07-30T15:30:04.726-04:00MSP430 Launchpad GamingPack<table border="0">
<tr>
<td valign="top">
<b>TEAM MEMBERS</b>
<br><br>
Max Thrun<br>
Brittany Finch<br>
Kathleen Foster<br>
<br>
<b>PROJECT DESCRIPTION</b>
<br><br>
Based on the <a target="new" href='http://excamera.com/sphinx/gameduino/'>Gameduino</a>, the GamingPack transforms your MSP430 LaunchPad into a full fledged gaming console complete with audio / video output and two Nintendo controller sockets. Just hookup your computer monitor, plug in a controller and you'll be writing games in no time.
<br><br>
<b>PROJECT FEATURES</b>
<br><br>
- 400x300 Pixel VGA output<br>
- 256 16x16 Pixel simultaneous sprite images<br>
- Up to 256 colors per sprite<br>
- 2 Nintendo (NES) controllers<br>
- Nostalgia<br>
</td>
<td valign="top">
<p style="text-align:center;"><img src="http://i.imgur.com/gmE9z.png" alt="" border="0"></p>
</td>
</tr>
</table><br>
<h1>Video</h1>
<hr>
<br>
<center>
<object width="640" height="360"><param name="movie" value="http://www.youtube.com/v/hDE0ZfmsVrw?version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/hDE0ZfmsVrw?version=3&hl=en_US" type="application/x-shockwave-flash" width="640" height="360" allowscriptaccess="always" allowfullscreen="true"></embed></object>
</center>
<br>
<a target="new" href="http://www.youtube.com/watch?v=hDE0ZfmsVrw">http://www.youtube.com/watch?v=hDE0ZfmsVrw</a>
<br><br>
<h1>Design</h1>
<hr>
<br>
The schematic capture and PCB layout were done in <a target="new" href="http://www.cadsoftusa.com/">CadSoft EAGLE</a>. The PCBs were fabricated by <a target="new" href="http://silvercircuits.com/">Silver Circuits</a>
<br><br>
<center>
<table> <tr>
<td> <a target="new" href="http://i.imgur.com/HHlrv.png"><img src="http://i.imgur.com/C0p1L.png"></a> </td>
<td> <a target="new" href="http://i.imgur.com/zQ4XT.png"><img src="http://i.imgur.com/fDMQl.png"></a> </td>
</tr></table>
<br>
<img src="http://i.imgur.com/71w43.png">
<br><br>
<img src="http://i.imgur.com/r9fbJ.png">
<br>
<br>
<br>
<img src="http://i.imgur.com/2uUXd.png" alt="">
</center>
<br>
<br>
<br>
The GamePack is designed around a Xilinx Spartan 3A 200K Gate FPGA. It implements the same sprite rendering core as the <a target="new" href="http://excamera.com/sphinx/gameduino/">Gameduino</a> and communicates to the LaunchPad via SPI. The FPGA bitstream configuration is stored on an external EEPROM which was programed using a <a target="new" href="http://www.ftdichip.com/Products/ICs/FT2232D.htm">FTDI FT2232D</a> development board and <a target="new" href="http://flashrom.org/Flashrom">Flashrom</a> in Linux. The FPGA 1.2V internal core voltage is provided by a TI TLV70212 low drop out regulator.
<br><br>
A resistor DAC provides the various voltage levels for the VGA interface and audio is achieved by passing 2 channels of digital audio through a 4KHz low pass filter. An optional SPI EEPROM can be installed to store large game data such as images and level maps. Two status LEDs indicate power and SPI data transfer to the FPGA.
<br><br>
2 Nintendo (NES) <a target="new" href="http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/nes/List/0/SortField/4/ProductID/522/Default.aspx">controller sockets</a> are included to provide a classic gaming experience. They are ideal for this project as the interface is simple and they can be easily purchased online or simply found in a box in your closet.
<br>
<br>
<br>
<br>
<br>
<center>
<a target="new" href="http://i.imgur.com/YesCN.jpg"><img src="http://i.imgur.com/fR1iX.jpg"></a>
<a target="new" href="http://i.imgur.com/3Bu7Q.jpg"><img src="http://i.imgur.com/iOmXz.jpg"></a>
<br><br>
<br><br>
<a target="new" href="http://i.imgur.com/kMz64.jpg"><img src="http://i.imgur.com/sswhx.jpg"></a><br>
With only a month and a half to complete this project designing for test was important. The GamingPack includes a 10 pin header that can plug directly into a <a target="new" href="http://www.saleae.com/logic/">Saleae Logic Analyzer</a>
<br><br>
<br><br>
<br><br>
<a target="new" href="http://i.imgur.com/8BdXx.jpg"><img src="http://i.imgur.com/bjB4S.png"></a><br>
</center>
<br><br>
<br><br>
Schematics, layout, and <a target="new" href="http://www.cadsoftusa.com/">CadSoft EAGLE</a> file can be found <a target="new" href="https://github.com/bear24rw/gamepack/tree/master/schematics">here</a>.
<br>
<br>
<h1>Basic Examples</h1>
<hr>
<p>
Several basic examples were developed to demonstrate and show off the various functionality of the GamingPack.
<br>
<br>
<center>
<table style="width:auto;">
<col width="350" />
<col width="20" />
<col width="350" />
<tr>
<td>
<img src="http://i.imgur.com/dyKTv.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/sprites_256">sprites_256</a></b> - Demonstates the hardwares ability to draw up to 256 sprites simultaneously
<br><br>
</td><td></td>
<td>
<img src="http://i.imgur.com/alvTn.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/palettes">palettes</a></b> - Shows each of the different color palette modes
<br><br>
</td>
</tr>
<tr>
<td>
<img src="http://i.imgur.com/5aNGW.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/scroll">scroll</a></b> - Randomly generated scrolling terrain to show off the hardwares ability to smoothly scroll backgroud images
<br><br>
</td><td></td>
<td>
<img src="http://i.imgur.com/9UFZN.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/rotate">rotate</a></b> - Example program showing the different rotation and mirror options
<br><br>
</td>
</tr>
<tr>
<td>
<img src="http://i.imgur.com/5D8YN.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/controllers">controllers</a></b> - Small program to show how to read the NES controllers
<br><br>
</td><td></td>
<td>
<img src="http://i.imgur.com/X0aYV.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/background">background</a></b> - Simple program showing how to display a background image
<br><br>
</td>
</tr>
<tr>
<td>
<img src="http://i.imgur.com/1DBG0.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/random_numbers">random_numbers</a></b> - Shows how to use random numbers and draw text
<br><br>
</td><td></td>
<td>
<img src="http://i.imgur.com/OaqUe.png" alt="" /></a>
<br><br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics/sprite_walking">sprite_walking</a></b> - Example showing to how create a smooth walking animation
<br><br>
</td>
</tr>
</table>
</center>
<br><br>
Source code for these basic examples: <a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/basics">https://github.com/bear24rw/gamepack/tree/master/code/examples/basics</a>
<br>
<br>
<h1>Game Examples</h1>
<hr>
<p>
The GamingPack wouldn't be a gaming pack without a few games.
<br>
<center>
<br>
<img src="https://github.com/bear24rw/gamepack/raw/master/code/examples/games/breakout/breakout.png" alt=""/>
<br>
<br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/games/breakout">Breakout / Brick Breaker</a></b>
<br>
<br>
<br>
<br>
<img src="https://github.com/bear24rw/gamepack/raw/master/code/examples/games/tetris/tetris.png" alt="">
<br>
<br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/games/tetris">Tetris</a></b>
<br>
<br>
<br>
<br>
<img src="https://github.com/bear24rw/gamepack/raw/master/code/examples/games/space_invaders/space_invaders.png" alt="">
<br>
<br>
<b><a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/games/space_invaders">Space Invaders</a></b>
<br>
<br>
</center>
<br>
<br>
Source code for the game examples: <a target="new" href="https://github.com/bear24rw/gamepack/tree/master/code/examples/games">https://github.com/bear24rw/gamepack/tree/master/code/examples/games</a>
</p>
<br></p>
<h1>Resources</h1>
<hr>
<p>
<a target="new" href="https://github.com/bear24rw/gamepack">https://github.com/bear24rw/gamepack</a><br>
<a target="new" href="http://excamera.com/sphinx/gameduino/">http://excamera.com/sphinx/gameduino</a><br>
<br></p>
Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com45tag:blogger.com,1999:blog-3623515592551780770.post-29012948283352170542011-08-26T00:10:00.008-04:002011-08-26T00:16:32.907-04:00RGB LED Coffee TableThis summer all the Co-ops at Texas Instruments were challenged with coming up with a project centered around a <a target="new" href="http://ti.com/430value">value line MSP430</a>. My group decided to build an RGB LED coffee table that pulsed visualization to music. We won 1st place!
<br />
<br />A write up of the project can be found <a target="new" href="http://e2e.ti.com/group/msp430launchpad/m/project/447779.aspx">here</a>
<br />
<br /><center>
<br /><a target="new" href="http://e2e.ti.com/group/msp430launchpad/m/project/447779.aspx"><img src="https://lh4.googleusercontent.com/-u1rAbqcEMO8/TjDwnB9TzgI/AAAAAAAABMU/UaEcguy1IzY/s400/CIMG3895.JPG" height="400" width="300" /></a></center>Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com3tag:blogger.com,1999:blog-3623515592551780770.post-85238428529366783042010-08-11T22:01:00.016-04:002013-03-26T21:56:13.618-04:00Theo Jansen Matlab SimulationMy roommate had to do a simulation of a Jansen mechanism for his kinematics class. It sounded interesting so I gave it a try. Here is what I came up with:<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/4884166878/" title="Screenshot-14-cropped by bear24rw, on Flickr"><img src="http://farm5.static.flickr.com/4073/4884166878_93557a0472.jpg" width="500" height="436" alt="Screenshot-14-cropped" /></a><br /><br /><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/lsl6992-tqA?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/lsl6992-tqA?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br /></center><br /><br /><br />Doing a simulation of a mechanical linkage was something I had never done, nor even really thought about. I initially tried to express all the angles as functions of each other but this soon became insane (this could very well be due to the fact that I am in Electrical Engineering and have never taken a kinematics course before so I had no idea what the proper equations would even look like). After trying to simplify gigantic trig equations in wolframalpha.com and getting back stuff that was disgustingly crazy I resorted to my middle school way of solving equations I don't really understand: brute force. (I used to make programs on my TI-83 to brute force single (and even double) variable equations way back in the day)<br /><br />So there was only three things I really had values for: the length of the legs, the distance between the crank and the pivot, and the angle of the crank. So say the crank is at a certain angle and you know its length, you can find the end point x,y using simple sin and cos. Now the end of the crank (node 0) needs to be connected to node 1. Node 1 is a known length off the pivot, link_9. So basically what I do is rotate link_9 around the pivot until the distance between node 1 and node 0 are extremely close to the length of link_1. I find this really hard to explain still even after trying to do it many times. Basically I brute force the angle of a bar until the tip of the bar is a certain length away from the other bar it needs to connect to (the distance which I know, since I know the length of all the legs).<br /><br />Even though this method is absolutely confusing to explain in words it is extremely modular and dead simple to implement. The code is basically the same thing over and over again just with different bars and also some angle constraints (you know link_9 will always be between 45 and 135, roughly). Adding new bars is as simple as copy and pasting and changing the names of the variables. I can literally make any mechanism this way without doing a single line of hard coded trig.<br /><br />I found the paper linked below to be extremely helpful for providing good bar lengths. All the nodes and bars in my code are named the same as those in this paper<br /><a href="http://ujdigispace.uj.ac.za:8080/dspace/bitstream/10210/1738/Numerical.pdf">http://ujdigispace.uj.ac.za:8080/dspace/bitstream/10210/1738/39/Numerical.pdf</a><br /><br /><span style="font-weight:bold;">Edit:</span> For some reason the link does not work, to find the paper google: "Numerical kinematic and kinetic analysis of a new class of twelve bar linkage for walking machines"<br /><br /><br />
<pre class="brush: matlab;" id="sh3-123">
<br />%Max Thrun<br />%Simulation of Jensen Mechanism<br /><br />close all %Clsoes windows<br />clear all %Clears all variables<br />clc %Clear command window<br /><br />%Declare variables<br /><br />crank_r = 120;<br />link_1 = 400;<br />link_2 = 389;%400;<br />link_3 = 275;<br />link_4 = 400;<br />link_5 = 275;<br />link_6 = 400;<br />link_7 = 275;<br />link_8 = 275;<br />link_9 = 275;<br />link_10 = 275;<br />link_11 = 412;%540;<br /><br />crank_x = 0;<br />crank_y = 0;<br /><br />pin_x = crank_x - (286/1);<br />pin_y = crank_y;<br /><br />node_1_x = pin_x;<br />node_1_y = 5;<br /><br />link_9_t = 0;<br /><br />link_10_t = pi;<br />link_11_t = pi;<br /><br />node_2_x = pin_x - link_9;<br />node_2_y = pin_y;<br /><br />link_8_t = 3/4*pi;<br /><br />node_3_x = pin_x;<br />node_3_y = pin_y - link_8;<br /><br />link_7_t = pi;<br /><br />node_4_x = pin_x - link_7;<br />node_4_y = pin_y - link_3;<br /><br />link_5_t = 3/4*pi;<br /><br />node_5_y = pin_y - link_8 - link_5;<br />node_5_x = pin_x;<br /><br />node_6_y = node_5_y;<br />node_6_x = node_5_x;<br /><br />axis([-300 300 -300 300]);<br />grid on %Display grid on plot<br />xlabel('real axis'); %Give the xlabel<br />ylabel('imag axis'); %Give the ylabel<br />title('Example 1'); %Give the title of the plot<br /><br /><br />avi = moviein((8*pi+pi/2)*5);<br /><br />%Animation<br />figure(3)<br /><br />i=0;<br /><br />x = [];<br />y = [];<br /><br />for t=0:0.1:8*pi+pi/2+pi;<br /><br /> i = i + 1;<br /><br /> node_0_x = crank_x + crank_r*cos(t);<br /> node_0_y = crank_y + crank_r*sin(t);<br /><br /> <br /> %<br /> % NODE 1<br /> %<br /><br /> dist = 10000000;<br /> <br /> for link_9_t=0:0.02:pi;<br /> node_1_x = pin_x + link_9*cos(link_9_t);<br /> node_1_y = pin_y + link_9*sin(link_9_t);<br /><br /> dist_tmp = sqrt((node_0_x-node_1_x)^2+(node_0_y-node_1_y)^2);<br /><br /> diff = abs(dist_tmp - link_1);<br /><br /> if (diff < dist)<br /> dist = diff;<br /> theta = link_9_t;<br /> %fprintf('New theta: %d Diff: %d\n', theta, diff);<br /> end<br /> end<br /> <br /> link_9_t = theta;<br /> <br /> node_1_x = pin_x + link_9*cos(link_9_t);<br /> node_1_y = pin_y + link_9*sin(link_9_t);<br /> <br /> <br /> %<br /> % NODE 2<br /> %<br /> <br /> dist = 10000000;<br /> <br /> for link_10_t=.75*pi:0.02:1.5*pi;<br /> node_2_x = pin_x + link_10*cos(link_10_t);<br /> node_2_y = pin_y + link_10*sin(link_10_t);<br /> <br /> dist_tmp = sqrt((node_2_x-node_1_x)^2+(node_2_y-node_1_y)^2);<br /> <br /> diff = abs(dist_tmp - link_2);<br /> <br /> if (diff < dist)<br /> dist = diff;<br /> theta = link_10_t;<br /> %fprintf('New theta: %d Diff: %d\n', theta, diff);<br /> end<br /> end<br /> <br /> link_10_t = theta;<br /> <br /> node_2_x = pin_x + link_10*cos(link_10_t);<br /> node_2_y = pin_y + link_10*sin(link_10_t);<br /> <br /> %<br /> % NODE 3<br /> %<br /> <br /> dist = 10000000;<br /> <br /> for link_8_t=pi:0.02:2*pi;<br /> node_3_x = pin_x + link_8*cos(link_8_t);<br /> node_3_y = pin_y + link_8*sin(link_8_t);<br /> <br /> dist_tmp = sqrt((node_0_x-node_3_x)^2+(node_0_y-node_3_y)^2);<br /> <br /> diff = abs(dist_tmp - link_6);<br /> <br /> if (diff < dist)<br /> dist = diff;<br /> theta = link_8_t;<br /> end<br /> end<br /> <br /> link_8_t = theta;<br /> <br /> node_3_x = pin_x + link_8*cos(link_8_t);<br /> node_3_y = pin_y + link_8*sin(link_8_t);<br /> <br /> %<br /> % NODE 4<br /> %<br /> <br /> dist = 10000000;<br /> <br /> for link_7_t=.75*pi:0.02:1.5*pi;<br /> node_4_x = node_3_x + link_7*cos(link_7_t);<br /> node_4_y = node_3_y + link_7*sin(link_7_t);<br /> <br /> dist_tmp = sqrt((node_4_x-node_2_x)^2+(node_4_y-node_2_y)^2);<br /> <br /> diff = abs(dist_tmp - link_3);<br /> <br /> if (diff < dist)<br /> dist = diff;<br /> theta = link_7_t;<br /> end<br /> end<br /> <br /> link_7_t = theta;<br /> <br /> node_4_x = node_3_x + link_7*cos(link_7_t);<br /> node_4_y = node_3_y + link_7*sin(link_7_t);<br /> <br /> <br /> %<br /> % NODE 5<br /> %<br /> <br /> dist = 10000000;<br /> <br /> for link_5_t=pi:0.02:2*pi;<br /> node_5_x = node_3_x + link_5*cos(link_5_t);<br /> node_5_y = node_3_y + link_5*sin(link_5_t);<br /> <br /> dist_tmp = sqrt((node_4_x-node_5_x)^2+(node_4_y-node_5_y)^2);<br /> <br /> diff = abs(dist_tmp - link_4);<br /> <br /> if (diff < dist)<br /> dist = diff;<br /> theta = link_5_t;<br /> %fprintf('New theta: %d Diff: %d\n', theta, diff);<br /> end<br /> end<br /><br /> link_5_t = theta;<br /><br /> node_5_x = node_3_x + link_5*cos(link_5_t);<br /> node_5_y = node_3_y + link_5*sin(link_5_t);<br /><br /> node_6_x = node_3_x + link_11*cos(link_5_t);<br /> node_6_y = node_3_y + link_11*sin(link_5_t);<br /><br /> x(end+1) = node_6_x;<br /> y(end+1) = node_6_y;<br /><br /> %<br /> % DRAW<br /> %<br /><br /> plot([crank_x pin_x], [crank_y pin_y],'black','linewidth',4); hold on % crank to pin<br /> plot([crank_x node_0_x], [crank_y node_0_y],'r','linewidth',4); hold on % crank<br /><br /> plot([node_0_x node_1_x], [node_0_y node_1_y],'b','linewidth',4); % link_1<br /> plot([pin_x node_1_x], [pin_y node_1_y],'g','linewidth',4); % link_9<br /><br /> plot([pin_x node_2_x], [pin_y node_2_y],'g','linewidth', 4); % link_10<br /> plot([node_1_x node_2_x], [node_1_y node_2_y],'g','linewidth', 4); % link_2<br /><br /> plot([node_0_x node_3_x], [node_0_y node_3_y],'b','linewidth',4); % link_6<br /> plot([pin_x node_3_x], [pin_y node_3_y],'r','linewidth',4); % link_8<br /><br /> plot([node_3_x node_4_x], [node_3_y node_4_y],'g','linewidth', 4); % link_7<br /> plot([node_2_x node_4_x], [node_2_y node_4_y],'r','linewidth', 4); % link_3<br /><br /> plot([node_3_x node_5_x], [node_3_y node_5_y],'r','linewidth', 4); % link_5<br /> plot([node_4_x node_5_x], [node_4_y node_5_y],'b','linewidth', 4); % link_4<br /><br /> plot([node_3_x node_6_x], [node_3_y node_6_y],'b','linewidth', 4); % link_5<br /><br /> plot(x,y);<br /><br /> hold off %So next plot will erase the current plot<br /> axis([-900 600 -900 600]);<br /> %pause(0.001) %Stop execution for 0.1 sec so that the animation can be seen<br /> avi(i) = getframe(gca);<br />end<br /><br /><br /><br />movie2avi(avi,'jansen.avi','compression','cinepak') % or cinepak, indeo5<br /></pre>
<script type="text/javascript">
// code snippet is loaded here, use SH3 API to highlight it
var element = document.getElementById('sh3-123');
SyntaxHighlighter.highlight(undefined, element);
</script>Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com2tag:blogger.com,1999:blog-3623515592551780770.post-43072256992027291382009-11-14T16:48:00.024-05:002010-08-11T22:47:03.370-04:00Omegle.com Man In The Middle AttackThe other day my friend showed me this site <a href="http://omegle.com">Omegle</a>. It's a pretty cool site that anonymously pairs you up with a 'stranger' and you chat 1 on 1 with the ability to disconnect and find a new 'stranger' at any time. It's surprisingly addicting and fun. It claims to be completely anonymous and so to check this I decided to fire up <a href="http://www.wireshark.org/">Wireshark</a> and take a look at what information was getting passed to the server. I was surprised to find the method of communication extremely simple and completely unencrypted. When you connect to a person the process looks like this:<br /><code><br /><span style="font-weight:bold;">You:</span> POST omegle.com/start<br /><span style="font-weight:bold;">Omg:</span> HTTP "123456" <span style="font-weight:bold;"><-- random 6 digit 'username' (a-z A-Z 0-9 _ -)</span><br /><span style="font-weight:bold;">You:</span> POST omegle.com/events?id=123456<br /><span style="font-weight:bold;">Omg:</span> HTTP [["connected"]]<br /><span style="font-weight:bold;">You:</span> POST omegle.com/send?msg=hello&id=123456<br /><span style="font-weight:bold;">Omg:</span> HTTP win <span style="font-weight:bold;"><-- funny</span><br /><span style="font-weight:bold;">You:</span> POST omegle.com/events?id=123456<br /><span style="font-weight:bold;">Omg:</span> HTTP [["gotMessage", "hey"]] <span style="font-weight:bold;"><-- message from other person</span><br />...<br /><span style="font-weight:bold;">You:</span> POST omegle.com/disconnect?id=123456 <span style="font-weight:bold;"><-- quit the chat</span><br /></code><br /><br />Seeing this immediately sparked some thought. Can I request events for other users? Can I send messages to other users? Can I disconnect other users? It seemed all you needed to do was post the command with the user id you wanted to receive events for. As it turns out its almost even better. If you post for events using someone elses user id it will "implode" their chat:<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/4103478151/" title="Screenshot by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2491/4103478151_554efd56bd_o.png" width="466" height="62" alt="Screenshot" /></a></center><br /><br />Whats better is that the other person is still connected and they have no idea that their 'stranger' has been imploded. Now you can keep talking to the other person and they have no idea what just happened.<br /><br />There is one major problem with this however. According to:<br /><br />http://omegle.com/count<br /><br />there are on average only about 3k users online at a given time, but the number of possible user ids are<br /><br />(26+26+10+1+1)^6 = 68,719,476,736<br /><br />That is a terrible chance of you finding someone quickly. I actually started making a brute forcer (omegle_brute_force.py) but quickly realized that this was an ill fated attempted.<br /><br />So if you cant find the users, why not have the users come to you? I realized that Omegle would be prime for a classic <a href="http://en.wikipedia.org/wiki/Man-in-the-middle_attack">man in the middle attack</a>. The idea is super simple. I would connect to two strangers just like normal, but instead of me talking to them they would talk to each other <span style="font-weight:bold;">through</span> me. As long as I don't inject any messages or anything weird they should have no idea that I'm even there. Here is how the program looks:<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/4103393791/" title="omegle by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2625/4103393791_c83703f5fe.jpg" width="430" height="336" alt="omegle" /></a></center><br /><br />As you can see I am having a legit connection to both client 1 and client 2, but I am transparently passing their messages right through me to the other person.<br /><br />Doing this was kinda tricky. Whenever you POST for events it blocks until the read is fulfilled. This means that with a single threaded program each person would have to take turns talking since the program would block every time I polled for their messages. Even most two threaded setups have the same problem. The solution I came up with I feel works pretty well. There are four total threads:<br /><br />1) Sending to client 1<br />2) Receiving from client 1<br />3) Sending to client 2<br />4) Receiving from client 2<br /><br />Every time the receive thread gets a message it queues it into a stack, so that the sending thread can retrieve the message at its leisure. The result? It doesn't matter if a POST blocks because the sender thread can still work through the queue and the other threads can still send and receive messages.<br /><br />A classic man in the middle attack:<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/4104149908/" title="Screenshot-2 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2527/4104149908_cedf54478d.jpg" width="500" height="420" alt="Screenshot-2" /></a></center><br />This has some interesting possibilities. I can send messages to one of the clients at the others behalf and the person will have no idea that I sent it. Also what about connecting more then 2 people together? There is no reason I couldn't connect multiple people together in a chat and maybe even append a user tag to each of their messages.<br /><br />Omegle is a pretty interesting site, and you gotta hand it to <a href="http://omegler.blogspot.com/">Leif K-Brooks</a> for (apparently) single handedly making such a propular site at only 18. I hope that he can implement some needed security to Omegle to prevent this kind of attack in the future.<br /><br />Download my programs <span style="font-weight:bold;"><a href="http://ucfilespace.uc.edu/~thrunml/omegle.zip">here</a> [<a href="http://bear24rw.gotdns.com:40/omegle.zip">mirror</a>]</span>.<br /><br /><span style="font-weight:bold;">omegle_man_in_middle.py</span> - program described above<br /><span style="font-weight:bold;">omegle_brute_force.py</span> - attempts to guess user ids and post for events<br /><span style="font-weight:bold;">omegle_class.py</span> - generic class for interacting with omegle<br /><span style="font-weight:bold;">omegle_connect_view.py</span> - connect to omegle and posts for events<br /><span style="font-weight:bold;">omegle_multi_connect.py</span> - connects to multiple people at once. proof of concept that multi connections can be made<br /><span style="font-weight:bold;">omegle_send.py</span> - send messages using a user id<br /><br />EDIT:<br /><br />Found another omegle man in the middle attack written in perl [<a href="http://thinkwaitfast.blogspot.com/2009/09/i-should-really-get-job-soon.html">here</a>]Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com31tag:blogger.com,1999:blog-3623515592551780770.post-2490595688147711172009-11-08T17:54:00.046-05:002013-03-26T21:55:49.444-04:00PS3 Eye Driver Patch<span style="font-weight:bold;">Update:</span> A lot has happened since this was posted. The main line kernel now includes most of these fixes!
<br />
<br />I've had a <a href="http://en.wikipedia.org/wiki/PlayStation_Eye">PS3 Eye</a> lying around for a while but I hadn't gotten around to using it because when it first came out there were no drivers for it so it sat in my closet for almost a year. I decided to check out the current state of the PS3 Eye in Linux and was happy to find that there is now support in the 2.6.31 kernel.
<br />
<br />What I was disappointed to find out though was that there was no ability to select frame rate or control a lot of the image quality. Lucky there is <a href="http://kaswy.free.fr/?q=en/node/54">patch</a> that allows selection of frames rates all the way up to 125 fps and some image quality controls. I patched my driver and tried it out but found that the color of the image was way off and none of the given controls could fix this.
<br />
<br />I decided to do some research and add support for brightness, contrast, hue, and auto white balance.
<br />
<br /><center><a href="http://www.flickr.com/photos/bear24rw/4086925303/" title="before by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2592/4086925303_8104630ae6.jpg" width="500" height="230" alt="before" /></a><br><i>With Kaswy's Patch</i></center>
<br />
<br /><center><a href="http://www.flickr.com/photos/bear24rw/4087682316/" title="driver by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2713/4087682316_2eb1f2237d.jpg" width="500" height="213" alt="driver" /></a><br><i>With my patch</i></center>
<br />
<br />I'm going to just supply the whole .c file instead of a patch since they are almost the same size. Applying the patch is almost the same as Kaswy's
<br />
<br />To apply:
<br />
<br />Install necessary packages:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ sudo apt-get install kernel-package libncurses5-dev wget bzip2 build-essential linux-source</pre>
<br />
<br />Extract kernel source code:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ sudo su
<br />$ cd /usr/src
<br />$ tar --bzip2 -xvf linux-source-2.6.(your version).tar.bz2
<br />$ ln -s linux-source-2.6.(your version) linux
<br /></pre>
<br />
<br />Replace driver:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ cd linux
<br />$ wget ucfilespace.uc.edu/~thrunml/ov534.c
<br />$ rm drivers/media/video/gspca/ov534.c
<br />$ mv ov534.c drivers/media/video/gspca/
<br /></pre>
<br />
<br />Recompile driver:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ cp /usr/src/linux-headers-$(uname -r)/Module.symvers /usr/src/linux
<br />$ make oldconfig
<br />$ make modules_prepare
<br />$ make SUBDIRS=drivers/media/video/gspca modules
<br /></pre>
<br />
<br />Install new driver:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ cp drivers/media/video/gspca/gspca_ov534.ko /lib/modules/$(uname -r)/kernel/drivers/media/video/gspca
<br />$ depmod
<br /></pre>
<br />
<br />Check to make sure it installed:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ modinfo gspca-ov534
<br />filename: /lib/modules/2.6.31-14-generic/kernel/drivers/media/video/gspca/gspca_ov534.ko
<br />license: GPL
<br />description: GSPCA/OV534 USB Camera Driver(kaswy mod for MT use V0.5 / <b>bear24rw patch V0.1</b>)
<br />author: Antonio Ospite <ospite@studenti.unina.it>
<br />srcversion: 1F87820D2B0705822B61A16
<br />alias: usb:v1415p2000d*dc*dsc*dp*ic*isc*ip*
<br />depends: gspca_main
<br />vermagic: 2.6.31.4 SMP mod_unload modversions
<br />parm: videomode: = xx //Set the videomode(see doc) (int)
<br />parm: autogain: = [0|1] //Autogain (agc,aec,awb) (bool)
<br />parm: gain: = [0..63] //main gain (int)
<br />parm: awb: = [0|1] //Auto White Balance (bool)
<br />parm: exposure: = [0..255] //Exposure (int)
<br />parm: brightness: = [0..255] //Brightness (int)
<br />parm: contrast: = [0..255] //Contrast (int)
<br />parm: redblc: = [0..255] //Red Balance (int)
<br />parm: blueblc: = [0..255] //Blue Balance (int)
<br />parm: hue: = [0..255] //Hue (int)
<br />parm: sharpness: = [0..63] //Sharpness (int)
<br />parm: vflip: = [0|1] //Vertical flip (bool)
<br />parm: hflip: = [0|1] //Horizontal mirror (bool)
<br /></pre>
<br />
<br />Now we can remove the one currently in use and load our new one:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ modprobe -r gspca-ov534
<br />$ modprobe gspca-ov534 videomode=10
<br /></pre>
<br />
<br />The available video modes are:
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />00: 640x480@15
<br />01: 640x480@30
<br />02: 640x480@40
<br />03: 640x480@50
<br />04: 640x480@60
<br />10: 320x240@30
<br />11: 320x240@40
<br />12: 320x240@50
<br />13: 320x240@60
<br />14: 320x240@75
<br />15: 320x240@100
<br />16: 320x240@125
<br /></pre>
<br />
<br />You can adjust the image using guvcview
<br /><pre class="brush: text; toolbar: false; gutter: false;">
<br />$ sudo apt-get install guvcview
<br />$ guvcview
<br /></pre>
<br />
<br />Hopefully the main line driver gets patched soon with these enhancements.Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com327tag:blogger.com,1999:blog-3623515592551780770.post-39281324418562566692009-10-01T12:36:00.034-04:002010-08-11T23:32:49.971-04:00LED MatrixLast year in one of my classes we were required to make an 'artefact' or something that reflects the interests of the class. Most people make posters and the past two quarters that's what my class did too. Posters however are static, usually boring, and don't reflect that fact that everyone in the class is an EE major. We decided posters are for noobs and decided to go off the wall a little and make an LED matrix display. Lucky one of my friends John Wathen already had this beautiful 16x24 Green SMD LED matrix that he built back in high school.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3574348952/" title="P5271009 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3652/3574348952_c85af6167f.jpg" width="500" height="375" alt="P5271009" /></a></center><br /><center><a href="http://www.flickr.com/photos/bear24rw/3573544803/" title="P5271014 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2452/3573544803_03000843fc.jpg" width="500" height="375" alt="P5271014" /></a></center><br />What we didn't have however was a driver for it. The driver we choose to design was highly inspired from <a href="http://www.instructables.com/id/LED-matrix-using-shift-registers/">this one</a>. The basic idea is that you use shift registers to sink the columns and a line driver of some sort to source the rows (we chose to use a <a href="http://en.wikipedia.org/wiki/Darlington_transistor">Darlington array</a>). <br /><br />There where a lot of changes from the Instructables design that that we had to make however. The matrix in the Instructables was a lot smaller than ours and used 8 IO lines to drive each row. Since our matrix has 16 rows this was completely infeasible using just an <a href="http://www.atmel.com/dyn/products/Product_card.asp?part_id=3303">ATMega168</a>. To solve this issue we choose to use a 4:16 <a href="http://en.wikipedia.org/wiki/Multiplexer">de-mux</a> to control all sixteen rows with only 4 IO pins. The de-mux combined with two 8 channel Darlington arrays provided the perfect interface to control all 16 rows. To sink the columns we choose to string three 8 Output <a href="http://en.wikipedia.org/wiki/Shift_register">shift registers</a>. Each shift register is rated to handle the current of the 8 LEDs that could possibly be on at one time.<br /><br />Some other features that we included on the driver board were 3 green LEDs, 3 push buttons, ISP header, TTL header. When all was said and done we ended up the the schematic shown below.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3574373426/" title="rev_4 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2447/3574373426_503851b4e9.jpg" width="500" height="256" alt="rev_4" /></a></center><br /><br />I know, you are probably looking at that and thinking, "Why are all the shift register outputs criss-crossed??". The reason for doing this is because the output pins on the chip are not exactly in a row so to assist in board layout the pins had to be crossed and mixed up so that the board layout would be nice. It's much easier to change the order of the columns in the program then it is on the board layout (in my opinion). We didn't want to etch a double sided board so a lot of effort went into laying as much of the circuit out on a single side. There were a few paths that could not be routed and were just jumped with wire (you'll see in picture below).<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3971619171/" title="board by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3528/3971619171_aefd2ebefe.jpg" width="500" height="404" alt="board" /></a></center><br /><br />Notice how there are a bunch of air-wires (yellow lines) that I couldn't figure out how to route, they are manually jumped when the board is put together.<br /><br />To etch the board we printed out the board layout 1:1 scale on glossy photo paper, it was than ironed onto a piece of copper clad. The idea is that the toner will stick to the copper clad and when the board is dipped in acid the acid will eat away at everything but the traces, since they are coved by the toner. I'm definitely not an expert in this area so ask John Wathen more about the process, he is basically a pro.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3575123202/" title="DSC_9192 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3321/3575123202_5d0d4d3b7a.jpg" width="500" height="332" alt="DSC_9192" /></a><br /><i>Etching the board in acid</i></center><br /><center><a href="http://www.flickr.com/photos/bear24rw/3575122950/" title="DSC_9193 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3354/3575122950_15d5263874.jpg" width="500" height="332" alt="DSC_9193" /></a><br /><i>Checking to see if its ready to be scrubbed</i></center><br /><center><a href="http://www.flickr.com/photos/bear24rw/3575123848/" title="DSC_9199 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3595/3575123848_e3d2ddf01a.jpg" width="500" height="332" alt="DSC_9199" /></a><br /><i>Dirty traces</i></center><br /><center><a href="http://www.flickr.com/photos/bear24rw/3575124082/" title="DSC_9205 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2431/3575124082_465d0bd566.jpg" width="500" height="332" alt="DSC_9205" /></a><br /><i>Scrubbing off the rest of the toner</i></center><br /><center><a href="http://www.flickr.com/photos/bear24rw/3575124516/" title="DSC_9217 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3624/3575124516_a745213afb.jpg" width="500" height="332" alt="DSC_9217" /></a><br /><i>The beautiful result, nice and shiny</i></center><br />Now, let me just tell you that we did this in a public bathroom at school. So there were three guys in a bathroom with latex gloves, a camera, and tub of some green liquid. Trust me we got some weird looks.<br /><br />The next step was to drill all the holes. I don't remember exactly how many there were (John might) but there were a lot.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3574352632/" title="IMAG0015 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3648/3574352632_aba3c639f7.jpg" width="500" height="375" alt="IMAG0015" /></a></center><br /><br />After all the holes were drilled John soldered it all up.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3574349530/" title="P5271010 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3559/3574349530_efda24867a.jpg" width="500" height="375" alt="P5271010" /></a></center><br /><center><a href="http://www.flickr.com/photos/bear24rw/3574349852/" title="P5271011 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3658/3574349852_3a86d9270f.jpg" width="500" height="375" alt="P5271011" /></a></center><br /><br />And the result!<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3573545651/" title="P5271017 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3576/3573545651_5a0196498d.jpg" width="500" height="375" alt="P5271017" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3574351302/" title="P5271015 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3322/3574351302_6a0e6b5ecf.jpg" width="500" height="375" alt="P5271015" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3574350634/" title="P5271013 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2423/3574350634_ac9f937a3c.jpg" width="500" height="375" alt="P5271013" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3573542359/" title="P5271008 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3593/3573542359_ea9cf699a6.jpg" width="500" height="375" alt="P5271008" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3574347398/" title="P5271007 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3410/3574347398_0e0d004da3.jpg" width="500" height="375" alt="P5271007" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3573540181/" title="P5271004 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3600/3573540181_d861a7ddfa.jpg" width="500" height="375" alt="P5271004" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3573540987/" title="P5271005 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3344/3573540987_a7371e6016.jpg" width="375" height="500" alt="P5271005" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3573541779/" title="P5271006 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3564/3573541779_4f6ea4c3b9.jpg" width="375" height="500" alt="P5271006" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3573546271/" title="P5271019 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2465/3573546271_f5ef0f8d60.jpg" width="375" height="500" alt="P5271019" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3573544803/" title="P5271014 by bear24rw, on Flickr"><img src="http://farm3.static.flickr.com/2452/3573544803_03000843fc.jpg" width="500" height="375" alt="P5271014" /></a><br /></center><br /><br />Now that the board was finished it was the moment of truth.<br /><br />Adam Steele lent me his programmer. Plugged it into my Xbuntu box, apt-get installed the avr tool-kit and the programmer was immediately recognized (NICE!). Flashed a simple program to flash the status LEDs and low and behold, IT WORKED! Next up, everything else. I started by modifying the program that the Intructables provided but quickly got frustrated by the way it worked. It treated each column as a bit in a byte and the rows as a byte, this made it extremely hard to visualize outputs to the display. Also I was using a de-mux and had 24 columns which the code did not easy support. So what do you do in this situation? REWRITE. <br /><br />An outline of how the new code works:<br /><br />The value for each pixel is stored in a 2D array 16x24, want to set the top left pixel? buffer[0][0] = 1; simple as that, much easier than dealing with it as an array of bytes. Okay, so it takes up more memory but IMO it is completely worth every bit (pun intended). <br /><br />The code starts by initializing the ports (pull-ups, in/out, etc) then it initializes timer1. To be completely honest the fill value for the timer was chosen by adjusting value, flashing, seeing if the refresh rate was noticeable. We ended up with OCR1A = 0x012C; as a good value.<br /><br />The code then falls into an While(1) where it sequentially calls functions to draw stuff on the screen, for example:<br /><br /><script type="syntaxhighlighter" class="brush: c"><![CDATA[<br />Spiral(5, 0);<br /><br />Tunnel(1);<br />Tunnel(0);<br />Tunnel(1);<br /><br />Erase_Rider(RIGHT, 10);<br />Fill(LEFT, 10);<br /><br />Shift(UP, 16, 50);<br /><br />Erase_Rider(DOWN, 10);<br />Erase_Rider(UP, 10);<br />]]></script><br />All the high level functions (tunnel, spiral, shift, etc..) write to 'buffer'. When the timer interrupt goes off it calls the function shift_int() which reorders the columns into 'buffer_2' and then shifts them out to the shift registers. It then calls shift_mux() which jumps to the next row. So essentially we have a double buffered display.<br /><br />Once all the low level code was done it was all fun and games. It was really nice being at the point were all you had to work with is a 2D array. We ended up with the high level functions:<br /><br /><script type="syntaxhighlighter" class="brush: c"><![CDATA[<br />void Delay_ms(int cnt)<br />void Clear_Display(void)<br />void Fill_Display(void)<br />void Flash_Display(u8 cycles, u8 speed)<br />void Col(u8 col, u8 state)<br />void Row(u8 row, u8 state)<br />void Fill_Col(u8 col, u8 dir, u8 speed, u8 state)<br />void Fill_Row(u8 row, u8 dir, u8 speed, u8 state)<br />void Fill(u8 dir, u8 speed)<br />void Invert_Col(u8 col)<br />void Invert_Row(u8 row)<br />void Invert_Fill(u8 dir, u8 speed) <br />void Erase_Rider(u8 dir, u8 speed)<br />void Spiral(u8 speed, u8 state)<br />void Tunnel(u8 state)<br />void Invert(u8 count, u8 speed)<br />void Draw_Line(u8 x1, u8 y1, u8 x2, u8 y2, u8 state)<br />void Shift(u8 dir, u8 amount, u8 speed)<br />void Scroll_Char (char myChar, u8 pos, u8 dir, u8 speed)<br />void Box(u8 speed, u8 dir, u8 state) <br />void Grid(u8 speed, u8 state)<br />]]></script><br /><br />It is so incredibly easy to make new functions when you are just manipulating a 2D array.<br /><br />A warning before you watch the videos, they were taken with a crappy point n shoot camera so they look incredibly choppy. In real life the display is incredibly fluid and smooth. The videos do it zero justice.<br /><center><br /><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/VOljZt9pW5g&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/VOljZt9pW5g&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br /><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/zxe39Q0XnrA&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/zxe39Q0XnrA&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br /></center><br /><a href="https://ucfilespace.uc.edu/~thrunml/led_board.zip">Eagle Files & Source Code</a> [<a href="http://bear24rw.gotdns.com:40/led_board.zip">Mirror</a>]<br />If you re-use the design or source (which I encourage you to do) please give credit where credit is due. Also note that the entire code was literally written in a one night programming marathon since we were extremely pressed (read: it was due the next day), so there are still many bugs. Also I take no responsibility for any damage if you use my design and code (had to put a disclaimer ;))<br /><br />Any questions regarding the design or the source code should be directed at me bear24rw . gmail.com<br />Any questions regarding the construction of the board should be directed at John Wathen jmwathen . gmail.comMax Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com28tag:blogger.com,1999:blog-3623515592551780770.post-21377497161905988992008-12-26T13:08:00.008-05:002008-12-26T14:11:23.485-05:00RFID Door UnlockerTodays world is all about efficiency, this includes getting into your dorm room. Inspired by other door unlocking projects found around the Internet, especially the <a href="http://www.engadget.com/2006/10/21/mit-student-hacks-his-dorm-room-door-lock/" target="new">MIT one</a> that is practically famous, I decided it was time to outfit my own door with an RFID unlocker.<br /><br />Our dorms offer the unique benefit of having full length mirrors on the doors so I figured that suction cups would be the best way to go as they were easy to apply, remove and are non marking.<br /><br />Being that I already had a <a href="http://www.parallax.com/Store/Microcontrollers/BASICStampProgrammingKits/tabid/136/CategoryID/11/List/0/SortField/0/Level/a/ProductID/294/Default.aspx">Basic Stamp</a>, Parallax's <a href="http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/RFID/List/1/ProductID/114/Default.aspx?SortField=ProductName%2cProductName">RFID reader</a> seemed to be the obvious choice as it was the cheapest reader I could find and already had example code written for it.<br /><br />My initial plan involved just a servo, standoffs, and suction cups...<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3036473344/" target="new" title="door_lock by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3039/3036473344_337f9033ab.jpg" alt="door_lock" border="0" height="500" width="344" /></a></center><br /><br />Modeled in Autodesk Inventor...<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3036473518/" target="new" title="render_1 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3047/3036473518_32251d8445.jpg" alt="render_1" border="0" height="375" width="500" /></a></center><br /><br />After some of the parts came in I set up a quick prototype to make sure the servo was even strong enough to flip the latch and that I could read the tag through the door. To attach the servo horn to the latch I tied a piece of string to the horn and taped it to the top of the latch, this is how it done in the final version as well. The reason for using string is so that you could still easily unlock the door with the key, it would just put slack in the string. The only fault with this method is that you cannot use the RFID tag to lock the door.<br /><br /><center><object height="344" width="425"><param name="movie" value="http://www.youtube.com/v/mOO9eL6x8pg&hl=en&fs=1"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/mOO9eL6x8pg&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="344" width="425"></embed></object></center><br />I quickly realized that I had given no thought as to how I was going to mount all the electronics. As a result the servo remained like that on my door for weeks. As I was cleaning my desk one day I found this box and instantly realized that it was perfect for the door unlocker.<br /><br />Another quick mockup in Invetor to see if everything fit, and it did perectly..<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3040794161/" target="new" title="render_4 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3186/3040794161_eed27a5c5e.jpg" alt="render_4" border="0" height="375" width="500" /></a></center><br /><br />Ordered some 6-32 screws and nuts from <a href="http://www.mcmaster.com/">McMaster</a> and started assembly.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3036474442/" target="new" title="PB120691 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3204/3036474442_f72043bdac.jpg" alt="PB120691" border="0" height="500" width="375" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3036474114/" target="new" title="PB120690 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3213/3036474114_459e5c5474.jpg" alt="PB120690" border="0" height="500" width="375" /></a></center><br /><br />The servo fits perfectly height wise, it sits against the bottom of the base when closed. Now that I had the servo and RFID reader mounted I needed to get some holes drilled for the suction cups and basic stamp. Due to my <del>procrastination</del> studying the project sat on my desk for a week.<br /><br />I finally got around to drilling the holes and mounting the whole thing...<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3036476094/" title="PB160699 by bear24rw, on Flickr" target="new"><img src="http://farm4.static.flickr.com/3176/3036476094_0a94c137c0.jpg" alt="PB160699" border="0" height="500" width="375" /></a><br /><br /><a href="http://www.flickr.com/photos/bear24rw/3035641697/" target="new" title="PB160700 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3211/3035641697_28f36f8af4.jpg" alt="PB160700" border="0" height="500" width="375" /></a></center><br />I used paper under the basic stamp to insulate it from the metal box.<br /><br />The assembly did not go without problems, however.<br /><br />The first major problem was when I went to reassemble the box after I put on the suction cups. I didn't take into consideration that the nuts would get in the way of the box closing. As you can see in the pictures I had to snip spaces in the box where the nuts were so the box would be able to close all the way.<br /><br />The second major problem was a weird one. The RFID reader was originally going to be mounted on the inside of the box. This box was perfect because the front was plastic and didn't interfere with the reader. The problem was, when I closed everything up in the box the range of the reader was almost cut in half and I couldn't read the tag through the door. However, if I pulled the box apart (like it is being shown in the above pictures) the tag could be read through the door. My best guess is electrical noise is causing this but I honestly did not want to spend any longer on this project, and there seemed little alternatives. I ended up just mounting the reader on the outside of the box. It does not really make any difference other then looks.Here is how it looks when it is all up and running.<br /><br /><center><a href="http://www.flickr.com/photos/bear24rw/3036474834/" target="new" title="PB150694 by bear24rw, on Flickr"><img src="http://farm4.static.flickr.com/3236/3036474834_25907ddb65.jpg" alt="PB150694" border="0" height="500" width="375" /></a><br /><br /><object height="344" width="425"><param name="movie" value="http://www.youtube.com/v/zbAy0aqiAsU&hl=en&fs=1"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/zbAy0aqiAsU&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="344" width="425"></embed></object></center><br /><br />The basic stamp program can be downloaded <a href="http://homepages.uc.edu/%7Ethrunml/rfid/rfid_unlocker.BS2">here</a>Max Thrunhttp://www.blogger.com/profile/18216963066514872707noreply@blogger.com41