Wednesday, December 30, 2009

California Academy of Sciences

My parents both managed to get today off of their jobs, so we decided that we should do something as a family.  In typical Finnegan tradition, it should be educational and thought provoking, so we spent the day at the California Academy of Sciences in San Fransisco.  If you happen to be in the area, here are some of my thoughts on the experience:

We got to the museum around 9am, half an hour before they started letting people into the build at large.  If you do go, getting there early is much to your advantage.  The line was several hundred people long when we got there, and talking to the docents, apparently today was pretty light.  The crowds were incredible.  Even getting there when they opened, we only got maybe two hours before we spent the rest of the day just tripping over other people.  By lunch, they had reached capacity, and only let people in count for count, as far as I could tell (unconfirmed).

The stairs from the parking are in the second picture.  We were able to get a space on the B1 floor, and I didn't see how deep it went (at least one more layer), but it was not big.  The rate was something like $3 an hour.

In the lobby, there were several pool displays, including a string ray tank, a tide pools, and this one on salt marshes.  They made for something interesting to look at as you waited in line for other exhibits, like I was when I took this picture.

They had the classic Foucault pendulum display, which is a pendulum that swings independent of the Earth's rotation, so as the Earth rotates under it, the pendulum knocks down pegs standing below it.  This, and the half hour video in the planetarium about the sun, were the only displays that wasn't entirely biology-based.  If you're a big fan of learning about nature, this should be an interesting museum for you.  If you're something like, say, a physical sciences engineer, the general focus of the entire facility may become a little tedious after a few hours.

Of all of the exhibits, I would say the two definitely worth making sure you see are the living roof and the rain forest exhibit.

Click to enlarge
The living roof is a variety of plants designed to decrease the cooling cost for the entire building.  Just the utter scale of it is quite impressive.  On the left of the picture, you can see one part of the solar system circling the entire building.  Their informational sign about it didn't give any useful specs, but some back-of-the-envelope calculations put the system on the order of 100kW (point of reference, our household system is 3kW).  On the right, you can see some of the automatic potholes.  These are computer controlled as part of the buildings climate control, which is pretty cool.  Being a mid-50Fs day in San Fransisco, it had the top two rows of pots open on one of the two mounds, which kept most of the building quite pleasant, with the disadvantage that the entry way had a very noticeable and chilly draft coming in.

The last exhibit we did was the one on the rain forest.  They built a bio containment dome, and built this very impressive recreation of a segment of the rain forest.  Plan on spending ~45 minutes once you get into the exhibit, after a 30-60 minute line.

You are let in at ground level through an air lock, and then progress up three levels of walkway around the perimeter of the dome.  At the end of each layer is exhibits on a variety of plants and animals found in the rain forest, which couldn't be integrated into the exhibit at large.  This included many snakes, frogs (poisonous), spiders (some with 3-4 inch leg spans), and more plants.

Once you reach the top, you ride an elevator down to below the pool. where you can look up on the catfish swimming in the bottom of the exhibit.  This was the most impressive exhibit in the museum, due to just the shear scale to it.

Over all, it was a very well done museum.  The facilities were well maintained, the docents were friendly and well placed, and the exhibits are well targeted at the lay person.  Like I said already, the only reason I didn't enjoy it significantly more than I did was due to my personal lack of interest in biology.

While we were eating lunch out on the lawn, I enjoyed seeing Sutro Tower (Wikipedia) up the hill, in person.  Sutro Tower is the tower that broadcasts most of the TV we watch from our home, and is a very distinctive part of the San Fransisco skyline.  I'm an amateur radio op, annnd it shows...

Thursday, December 24, 2009

Twinkling LED Snowflakes

Around the beginning of December, my sister, Kristina, sent me a link to snowflake ornaments with a white LED in them.

Needless to say, she thought they were pretty cool, and that we should make some.

Needless to say, I thought they were a good idea, but weren't over-engineered enough. Two hours of hacking source code later, I had an ATtiny 2313 programmed to twinkle 8 LEDs. The eventual result only used 5 of the channels, due to space limitations.

