Thursday, September 24, 2009

Conway's Game of Life on an Arduino

I'm finally back in Davis, but unfortunately one of the first things I did once I got here was come down with a miserable head cold. I therefore took the opportunity to play with my Arduino micro-controller, which I haven't really gotten a big chance to mess around with for a while.

For those who don't know, an Arduino is a very small computer, except it's designed to be hooked up to other basic electronics, i.e. LEDs and switches, instead of computer monitors and keyboards (which are actually possible). Last year I went down to Halted, and splurged on a 16x2 alphanumeric liquid crystal display for it, so I can quite easily display text on it, at the cost of 6 of the 14 I/O pins.

HD44780 based screens, like mine, have a pretty complete character set (page 17-18). On the off chance you need a few more specific characters that they don't happen to have, they have the ability for you to program 8 custom characters, simply by feeding it the 5x8 bitmap of the character. This is useful for when you want something iconic like a smiley face, but others have gotten more creative by using them to make bar graphs, etc, since you can program anything you want into it.


The idea came to me: with 8 custom characters, you could essentially make a 20x16 matrix display, which would be perfect for the Game of Life. 100 lines of C code later, I had a working Life engine. Another 60 to add extra features like checking for when it's in a steady state, and this is what I end up with:


How I store the world isn't especially elegant. I use an entire byte for each grid, where I really only need two bits for the basic engine (current state and the state for the next step). I thought about doing all the crazy bit packing needed to access each individual bit, but decided against it. Instead, I stored the current state as a 1, then as I calculated the state for the next step, stored it as a 2. Once I finished working through the whole world, divide everything by 2, and all you have left is the next steps state. That's 320 bytes, for those of you counting at home.

I then ran into the problem that, eventually, the world is going to end up being a lot of steady state blocks, or oscillators, which posed a problem. If I was only worried about it being frozen, I could just keep track to see if anything changed while calculating the next step, and set a flag, but the oscillators will change, rather uninterestingly, every step. According to Wikipedia, the oscillators can have a period of up to 30, but I figured the only ones I was really worried about were 2 and 3, since anything more than that was unlikely on such a small world, and probably pretty cool anyways. To deal with this issue, every 6 steps I save a copy of the world and compare it to the world from 6 ticks ago. Now if the only thing left is oscillators, they will end up in the same state 6 steps later, and the engine will catch it and reset the world. That is another 320 bytes, which is 8 times what I really need, and now means I'm using 640 bytes of only 1k of RAM just to store the world. Not great, but since that's all I'm doing, it's ok, right?

Calculating each step only takes a few milliseconds, so I have a 300ms delay on the end of each tick, so it could be run quite a bit faster. For those who are interested in seeing the code for it, here it is:

Friday, September 4, 2009

More Glass Etching

To see how I did this, check out my post on the wine glasses from yesterday. In short, I masked off a set of old fashioned glasses last night, cut out the design, and sandblasted them this morning. I found coming up with designs for the cylindrical glasses much more difficult than for the wine glasses, due to the surface itself being much less interesting. I ended up remasking some of the glasses three or four times before I was finally happy with it, but I think they turned out quite good in the end.





UPDATE: I guess I should get around to posting some more of the glasses I etched. Enjoy:
 
 
 

Related Posts:
Etching Wine Glasses
Sun Jars.

Thursday, September 3, 2009

Etching Wine Glasses

 I came up with this idea while hanging out with my sister in Davis last weekend. For her 18th birthday party, we managed to find a good deal on white wine glasses, so instead of buying disposable red party cups, we bought two and a half cases of white wine glasses. Of course, we've never even come close to using anywhere near that many wine glasses simultaneously since then, so most of them have sat in storage. We came up with the idea of, instead of using wine charms, to etch a strikingly different design in each wine glass to make them easily recognizable when we have several people over for wine.

This is my first attempt at such:


I found making four different designs that were both different, yet stylistically the same very artistically challenging. Of these four, I would really only classify the last two as really being part of one matching set. I feel the top left one is too heavy handed to match the minimalistic touch of the bottom two. The top right glass is a continuous ring, and I would like to eventually pursue that as an entirely separate set of four.

UPDATE: I've made more glasses.

How I made these designs

Making the designs was relatively simple, ignoring the fact that it requires a sandblast gun, and somehow getting sandblast media, which was an adventure all its own.
First I very carefully selected maroon duct tape from atop my pile of 35 other colors of duct tape, and masked off the areas where I wanted to detail the glasses.
Once they were masked off, I used an exacto knife to cut out the designs, and added more masking to prevent any kind of splatter damage to the rest of the glass.

Take it outside, hit the areas with my sandblast gun, peel off the tape, and wash. I have to say they turned out better than I ever hoped for. I'm currently working on a set of four plain old fashioned glasses I've had laying around in my collection for a few years, so I'll keep you updated on those.