Parts list:
  • 1 - ATtiny 2313 programmed with custom twinkle code. I used a MiniPOV3 to program the ATtiny. Porting this to another controller, like the Arduino, would be trivial.
  • 1 - 7805 linear voltage regulator
  • 1 - 1N4002 diode to protect from reverse polarity on the power supply (optional)
  • 1 - 10μF electrolytic capacitor to filter the 5V from the 7805
  • 1 - 10kΩ pull-up resistor connected to the reset pin in the ATtiny (didn't actually bother to check if this is actually needed. Saw no reason not to just stick it in).
  • 5 - Bright white LEDs
  • 5 - 330Ω current limiting resistors. These are a little big for a 5V and bright whites, but the result was still a little too bright, so pick some value you're happy with.
  • Lots of wire and beads.
We split the work of building the hardware into two parts. Kristina built the snowflakes (including soldering the LEDs to the wire!), and I build the wiring harness and put together the controller.

Kristina building the snowflakes.

One of the completed snowflakes. Our beads aren't as fancy as the ones in the original tutorial, but that was mainly because our options were so limited by the fact that we were using twisted pair instead of wire wrap wire. Most of the nice beads had holes that were too small for us to use.

The control board, fully assembled. On the left is the power supply, with a reverse protection diode and a filtering capacitor, with power in being the two far left screws on the terminal block. On the right is the ATtiny connected to the five sets of twisted pair running out to the snowflakes. I just arbitrarily connected the snowflakes to five of the eight pins on PORTB of the controller, since all eight pins twinkle differently.

One of the snowflakes hanging from our fireplace.

All five snowflakes hanging between our stockings.

Finally, a very dark video of the five of them to give you an idea of what my twinkle algorithm looks like:

Any questions, or ideas on how to improve this, aesthetically or functionally, are certainly welcome in the comments. Merry Christmas!

Monday, November 30, 2009

Seven Segment LED Arduino Clock

As an early Christmas present this weekend, my dad let me go through his old electronics parts boxes to pick out anything I might find useful. One of the first things to really catch my eye was a seven segment LED display.

These are the type displays you see in most digital clocks, so making a clock out of them isn't particularly ground-breaking. Unfortunately, I only have one digit, so just displaying the full time was out of the option. I've seen videos of single tube nixie clocks online, and appreciate the style of flashing each digit individually (Granted, they're doing it because nixie tubes are #%$! expensive, and not because they just don't feel like spending the $3 for a 4 digit display).

The thing on the left is the module I built for my DS1307 so that it'll always be backed by a battery and never lose the time. Super nice when you're moving it between projects.

I pretty much explain everything in the video, but as anyone who has recorded themselves know, you get 50% less articulate once you press record. I point out that AM/PM is easy, since you only need to divide by 12. This is correct, since I'm running the DS1307 in 24 hour mode, but kind of silly, since the DS1307 has a 12 hour mode. I simply run it in 24 hour as a matter of personal preference, since I'm using the same clock chip over and over in all my projects, some of which really lend themselves to 24 hour mode, and don't find converting between 24 and 12 hour mode that difficult when needed.

I also mention using a shift register LED driver. I haven't mentioned these yet, but I bought a couple LED drivers, which are nice because they let you drive 8 or 16 LEDs, using only one resistor to limit current, and only 2-4 pins on the controller. This means it's trivial to change resistor values to adjust brightness, and that I don't have to worry about my power budget on the controller. (Link to the 8 bit LED driver I bought)

Source code.

Note that I got lazy, and used delay()s everywhere in the display system, so there really isn't any way to set the time on the clock as is, other than plugging it into a computer and using the serial port. Feel free to convert it to being non-blocking, but I didn't feel like putting that much effort into a quickie weekend project like this.

Sunday, November 22, 2009

Arduino RGB LED Mood Light

I wasn't feeling creative today, so I decided to hack together the classic mood light, where you take a Red-Green-Blue LED and have it fade from color to color. I did this back when I originally got the RGB LED, but didn't do a very good job on the algorithm for the colors.

The algorithm I used this time was a little better, but still needs a little work. As it stands now, it picks a new color as follows:
  • Generate a random number between zero and the maximum intensity and assign it to the target value for a random one of the three colors.
  • Generate a random number between zero and the maximum minus the target for the first, and assign this number to the next color's target value.
  • Subtract both of the previous target values from the maximum, and assign this to the third.
This would normally generate red heavy colors, since it would average 50% red, 25% blue, 25% green, but since I have it start randomly between the three, it is still biased away from (33, 33, 33), but that's white, so it's not necessarily a bad thing.

Once the target color has been selected, all that's left is to drift to it from the current color, to create the soothing ebb of color.
  • Is the current red level higher or lower than the target? If so, add or subtract one to get closer.
  • Write out the current state to the PWM pins on the Arduino.
  • Pause for 10ms
  • Move on to blue, then green, pausing another 10ms after each.
  • After moving all three one value up or down, if we're still not at the target color, loop back and repeat.
  • Once the target color is reached, pause for 2 seconds to let the viewer enjoy the new color, then select a new target color and repeat the entire cycle.
Overall, I think it does a decent job, but the colors tends to be more washed out half-whites than I'd really like. The ideal solution would be to build a table of ~20 colors that you know look good on the RGB LED, then drift between those randomly. Unfortunately, that requires picking ~20 orthogonal pretty colors, and just calling random() a couple times is a lot easier when you aren't feeling creative.

My video camera isn't very good at recording the color of a light source, but if you watch the breadboard it's plugged into, you can see what's going on, color wise. (If you're reading this in Facebook, you're gonna need to click through to the original post. Yeah, right there, at the bottom, right above the comments, theeere you go...)

Link to the source code.
The simplest circuit diagram you've ever seen:

Note: Apparently the common-cathode RGB LED (where the LED's all share one cathode) I have is uncommon. Reconfiguring this circuit to operate with a common-anode LED is relatively trivial, since AVR I/O pins can both source and sink current. Just connect the anode to 5V, and subtract the desired PWM value from 255 in the source code.

Sunday, November 15, 2009

How to Replace 62 Railroad Ties in a Day

In case you've missed every one of my blog posts since this quarter started, the theme this year has been fun with electronics. However great this theme is (the correct answer is "very"), I felt like this weekend solicited a change.

Thursday I muscled my way through my last engineering midterm for the quarter, and decided that to celebrate, this weekend I would give my actual major (Mechanical engineering. Who knew, right?) the tender love and care that it so deserves. So now the question becomes, "what to do?"

Luck would have it that this weekend happened to be a track work weekend at the Western Railway Museum, and what's more fun than riding on a piece of maintenance of way rail equipment out into the middle of the Central Valley on the old Sacramento Northern line to work your ass off for 8 hours?

Replacing Railroad Ties

Railroad ties are typically heavy pieces of lumber, which the rails are spiked to, to hold the track at the right width and help distribute the weight of trains onto the ground. Unfortunately, wood has this wonderful habit of decomposing, so ties eventually have to be replaced with new ones, which is what we happened to be doing this weekend.

Replacing ties is normally a lot of work. You're literally trying to remove a large piece of old wood from underneath an obscenely heavy ribbon of steel, shove a new large piece of wood under, and then drive four half inch spikes into each one with a sledgehammer. Lucky for us, the WRM track crew has a nice collection of equipment to make our lives easier.

First pull out all the spikes driven into the old tie. This is usually pretty easy, since the ties we're replacing aren't far from being something you'd call tanbark, and you use a claw bar, which is a 5 foot long crowbar. Our track is so bad, several of the spikes have rusted almost completely through as well, making this job even easier.

Next comes pulling out the old tie and inserting the new. We have a machine creatively called a tie inserter, which does pretty much what the name implies. It yanks out the old tie, we shovel out whats left of it, manually line up the new tie, and then the tie inserter comes back and shoves the new one in. In this video, you can see the inserter inserting new ties, while the rest of the guys line up the next few in front of it.

Once the new tie is in, it's time to reassemble the track on top of it. Tie plates, which are flat pieces of steel about 8 inches on a side that the rail sits on so as to not crush the wood underneath, need to be placed underneath the rail. If you're lucky, they'll slide in. If not, you need another guy to pry the rail up with a claw bar, and hope like hell he doesn't slip with your fingers in an unfortunate position.

Now you're almost ready to start driving spikes, but before you do, you want to be sure the new ties are stable in the ballast. Ballast consists of large, loose rock, so you need to compress it underneath the new ties. Quite a big job, usually, but not as bad when you can just use a ballast tamper instead. These things are a sight to be seen. Ours has four giant vibrating claws that plunge into the rock and then squeeze it underneath the tie to form a stable support for the rail. Ahead of the tamper, we shovel extra gravel onto the ties, and in the video you can see him dropping spikes out of the cab to be driven later.

Once the ballast is compacted, all that's left is driving the spikes to hold the track in place. This is the hardest part of the entire project, even with our power tools.

The spikes need to be started into the ties manually, which for 62 ties x 4 spikes per tie gets pretty tiring. I'll be the first to admit I couldn't keep up with the other guys on this, so I opted for assisting driving them the rest of the way with the spike driver once I got tired. The spike driver is a cantilevered jackhammer so that it's easy to move from spike to spike to drive them the rest of the way in. The hammer and compressor are on a track which lets the entire assembly move from side to side, which requires a second operator to guide it from the back.

Note that one of the plate bolts broke at the end of this video, but luckily we were able to limp through the rest of the ties. We did discover that the compressor is metric when we needed to open one of the panels to get it started after it backfired later. I'll let you guess if we happened to have a metric set of sockets out in the middle of nowhere. We had the museum send out a metric tool box on the next trolley, which dropped it off at our red flag, so we only had to haul it 100 yards, instead of 3 miles.

Once the spikes are driven, you're done. We worked a solid seven hours on Saturday, and managed to install all 62 ties we had left. This brought the total for the year to 425, which passes our goal of 400. You'll notice in all my videos that we only replaced every other tie in the bad places, so we've still got plenty of work for next season.

Tuesday, November 10, 2009

DS1307 Module

I've been doing a few projects lately using the DS1307 IC. If you don't already know, the DS1307 is a real time clock chip (as opposed to an unreal time clock chip, which is often used by musicians and people attending events on Facebook). This means that you just have to attach a quartz watch crystal to it, and it'll keep time for you. RTC chips are divided into two categories; those that keep time by counting seconds (usually as a 32 bit number) since some specific start point, and those that count seconds, minutes, hours, days, months, and years.

The DS1307 is of the latter type. This means that it stores the time as seconds : minutes : hours (12 or 24 hour) : day of the week : day of the month : month : year. It also has some smarts so it knows how many days are in each month, and even knows about leap years out to 2100.

This is great, and super useful, but every time I need to pull the chip out of the breadboard to move it, or even just accidentally remove power, it loses the current date and time. Since most of my projects aren't serious enough to warrant wiring up buttons and coding a way to reset the clock, I have to instead plug my Arduino into my laptop with a USB cable, reflash a DS1307 clock setting program I threw together, send it a 13 digit number over the serial port, reflash the firmware for whatever project I'm currently working on, and move forward. Can you see how this would get just a little annoying after the twentieth time? I also have been using the SRAM on the clock to store data, and losing that isn't catastrophic, but annoying as well.

Lucky me, the DS1307 has a neat little feature, where it has an extra pin that you can connect to a Lithium 3V battery, or tie to ground if you're not using it. Sparkfun has a board that has a surface mount DS1307 on top, and a battery clip underneath, which would be useful, but at $20, is a little rich for an inconvenience. I then saw an idea where you do the same thing, just with the DIP package, and all on one side of a piece of perf board.

Parts list
  • Perf board - 5 x ~17 (I used a leftover piece from Radio Shack, but any would do)
  • 5x right angle male header. (sourced locally at Halted, 14 cents) This is so I can turn the board on end and plug the board into my breadboards when I'm done, which is the only place I plan on using this.
  • 1x 8P3 DIP socket (sourced locally, ~30 cents), because soldering ICs hurt my soul.
  • 1x DS1307 RTC (Digikey, $3.74)
  • 1x 12.5pF 32.768kHz crystal (Digikey, 32 cents)
  • 1x CR2032 battery clip (Digikey, 96 cents)
  • 1x CR2032 cell (Digikey, 40 cents, USPS won't ship | Locally, $4.50, I hate you RiteAid)
  • Some wire, solder, soldering iron, etc.
Wiring it up
The DS1307 is nice enough to have 4 of the 5 IO pins on one side (5 - SDA, 6 - SCL, 7 - SQW, 8 - VCC). The fifth pin is for the ground connection, which you need to jump from the other side of the IC with some wire. The battery clip needs to be connected between VBAT and GND, so that'll take at least one piece of wire from the far end. I soldered the crystal straight to the perf board and DIP socket. You should end up with something that looks like this:

Plug in the DS1307 and a CR2032, and you're ready to set the time once, and use until DST.

It works quite well when it's plugged into a project, and I power down everything else. It's super nice not having to try and keep this powered while I'm mucking around with all the other wiring on a board.

I have had a problem when it's just sitting loose. It seems that when VCC isn't pulled to ground, the chip only keeps time half as fast as reality, which makes it less real time, which personally, I find quite offensive. For the second revision, I would probably add a resistor, or even just a bypass cap (0.1μF) between the VCC and GND lines to improve this. While plugged into a project, the rest of the project keeps the VCC line very much at ground, so it's not a very big issue as far as I see it.

Considering that I managed to put this together for easily half of what the Sparkfun board costs, and that I got to break out the soldering iron, which is always welcome, I'd call this project a success.

Sunday, October 25, 2009

Temperature Logger in Refrigerator

The fun continues with my new temperature logger. After leaving it running for a week in my room, I decided to give it a shot at my refrigerator.
Click to enlarge.
To say the least, I was awfully surprised by the data once I graphed it. First of all, I expected it to be much more temperature stable than it really is. With a slope that high, it's clear that you really don't want to open the door when the power is out, because it is already rapidly approaching room temperature.
  • The initial drop is just because I started the logger while it was still in my room, since it had to be plugged into my computer to be reset, so it took about an hour for the breadboard to cool off.
  • Around minute 850, we got home from grocery shopping, so before then, our fridge was rather barren, and the spike was because we had the door open, and were loading warm food into it.
  • It surprised me how the temperature started swinging more after it was fully loaded, instead of less. This might be because all of the added food blocking air flow means there is a greater differential between the cooling element and the sensor. Any other theories?
  • The bizarre temperature spike for the last hour didn't actually happen. With a diode and a voltage regulator between my 8V battery pack and the 5V ICs, that left a very small (<0.5v) margin before the regulator started sagging.
I'm really quite interested in seeing what the difference is between the bottom and top of the fridge, and getting more than a day and a half of data. Luckily, I just happened to have ordered TWO temperature sensors, so the only things preventing me from logging two simultaneous temperatures is the lack of spare hookup wire (left my big spool in Sunnyvale -_-), a dozen lines of C, and a fierce competition between roommates about whether we should be keeping temperature sensors or food in the refrigerator.

Saturday, October 24, 2009

Protip: Masking Tape for Buying Electronics

This was a new idea I got yesterday when I was shopping at Halted. Since the Sunnyvale Halted is kinda far from my house, and the Sacramento one is hellza far from my Davis apartment, I usually tend to go with parts lists for several projects I have queued up at once. Unfortunately, this means the first thing I get to do when I get home is sort out three projects worth of parts from one bag, based on the what seems to be sometimes optional markings on parts.

New trick: Bring a roll of masking tape, and then lay each project down on one strip of tape, then once they're all collected, put a second piece down on top of it. Once you get home, it's just a matter of peeling the tape apart when you have time to work on that specific project.

Sunday, October 18, 2009

Arduino Temperature Logger

Just like every other good engineer in life, I thrive on data. It doesn't even need to be solving a problem. Simply having the ability to say, "I know this," is awesome. Having some free time last month, I started playing with my Arduino again, and finally got around to ordering all the parts I needed for a project I've been thinking about for a long time.

This is my Arduino-based temperature logger. On the breadboard, from left to right, is a serial real time clock, a 1Mb EEPROM, and lastly the serial temperature sensor. Parts list:
Instead of all of the parts for the clock, you can also consider SparkFun's DS1307 module. You pay for it, but you get what looks like a very nice clock/crystal/battery package that you can just drop into your project. Disclaimer: I've never played with it personally. Only had it recommended to me. No way am I paying $20 for $3 in parts on a board.
Forget that. I was able to put together the functional equivalent with less than $10 worth of parts on a scrap piece of perf board.

Since pretty much everything uses I2C, I'll leave wiring it all up as an exercise for the student (Hint: connect everything to analog 4 & 5).

Source code.

Note that some of the features of the dumper (setting the clock, reading the clock), don't work. The main goal was to just get the D(ump) and Z(ero) commands working. I'll get the other commands working at some point if I mess up and the DS1307 loses power at some point (I originally set it using some sample code I found online).

I measured the current draw as 42.5mA, so ignoring the loss in the power supply, that's only half a watt. For this much data, I can pay for half a watt!

How It Works

On power-up, the Arduino checks the CH (Clock Halt) flag on the DS1307 clock chip. If this flag is set, it indicates that the clock has lost power, and that the date and data stored on it isn't valid. Without valid data, the Arduino displays an error message on the LCD and enters an infinite loop to do nothing.

If the clock is running, the controller then loads the first two bytes of general purpose RAM off of the clock. The DS1307 provides 56 bytes of RAM which can be backed by its battery in the case of power failure. I use the first two bytes of it to store the current index into the EEPROM, so that if the controller gets reset, as long as the clock has power, I'll never start writing over collected data by starting from the beginning again. It then prints the read count on the LCD for a second before changing to the current time and date. I found this useful for debugging, since I then only needed to hit the reset button to figure out where it was writing to on the EEPROM. It also sends the temperature sensor the signal to start taking temperature readings. The DS1631 is factory set to continuously take readings, as opposed to the other option where it only takes one and goes back into standby.

Once all of the initialization is finished, the Arduino enters a loop where every 100ms it reads the time off the DS1307 and the temperature off the DS1631 to display on the LCD. It then compares the minute value to the previous one, and if they're different, that means it's been a minute since the last temperature recorded in the EEPROM.

To record the temperature to the EEPROM, the current temperature reading is written to the EEPROM, and the address stored in the clock's RAM is incremented, so if the power goes out in the next minute, no data is lost or overwritten.

Conveniently, all three of the ICs use the I2C serial interface (by accident? Who knows...), so that leaves a ton of extra pins if I manage to think up anything else to add on.

Possible Extensions

Each temperature reading is stored as 2 bytes, one for the whole degrees, and the other to store 4 bits of fractional degrees. It wouldn't be unreasonable to assume my room is never going to swing outside of something like 20-30 degrees Celsius, and try and pack the reading into one byte to save room. I'm using a 1Mb EEPROM, which gives me enough room to take two byte readings every minute for 45 days. This is an incredibly high time resolution, and backing it off to something more reasonable, like once every 15 minutes, stretches this time out to 2 years. Changing the source is trivial; just add minute%15==0 to the if statement in loop().

Since the EEPROM is I2C, having the maximum 4 devices per bus is simply a question of paying the $4 per device. You would have to change how the tempreadcount variable is handled everywhere (store it in three bytes on the DS1307 instead of two, etc) so it doesn't roll over after the first chip is filled, but that would mean being able to take a temperature reading every minute for half a year, and that's just freakin awesome.

Even without the AT24C EEPROM, the Arduino comes with 512 or 1024 bytes of EEPROM on-board. This can get you a couple days of 15 minute readings, which is at least enough to play with, if you just wanted to buy the DS1631 chip.

  • For some reason, I could not get the LiquidCrystal library and Serial to both work at the same time. This means that to dump the EEPROM or reset the clock, I have to flash in a different program, then reflash the logging program.
  • I was originally using a DS1306 clock chip, but it drifted badly (a few minutes a day). Once I switched to the DS1307, which calls for the 12pF crystal I had, instead of a 6pF crystal, it hasn't noticeably drifted in a few days. Lesson learned: make sure you have the right crystal for your clock.
  • Don't copy paste big chunks of code that almost do the same thing without stopping and really thinking about it. I spent a long time trying to figure out why the data dump just read the last measurement for all of them. Was using the read number count instead of the loop variable... I was afraid I had somehow smoked my $4 EEPROM.
  • I think finding I2C addresses in data sheets is some kind of right of passage. You'd think that they would be something they're put rather prominently on the first page, or refer to it several times, but instead, every time they do refer to it, they refer to it as, "that address as noted previously," etc. Freakin pain in the ass, digging through not only the text, but all the I2C spec diagrams to find where they happened to show the waveform for the device's address, which you then get to decode into the 7 bit number you needed in the first place. I finally wrote up one page of notes with all the I2C addresses and register numbers so I could actually write some code instead of spend two hours digging through the data sheets every time I try to implement something.


After running for one day, it came time to dump the data into Excel. I did this by writing the second program, which just prints each reading number, and the two bytes of the reading, all tab seperated so they will go into seperate cells nicely. To calculate the temperature was simply a matter of =(first cell)+(second cell/256). A little bit of good old graphing magic later, I got this:
Click to enlarge!
It is pretty clear that a one minute time resolution on a 12 bit temperature measurement is a little overkill. Most values are repeated for 10 minutes before drifting down another 1/16th of a degree to the next possible value. I've been playing with massaging the data after the fact to get a smoother line, but the logical next step is to just record the average reading for 5-15 minute periods to ink out two more bits, while saving a tremendous amount of EEPROM (45 days per chip to 1.8 years for 15 minute intervals). Note that the spikes in the afternoon were me playing with it by putting my finger on it and watching the temperature go up and fall back down to room temp.

Update 10/24/09: So after running the logger for a whole week, I've dumped the 10,000 some odd data points, and graphed them in Excel, just for your enjoyment (I'm lying, mine too).
Click to enlarge.
The ticks on the x axis are about where I believe midnight to be (I'm planning on patching the firmware to log a 0xFFFF temperature at midnight, since it knows what time it is). It's pretty clear that I left my window open over night two of the seven nights (Monday morning, Friday morning). What I did find surprising was how late it was before it started getting cooler. Most nights you can see it at least holding steady until I finally went to bed around 12:30am (Sunday night being the exception, due to the open window). On Thursday (second to last day) it's most dramatic, but when I leave for class, etc, the temperature markedly stops rising. I expected being home, awake, and active had an effect on my room's temperature, but certainly not to the degree shown on these graphs.

I also implemented a histogram feature on the last of the unused LCD space using the eight custom glyphs feature on the HD44780 controller. Essentially what I did was every hour (every half hour in the picture), stored the current temperature in an array of the last 40 (5 columns * 8 glyphs) such readings. I then calculated the maximum and minimum values for this set, and used that to normalize the values so they ranged between zero and eight, to calculate how many pixels high that column should be. The code ended up being pretty ugly, so I'll leave the specifics as a challenge for the student (don't you hate it when they say that?). The general idea is:
Bar height = (temperature - minimum temperature) * 8 / (maximum - minimum)
Storing the hourly temp readings in an array was just me being lazy. The I2C bus is pretty freakin fast, so the better solution would be to just read the values back off the EEPROM, since this only needs to be done once an hour, and that has the added advantage of not having an empty graph on reset.

Update 10/25/09: Data collected in my refrigerator.

Sunday, October 11, 2009

Disabling a Car's Panic Button

In some situations, having a car alarm with a remote panic button can make a lot of sense.  The traditional somebody-is-mugging-you one comes to mind, but even for much more mundane uses such as trying to find your grey colored Toyota Camry in pretty much any parking lot.

Unfortunately, this is a less than ideal world, so many times you will accidentally set off your car alarm at a time when you don't want to.  In an even less ideal world, your remote actually fails, putting it in a state where it will randomly set off your car alarm ALL THE TIME.

Fortunately there is a relatively easy fix, that I've actually done a few times on various remotes already. Usually what I do is just cut the actual button rubber down so it becomes more difficult to press, and less likely to be pressed accidentally in your pocket, but sometimes the actual button in the remote will fail, which means either buying an entirely new remote, or just disabling the remote panic feature and to live without it.

The button covers were all a single sheet of multicolored rubber, molded so it would look like four buttons. Thank you wonderful modern technology: you make our lives so much easier, when you work. Cutting that off just didn't seem like a good idea, breaking the seal on the electronics, etc.

That worked out just as well, anyways, since a little poking around with a volt-ohm meter made it pretty clear that this wasn't a case of fat fingers. The panic button (top right in the picture) was really defective, naturally shorted out, just waiting for some good reason to cry wolf. This meant I needed to actually disconnect the button entirely.

I first tried using my soldering iron to heat and lift off the entire button, but I've never really had much success with surface mount components like these, so I gave up on that fairly quickly. I instead opted to simply cut the trace. A little scratchy scratchy with an exacto knife, and the button is officially out of service.

You can see the scratch between the button and the 4th pin on the IC on the vertical trace. Tested it with my ohm meter to make sure it was really open, put everything back together, and we have a much calmer remote (get it? no panic - calmer. Man, I kill). Another day saved by not being afraid to open something and figure out what's up. Carpe diem, people.

Thursday, October 1, 2009

The Square Root of 2 is Irrational

You remember that fun piece of trivia from some math class in high school? Some teacher, in their infinite wisdom, laid down the law: The square root of 2 (√2) is an irrational number, which means that it cannot be represented by a repeating sequence of digits. The first few are 1.4142135623730950488016887242097...

But I'm in college now. I'm supposed to be challenging preconceptions about religion, culture, and basic properties of numbers, right? Of course, but fortunately, religion and culture aren't nearly as interesting, so we're going to be limiting ourselves to the third subject.

So if √2 really is an irrational number, I should be able to prove it. Before I prove it, we're going to need something to prove it with:
  • A rational number is a number that can be represented by the division of two integers. This means that I can represent 4 as 4/1, 2.5 as 5/2, and 3.333... as 10/3. An irrational number is a number which cannot be represented by these two integers. Some familiar ones are π and e. φ has also been coming up in discussion a lot this week.
  • The Well Ordering Property of Integers: Given any positive set of integers, I claim that of them, there is one that is less than all the others. That's right, when given the numbers {4, 9, 123, 19244000}, you can always look at them and say, "Ah ha! That four is less than all the other numbers!" This is important, I promise.
So now that we have something to work with, let us start making the magic. A good way to prove something in mathematics is to instead prove that what it isn't, it is not. Show that it can't possibly be anything else, so the only option left must be the answer.

Lucky for us, there is only two options here: √2 is either going to be rational, or irrational. We're claiming it's irrational, so let's show that it's not rational:

ASSUME √2 IS RATIONAL. This is mathematics, so we can play pretend. This means that we can express it as the division of two integers: √2 = a/b. Now if we multiply both sides by b, we get the following:
b√2 = a.
We know that a is an integer, since we called it an integer to begin with, so that means that b√2 must also be an integer. Now since a and b exist, it's not hard to imagine there is a positive set of integers that would satisfy the requirement √2 = c/d (2a and 2b come to mind).

Let's call the set of all the possible positive integers b√2 the set S. This means S is a really big group of positive integers, all of which are products of another integer and √2. This set must have a smallest member, as per the well ordering property. Let's call that smallest member s = t√2.

Since s is the smallest member of this set S, that means that if we can show that there is yet a SMALLER member of S than s, we've got a problem, since smaller than the smallest doesn't make much sense.

s = t√2
s√2 - s = s√2 - t√2
s√2 - s = (s -t) √2

Now we know s and t are integers, by definition. If we multiply them by another √2, we have s√2 = 2t, which means that s√2 is also an integer. Since s and s√2 are both integers, that means the left side of the equation is an integer, which means both sides are integers (we can make this argument from either side).

We also know that both sides are positive. The left side can be factored out to s (√2 - 1), and √2 > 1, since 12 is 1, and 22 is 4.

Now we've got a problem. We've got this integer (s - t) which is positive, and which is an integer when multipled by √2. This is bad, because (s - t) is clearly less than s, and we picked s as the smallest member of S. This means S can't exist, and finally that √2 is an irrational number. Q.E.D.

Well that was fun, wasn't it?

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.

Friday, August 28, 2009

My First 24 Hours of Texting

I finally broke down yesterday and decided that it was worth $10 a month for me to get and send text messages. If it was just up to me, I would have probably lived without them, but unfortunately too many people I know assume them to be guaranteed delivery, so when their texts to me just disappear into the ether, they assume I just ignored it...

So in the last 24 hours, I have sent or received 70 text messages. Luckily most of those were to others on Verizon (ie my sister or my best friend), so I'm not counted against my 500/month for those. Most of those were sent using t9word, which I found to be an interesting experience. Sure I had used it before to enter short notes to myself, but never anywhere near thee extent I've used it in the last 24 hours. As I got more experience, it very slowly stopped being so much about hitting the number with the correct letter on it, and more about hitting the right combos for the words I wanted to type. Much the same as can be said about morse code: You can't think of it as dots and dashes. You have to start listening to it and just be able to hear that - .... . means "the" and - .... .- -. -.- ... means "thanks." In this case, it just happens to be only encoding, and not both directions.

It goes to show that, if you spend some time learning something every day, you can pick it up rather quickly. Now I just need to start working on my morse code as such...

Friday, August 21, 2009

Personal Best for Origami Ball

I have been folding these balls ever since 6th grade when my teacher had one on her desk. I was just obsessed with it, and she made a deal that for every week I turned in all my homework, she'd teach me the next step to making it.

The one she taught me how to build used 30 squares of paper. Each square is folded into a parallelogram, then woven together. The centers of each parallelogram make the edge between two of the pyramids on the surface of the sphere. The 30 ball was made by grouping the triangular pyramids in groups of 5, like the group in the front of the first picture. I soon discovered that you could make a smaller ball using groups of 4, which only used 12 parallelograms. Going in the other direction, I soon found that groups of 6 would make an infinite sheet (consider the pyramids as just equilateral triangles, and you can see why they'd lay flat).

This left me with a challenge: How do I make a sphere larger than the 30, when 6 groups don't make a sphere at all? I figured that a heterogeneous lattice would do it, but couldn't quite visualize what the layout would be.

Wikipedia to the rescue! Buckminsterfullerene (C60) is perfect to model my sphere after. Treat each Carbon atom as one of the equilateral triangles, and each bond as the long edge between each pair of triangles, and the whole design drops out. The fact that I was able to realize this somewhere in the order of 8th-9th grade, is, in hindsight, pretty impressive.

Wanting to have a general idea of what I was getting myself into, I wanted to know how many of these parallelograms I needed to fold. This turned out to be a fairly easy calculation. Each triangle is made from three interlocking parallelograms, and each parallelogram is part of two triangles. Since I'm treating each triangle as a Carbon atom in the fullerene template, I know I need 60 triangles. 60 triangles * 3 parallelograms per triangle / 2 triangles per parallelogram = 90 parallelograms. Quite a project.

Lucky for me, I was generally unemployed this summer, so time was my middle name. I woke up at the crack of noon one day, and decided, "self, today is the day that this is actually going to happen." A paper cutter, 24 sheets of paper, and 6 straight hours of folding later, I sat down to dinner being the proud owner of a sphere admirably larger than my last.

In case we're unclear, by "larger," I really mean "more awesome"

UPDATE: Before I finally disassembled it, I figured I should take a picture of this latest accomplishment next to its predecessors to give you a better idea of what kind of progress has been made. Pictures below is the Buckyball on top, with the 4 cluster on the left and 5 cluster on the right.

Thursday, August 20, 2009

I Have a Pen Problem

I'm ready to admit it; I have a pen problem. Fry's had a ridiculous sale this week: an 8 pack of pens for 15 cents. 15 freakin cents! So like every reasonable human being, I promptly drove to Fry's, Jeff Glass in toe, and bought 5 of them. Unfortunately, my wonderful mother pointed out that she needed more pens for her desk, so being the reasonable son I am, I sold two packs to her for 30 cents.

At this point, I was faced with a dilemma. I only had 3 packs of pens, which works out to be 24, which is good, but not nearly as awesome as 5 packs of pens. Normally, that would be that, but I happened to be in that side of town again (literally drove right by Fry's), so the obvious answer was to go in and buy another 5 packs.

I have 64 pens, and I spent $1.34 to get them. My life is awesome.