Related posts:
More Glass Etching

Buying Sandblast Media

Fun fact: No one has any idea what sandblast media is. I have been previously using sand, which you would think is the obvious choice, but chatting it up with a vendor at a hardware store convention, it was pointed out that sand is a rather poor media. When used, it apparently tends to crack and then you're blowing silica dust everywhere. Another one of those Bad Ideas™ in life.

One of my Sun Jars ended up broken, so I needed to reetch another jar for it. Unfortunately, when I went to pull out the cardboard box in which I store my sand, the bottom of the box decided that it was cool right where it was, and saw no need to come out to the party I was throwing for it and the other four sides of the box out in the open. Needless to say, the sand was in general agreement with the bottom of the box, but went even further and threw a party of their very own ALL over the floor. Fine. Looks like a sign from above: I should go out and finally buy real sandblast media.

In case you didn't know, sandblast media comes in several different types, such as glass beads, coal slag, aluminum oxide, or even biodegradable ones such as corn cob, as well as several different sizes, dependent on what kind of work one is planning on doing with it. Considering that I pretty much only do glass etching, I was looking for something along the order of 30 mesh glass. Of course hardware stores wouldn't have any of it. What kind of normal customer would ever dream of wanting something as eccentric as sandblast media? Me, that's whom...

I can't list them all off the top of my head, but I called several places, such as Franciscan Glass and Peninsula Building Materials, to try and find someplace that carries, or even just be able to hook me up with media. None of them had it. None of them had even heard of what I wanted. To give the guy at Peninsula credit, he at least picked up that sand might be of use to me. My father, in his infinite wisdom, next came up with Grainger. An industrial supply company with a 6 inch thick catalog. They have got to have this.

Matter of fact: they do. 26 kinds, in fact. Score. Not only do they have glass beads, they even have just crushed glass for those of us not looking to set the sandblasting scene on fire. Just a little unfortunate that they only sell it in 50 pound buckets, but when you need it, you need it. US Sieve 25-40 (which is slightly different from mesh sizes) ground glass blast media.

Victory. I call them up, and talk to a rather intelligent sounding guy who figures out which store I should be at, and points out that they only have two in inventory, and offers to put one on will call for me. What the heck? Type type type, done.

Next day, drive across town to Grainger, and ask for will call for Kenneth Finnegan.
"Sir... we don't have anything under Kenneth Finnegan... What's your company's name?"
"I don't have a company; I will called this last night."

He then went on to point out that Grainger does not sell to us lowly public, but since I seem like such a fine and upstanding guy, he'd do me the favor of taking my $40 for a freakin bucket of ground glass, this time. Me possibly getting a catalog for my collection was out. of. the. question.

Long story short, I got my sandblast media, and the message that Grainger does not want to serve me as an individual. I later found out this has to do with them keeping their wholesale status, and one of my buddies gladly gave me his card to use next time I need something.

In case you're curious what the stuff looks like, here is two pictures of my bucket once I got it home. After my first pass with the stuff, I now realize it flies much farther, and is much more noticeable, than sand. Unfortunately, this was after three hoppers worth of media, so I am currently working on strategies to reclaim the stuff to keep my entire front yard from being as sparkly.

Tuesday, September 1, 2009

Buying Classic Soda Locally

Last week I found a youtube video about a soda shop in Los Angeles that sells something along the order of 500 different types of microbrew soda. Soda using real sugar and flavoring, that is something I've always wanted to try. Luckily, they have a website where you can mail order their soda from. Unluckily, mail ordering soda is much like mail ordering water: rather heavy, and incredibly expensive.

I've been hemming and hawing one way and the other about paying quite a bit of S&H on some rather expensive soda to begin with. I had almost talked myself into it, when I happened to be wandering around a BevMo this weekend. Beverages and More is a chain of stores which sell almost nothing more than drinks, and mostly alcoholic drinks at that. I was sharing in the experience that was driving to BevMo and buying drinks by those of the prim and proper age to be doing as such. This left me in the very axillary position of completely and utterly useless, so I had some time to wander the store.
There it was. Bubble Up. The very soda, above any other soda I saw at Soda Pop Stop, that I knew I had to have. Cane sugar, real lemons, real limes. The holy grail of lemon lime soda. And it was right there. In my hand. I had to have it. There was additional flavors bought. An underwhelming Strawberry and Grape, as well as a quite good Peach. None of them quite compared with this though, so I'm quite content with my current supply of snobby soda.

So be advised, if you're a fan of, or want to try, good soda made with real ingredients, BevMo has one short aisle of the stuff, which might hold you over until the next time you happen to be in LA.