Monday, January 2, 2012

Pretty Pachube Plotting Progress

Edit: January 4, 2012. My Pretty Pachube plots seem to be showing up only part-time. I suspect that there is some throttling going that I need to get a grip on, perhaps because the feed data I am plotting is not my own. Please leave a note in the comments if you have an idea of what might be going on.

In my last post, I wrote about motivating myself for 2012.  Goals #1 and #2 had to do with working out, but I felt like a bucket of crap on the first day of the New Year and had little energy and less motivation (thank you very much, rhinopharyngitis).  I just felt like lying around like an inanimate carbon rod.
The Only Thing Keeping Me From "Employee of the Week"
But NO!  I have things I've gotta get done, so I thought I'd work a bit toward Goal #3.  Goal #3 was to get a basic home monitoring system set up, and one of the ideas I had was pushing that data out to Pachube to act as a repository for the data I would collect.  I'm not actually pushing out any data just yet, so I thought I'd dig into the presentation side of it.

Searching around on the Pachube web site, I came across the  Zoomable 30 day graph documented on the apps section of their site.  There is a nice little setup there where you can set up the graph's basic configuration online.  Give it a feed and datastream ID, a few parameters on size and color, and it spits out some code to cut and paste into a blog entry or web page.  Simple, eh?

Don't use it.  It has a couple of limitations:
  1. It can't put multiple lines on the same plot
  2. It doesn't work.
It actually does work until you try and plot more than one graph on the same web page.  The script doesn't handle multiple instances properly, and you end up wasting a bunch of time before finding this out.  Ask me how I know.

The link above does, however, include the following comment:
Note: if you are looking to combine multiple datastreams on the same graph, either by summing them or displaying them separately, see this post in the community forum for a solution
That is almost a solution, but it doesn't work with non-numeric data stream names.  What you really need to use is the script pointed to in this link.  This works great, and here is a summary of getting it to work on any web page or blog post.

First of all, you need these two lines of script before trying to show a plot:
<script src="http://www.google.com/jsapi" type="text/javascript">
</script>
<script src="http://thecodergroup.com/store/pachube/pachube_multi.js" type="text/javascript">
</script> 
Once you've done that, you can follow the examples in this forum post for the Javascript needed for the plots themselves (if you want to see the Javascript behind each of the examples below, just hit Control-U to see the source of this page).  These examples use data collected from a bash script from this page running on a DD-WRT powered router. 

Let's start off simple.  First, here is a plot of the uplink datarate.
Next, a plot of the downlink datarate.
Let's geta little fancier.  How about a plot of the uplink and downlink datarate on the same graph?
Or the sum of the two values plotted as a single value?
Pretty cool, I'd say.  There is one thing to be careful of here though.  The "div name" that is the first parameter to the script needs to be different for each of the plots you use.  This keeps the data behind each of them separate.  Weird things will happen if you don't.

There are other ways to present Pachube data.  I could just look at the data right off the Pachube web site.  Look here for the Pachube version of the plots I presented above.  Nothing fancy, but not bad.  There is yet another method of plotting data out there using the iGoogle Pachube Gadget and the associated method of publishing to a web page discussed here, but I found that to be a lot less flexible.

Despite taking a little longer to sort out than I anticipated, I'm pretty happy with the flexibility of this presentation. But wait, there's more!  There are more apps, such as ones that will send SMS alerts or Twitter messages when a particular condition is reached.  I haven't dug into these yet, but it is on my list of things to do once I've got my own data going in.

Friday, December 30, 2011

Motivating Myself for 2012

It is that time of year that people look back on the year it was.  I look back and I'm pretty pleased with how it went down.  I've gotten some things done that I've been meaning to get done for a long time, I have challenged myself to learn new things, I have had good success at work, and I like to think that I am a little better person than I was when 2011 was about to roll in.

It is said that one way of making sure you carry through on something is to tell other people what you are doing.  The more people you tell, the more people you are letting down if you fail to follow through.  With that thought in mind, and with 2011 drawing to a close, it seems like a good time to look ahead and set some goals for 2012 in a couple different areas.

Working Out

I have been working out pretty diligently over the past four years or so and have become decently strong on a few lifts.  This despite having the frame of a Japanese schoolgirl and the fact that the testosterone train left the station long ago (i.e. I'm old).  I'm not expecting huge gains in muscle mass but I do think I have the capacity to put on a few more good pounds if I eat enough and don't get hurt.

My best lift is the deadlift.  Pick a weight up off the ground and put it back down.  Simple enough.  I can usually do something like 350lbs to 365lbs for five or six reps depending on the day with a bodyweight in the low 140lb range.  Not bad.  This should translate into a 415lb+ one-rep max.  Should, but probably doesn't, at least for me.  I find that my body doesn't seem to obey the basic predicted formulas for one-rep max

one-rep max = weight / (1.0278 - (.0278 * reps))

and that my reps go down sharply as the weight goes up.  So...

Goal #1: Deadlift 405lbs for a single rep.  That's four wheels a side.  This goal should be doable.  I just have to do it.
This is 495lbs, but you get the idea
One of my weaker lifts is the squat.  Yesterday's workout was 235lbs x 4 for a calculated one rep max of 256lbs.  This lags well behind my deadlift.  I feel my hamstrings are letting me down and will work to strengthen them up.  I really need to build up my bottom position strength before I see some decent gains here.  Because this lift sucks for me, I'm thinking...

Goal #2: Squat 280lbs for a single rep below parallel.  285lbs - 290lbs would be even better, as this would be 2x bodyweight.

 I get mistaken for Tom Platz all the time

My other lifts are decent enough, so I'd be OK with basically maintaining them as I bring these others up.  I can pretty easily Military Press my bodyweight, and I can do weighted chinups with an extra 77.5lbs of weight (around 55% bodyweight) hanging off a belt for 5 reps or so.  Bench press?  Screw it.  It has done my shoulders far more harm than good in the past.  I might play around here a little bit, but pushing serious weight with them isn't something I'm planning on.

Work

Work isn't really something I talk about this on this blog, so I won't.  Suffice to say I just hope I'm not putting in crazy amounts of extra time that would take substantially away from all this other stuff I want to do.

Hacking

This year we went away for a few days to spend Christmas with the family.  We had our neighbor check in on the place while we were away.  You never know if the furnace might go out or a pipe springs a leak or something like that.

Actually, you can know.  And it isn't that hard.  I've spent a bunch of time researching this lately.  There are a multitude of ways that data can be collected and made available so I could know right away if my furnace stopped working or a pipe sprung a leak.  Then I could just make a phone call for somebody to check into it rather than having them waste their time when everything is fine.  One strategy would be to collect the data with some JeeNodes from JeeLabs and the incomparable Jean-Claude Wippler.  JeeNodes are a kind of Arduino clone with built in network capabilities and an emphasis on low power such that a single remote node ran on a single LiPo for a year without breaking a sweat.  More here.  And did I mention that these things are crazy cheap?

Now, that data has got to get onto the net, so why not just hook up a JeeNode to my router and write a script like that used to collect data from my weather station and push it out on to the web?  If only there was a site that was willing to store all of this data for me and make it easy to get to.

It turns out that there is.  Pachube is happy to take all of the data I send to them.  They have an open API.  Look at the data from their web site or pull the data into a Google gadget and display it on a web page.  And you can retrieve the data whenever you want in three different formats.  All for free.  So how about...

Goal #3: Get some basic home monitoring going by Christmas 2012.
This is what I have in mind.
One more thing that I have been playing with for some time is trying to understand how the Davis Weather Station outdoor sensor suite is monitored by the indoor console.  What I'm working towards is some means of building a standalone receiver that could listen in on its transmissions and collect the data without depending on the console.  I had initially proposed a Pretty Pink Pager for this task, and indeed, I was playing with this just the other day.  Unfortunately, I'm struggling with some kind of problem with my GoodFET where it doesn't want to talk to the IM-ME, and this is slowing me down.

There is a problem with this approach though.  The number of people that have a Davis Weather Station, an IM-ME, and the means to hack it is a number one less than two.  The IM-ME is a good prototyping platform for this kind of thing, but it isn't an accessible solution for others.  The biggest problem is the CC1021 chip in the console is not exactly hacker friendly.  The documentation is great, but actually building a board around this thing is not: the components are tiny and a good layout is critical to decent performance.  Development boards also tend to be either expensive or very expensive.  Then I came across the XRF module from Ciseco that puts a CC1101 processor (CC1021 RF compatible) onto an XBee form factor board for just £10 plus another £2.50 for shipping.  What a deal!  This leads us to:

Goal #4: Get a standalone receiver picking up the transmissions from a Davis outdoor sensor suite by the end of 2012.
Let's Do This.  You and Me.  Mano-a-Mano.
Wrapping Up (Finally)

Well, that is enough for now.  There are still a lot of other things I want to get done this year, such as
  • I have a bunch of landscaping to get done.
  • I'd like to get a little hydroponics setup going so I don't have to wait until fall for a decent tomato.  Life is too short for shitty tomatoes.
  • I'm going to keep working at improving my breadmaking skills.  Incidentally, this Sourdough Rye bread is outstanding.
These things lead me to...

Goal #5: Keep this blog going, share the adventure, and enjoy the ride.

What are YOUR goals?  What do YOU plan to do?  We live in a great time where pretty much anyone can learn about anything.  The greatest threat to this is a lack of motivation.  Don't waste the opportunity you have.  Get started today.

Happy New Year from all of us here at Mad Scientist Labs.

DD-WRT is Dead! Long Live OpenWrt!

The Christmas break is upon me and I am trying to get a few things done rather than just sit around and eat cookies.
Chose to Eat Cookies
One of these things was to change the firmware on my trusty Linksys WRT-54G, perhaps one of the greatest routers of all time.
The Muhammad Ali of Routers
It's greatness was largely accidental and stemmed from a license violation.  Linksys used Linux as the brains behind this router.  However, they did not realize at first that the GNU Public License that Linux is released under requires all changes to the source code be made public.  Their hand was forced, and the source code was released in July of 2003.  The open source community tore into this code like a pack of wolves and custom versions with additional features sprang forth.  Before long, this $60 router had the features of a $600 router.  It became the router of choice for geeks and hackers everywhere, and Linksys sold approximately eleventy billion of them.  Read this if you want more of a history lesson.

Linksys came out with many different versions of this router as time rolled on.  I have one of the best: a Version 3 with a staggering 16 Meg of flash and 4 Meg of RAM.  Later versions halved the amounts of flash and RAM, forcing subsequent versions of custom firmware to cut back on features to make room.

I don't remember when I did it, but my first cut at custom firmware was DD-WRT.  I picked this because it had more features than I would ever use, was well supported, and had a nice GUI to control everything.  Sadly, DD-WRT doesn't seem to remember where it came from anymore, and you can't build the whole shebang from source.  Want to modify the GUI?  Be prepared to jump through some nasty hoops to do so.  Development of DD-WRT has also slowed to a trickle: the last release for my router was in 2009, and that was to fix a software vulnerability.

Screw this.  Time to switch, and switch I did.  Yesterday I put OpenWrt and the Gargoyle "router management utility" on it and the process was relatively painless.  Note that I said relatively painless.  There were a few bumps in the road that tripped me up briefly.  This is what got me going.
  • I went to this page on the Gargoyle website and chose the Firmware Image for the Broadcom architecture for the latest stable branch of the code.  This image has the OpenWrt firmware rolled in already.  Nice.
  • The brcm47xx-squashfs file was what I needed, but should I download the .trx or the .bin version?  According to the install guide...
If you are installing from another third-party firmware such as DD-WRT or Tomato, you should also use the .trx file.
Sounded to me like I need to download the .trx version.  Turns out this was wrong.  More on that in a second.
  • The Installation Guide on the OpenWrt Wiki told me that all I should have to do was "Open the WebUI of the original firmware with your web browser and install the OpenWrt firmware image file using the "Firmware Upgrade" option of the original firmware."  Easy peasy.  I backed up my DD-WRT settings from the GUI and then tried to load the .trx file.  DD-WRT greeted me with
Incorrect Image File 

Not good.  That is when I started Googling around and started reading about all the people that had troubles upgrading to OpenWrt from DD-WRT.  The problems people were having were broken charts in Gargoyle and wireless that just plain didn't work afterwards.  This got me a little nervous because this is the only router I have, and botching this upgrade would make me very grumpy.  But no guts, no glory.  I proceeded onward.
  • This post suggested resetting to factory defaults within DD-WRT before doing the upgrade.  This made sense to me: clearing the NVRAM in the router before going to a new firmware version would let OpenWrt start with a clean slate.  Resetting to defaults caused the router to reboot into DD-WRT, after which I had to re-login with the default password of "password".  I'd have never guessed.
  • The next step was to rename the .trx file to .bin and again use the DD-WRT "Firmware Upgrade" option, against the advice of the installation guide.  DD-WRT happily accepted this file.  Several nerve-racking minutes passed while the router re-flashed and rebooted itself.  I pointed my browser to 192.168.1.1 and...
Success!
  • But I wasn't through yet.  Wireless wasn't working.  I dug around the GUI a bit and saw that it was disabled by default.  I enabled that, set the SSID and security stuff, and saved my changes.  This caused the router to reboot and... still no wireless.  This is what I had read about and I was starting to get a little nervous again.  I unplugged the router's power supply for 30 seconds, plugged it back in, and it worked!  Yay me!
Looking back, I realized I was fortunate doing this upgrade over a wired connection.  The default of wireless being disabled and the temporary problem I had with getting wireless going would have caused addition grief if I hadn't been wired in.

A question you might be asking yourself is why I am still playing around with such an underpowered, ancient router that only supports the B & G standards.  Well, when all you have 2 Mbits/sec of downstream bandwidth and 128 kbits/sec of upstream bandwidth, Wireless G is all you need.  But more than that, this thing is completely and utterly reliable.  It quitely does its thing, hidden away in the basement.  The custom firmware also gives it far more capabilities than I need, and it is still incredibly well supported.  What is not to like?

Well, it doesn't have anything in the way of extra ports and it could use more memory.  But there are a ton of easy hardware mods for this router that I might take a shot at that would give me exactly this.  One thing that I really want to try is this 1-wire mod that will let me connect simple devices like temperature sensors to this thing.  A reader of my blog has even written a script that lets a WRT54G with a serial port hacked on upload data from a Davis Weather Station Console directly to Weather Underground.  How cool is that?

This baby still has a lot of life in it yet.

Sunday, December 11, 2011

Please Read This

Christmas was the best day ever when I was a little kid, just like it is for so many kids today.  But as I've gotten older, there are a few things about it that are like old clothes: for some reason, they just don't seem to fit quite as well as they used to.  I still enjoy the socializing and the food.  It is more the gift thing that just seems a little awkward now.
Best Christmas Movie Ever, Bar None
I am not a very materialistic person.  I also understand the difference between "need" and "want".  If I need something, I get it because I actually need it.  If I want something, I tend to mull it over for some time.  What I have found is that the things I think I want are fleeting, and what I think I want one month, I am no longer interested in the next.  To quote Sheryl Crow:

It's not having what you want,
It's wanting what you've got.

It is very rare that I will buy something I think I want on the spur of the moment.  This discipline serves me very well.  It saves money and keeps down on the amount of clutter around the house.  I've found clutter like this tends to depress me, so avoiding it in the first place just helps me feel better.
I Am A Few Ounces Of Discipline Away From This...
I also have gotten to be pretty particular about the things I buy.  If I decide I want something, I'll get something that does all the things I want it to do.  I do a lot of research before putting down my hard earned cash.  That doesn't necessarily mean that it is expensive.  It means it does what I want it to do at a good price.  The internet is an absolute godsend for me.

So lets get back to Christmas.  I was getting gifts in recent years from very well meaning friends and relatives that I wasn't really enjoying or using that much: books I wouldn't get around to reading, stuff that I never used, etc.  It just seemed kind of wasteful despite the best of intentions.  This stuff and another incident I won't get in to started turning me off the whole gift thing.  So after Christmas a couple of years ago, I decided it was time to do something different.  I simply asked everyone that in lieu of a gift to me, that they instead make a donation to a charity of their choice.

You see, one of my numerous shortcomings is that I don't donate much to charity.  My request would indirectly address this shortcoming and take some of the commercialization out of the holiday season that was bugging me as well.  I was killing two birds with one stone.  Sheer genius, eh?  I'm right up there with the great physicists of our time: Einstein, Planck, and Spears.
First Row, Fourth From the Right
So last year was the first year that there were no gifts under the tree for me.  How did it  work out?  Much better than I had expected, without a doubt.  It was a little weird in that it was different for me.  However, I felt great each time I heard of other person's act of giving.
Srsly
I learned of the most memorable of these events when I drove home on Christmas day 2010 to see my mom and spend the day with her.  She told me that she had made a donation to the Children's Wish Foundation, whose goal is to bring some happiness to children who are facing a pretty dire situation.  This is a charity dear to her heart (again for a couple reasons I won't go in to).  She had made her donation to Children's Wish earlier that month, and that was great.  But for her, what really made it was when the charity phoned her just before the holiday to express their gratitude.  They didn't ask for more money, they simply thanked her.  She told me that this was the best thing that had happened to her all holiday.

That made me feel pretty awesome.  I'm getting a little choked up typing this in even now.

Fast forward a year to 2011.  I got a Christmas card from my mom in the mail just the other day.  I opened it up so I could read it and put it onto the mantle with the rest of them.  But this was no ordinary card.
I didn't realize it was my Christmas present until I opened the card and started reading.
A goat brings lasting abundance to hungry families.
For impoverished families, a gift of one or even two goats is a fantastic milk, food, and income source.  The family will also receive training on how to breed the goat and start a business.  Because of you, this precious gift can even be the start of a flourishing dairy business for the family that receives it.  Thank you!
Mom had done it again.  I was totally taken aback.  The card was from World Vision.  They work "to improve child well-being and to serve people around the world regardless of religion, race, gender or ethnicity".  Mom had chosen this goat from the many options listed in their gift catalogue.  Her choice meant some family I will never meet will get a shot at a better life vs. me getting something I don't really want and won't use.  Seems like a pretty good deal to me.

Whoever said it was better to give than to receive was right.  I know that now.

Why not find this out for yourself if you haven't already done so?  Consider giving either some of your cash, some of your time, or some of what you might have coming your way this season to a cause you support.  Or maybe you've enjoyed what you've read on this blog or learned something useful and want to show some appreciation?  That works too.  Pick a cause and help them out.  Whatever cause you choose isn't important, as long as it is important to you.

If you decide to do something, that would be fantastic.  If you don't, that is OK too.  Your choice.  Whatever you choose to do, the staff of Mad Scientist Labs wishes you a safe and happy holiday, and the best of 2012.

Sunday, November 27, 2011

Shattered

My lovely wife and I live out of town on an acreage.  Our nearest neighbor is a half mile away.  We have no yard light and don't want one, either.  At night, it gets dark outside.  Very dark.  It looks a lot like this:
Seriously
We also have a dog.  A large dog.  A large dog that refuses to take advantage of modern conveniences like indoor plumbing.  If she has to "go", she has to "go outside".  "Going outside" is her favorite thing in the world, as it is with most dogs.  But our dog is also rarely more than a few feet away from either my lovely wife or myself.  If we try to let her outside to do her dirty, filthy business, she'll just stand on the step and wait for us to come out.  She would probably blow out a kidney waiting for an escort to take her into the tall grass where relief awaits before heading out there to do her business on her own.

Now going outside sometimes means going outside at night.  At night, it gets dark outside (we've been over this - remember?).  And at night, there are various critters that like to come out as well.  We regularly hear the coyote packs howling under the moonlight.  And then there are the porcupines.  Our dog has tangled with these and other critters.  Usually she comes out on top because of her size.  Sometimes, not.  A dog can't win against a porcupine, but they don't seem to be able to figure this out.  These battles can be painful.  And expensive.
Our Dog: Post Surgery after Porcupine Battle #2
So because our dog needs to go out at night, and because it gets dark at night, and because we have to go out with her, and because there are dangerous critters outside at night when it is dark, and because we can't see in the dark, we need a flashlight.  A bright flashlight.  A flashlight that can light up the night for a great distance.  A flashlight that can find the critters before our dog does and hopefully scare them away.  We started off with a four D-cell MagLite flashlight.
Great For Smashing Some Thing's Head In, But Not Great Otherwise
This thing threw a pretty decent amount of light.  We also got a good workout lugging it around.  And it would also go through batteries like Wynonna Judd goes through donuts. Not recommended.
I Am A Mean Person...
Then I discovered the wonders of LED flashlights.  I coincidentally also discovered the wonders of Deal Extreme.  They have Deals there!  And they are Extreme!  After much research a year ago, I picked up this bad boy: an Eastward YJ-XGR2 Waterproof Cree R2-WC 2-Mode 250-Lumen LED flashlight.  It is amongst my most cherished possessions.
Is It Wrong To Love An Inanimate Object?
The first night I tried it out, my lovely wife and I were outside.  I pointed this baby at her eyes and she had to look away.  "Big deal", you say.  "That would happen with any flashlight."  Sure.  But I was 200 yards away at the time.  This thing is light, far brighter than the Mag, and one charge of its single rechargeable batteries last up to 10 hours.  I love this thing.

That is why I was devastated to discover this after the pup and I went for our morning walk-about.
The Lens Was As Shattered As I Was
We don't know how it happened.  But it happened.  This flashlight was in critical condition.  What to do?

There was no way we could go back to the Mag: I am a man of modest means and cannot afford the batteries it chews through.  I had to develop a recovery plan, and fast.  Fortunately, all the pieces of the lens were still in place and nothing of any size had fallen out yet.  If I could only keep the lens together for the short term, I could then work out a longer term plan.  So I dug out a roll of clear packing tape.
You Can See Where I'm Going With This...
 I used a razor to trace around the lens and lightly pressed the tape around the glass.  This held things together enough so I could open up the flashlight and tape the back side together using the same method.  This would hold things together in the short term.

Next, I remembered from my research that Deal Extreme also sold flashlight parts.  I search for flashlight lenses and, lo and behold, they sell replacements.  Yay!  But the replacements come in 20 different sizes.  Time to dig out my calipers make a measurement.  Fortunately I had a banana handy to support one end of the caliper so I could free my hands to take a picture.
Better Eat That Banana - It's Getting A Little Ripe
The measurements vary from 41.6mm to 41.8mm depending on where I measured (smashing a piece of glass tends to affect its symmetry somewhat).  Not shown is my 1.5mm measurement of the lens' thickness.

Back to Deal Extreme.  And wonder of wonders: they sell a 41.5mm Diameter, 1.5mm Thick Replacement Glass Lens.  In ten-packs.  For $2.78.  For all ten.  And free shipping.  And no minimum order.  The well-intentioned recommendation of my cousin to consider somewhere else for a "decent light" falls on deaf ears.
This Makes Me Very Happy
So now that this post is written up, I'm off to put in an order to Deal Extreme.  Unfortunately, the "Add To Cart" button on that site is made of crack cocaine: you can't stop at just one hit.  I have a funny feeling I'll be spending more than $2.78.

Bad News and Good News

First the bad news. In my last post detailing how to build your own Davis console datalogger, I speculated that using a bigger memory chip than what Davis used in their original design might get picked up by the console and allow more archive records to be stored.  Unfortunately that is not the case.  The Davis 1 Mbit version tops out at 2560 records.  So does my 4 Mbit version.  If you are going to build your own (more on this in a second), save the 43 cents and stick with the 1 Mbit chip.
The Bane of the "Off by one" Programming Error
Now the good news.  When I got my DIY logger working a couple weeks back, I made a wxforum post detailing what I had found.  I made a similar post when I figured out how to build your own computer interface to the console, and comments poured in quickly.  This time around, it was a little different...
Kinda Quiet Around Here...

But little did I realize that despite the initial, deafening silence, great things were at work: wxforum member belfryboy put his head down and got busy.  After an iteration or two, behold!
A Schematic!
Yes indeed.  He did what I should have done and put together a schematic in Eagle.  This has a connection for both the Atmel flash chip for datalogging and a six pin connector for hooking up something like the Sparkfun FTDI cable.  These two pieces give you the complete equivalent of the Davis USB logger (except that this version will maintain a reliable connection).  Now, behold again!
A PCB Layout!
This is the corresponding board layout for the schematic above.  The ground pour isn't shown for clarity, and so you can see the shout-out that belfryboy gave me on the bottom layer.  This board is single sided and therefore DIY friendly.  Speaking of DIY friendly, the design can be easily pulled into the freeware version of CADSoft Eagle so that anybody can have a look and play around with this.  All you need to do is grab the design files from here and you are good to go.  And if you don't have the means to build your own circuit boards, belfryboy will build one up for you.

If you do build this, remember from my last post that you need to use a terminal program to actually activate the logging function in the console since Cumulus doesn't do this automatically.  I think I'll ping the author to see if he'd be kind enough to add this function.  belfryboy has a setup utility in the works and I'll add it to the design files once I get it.

So what the heck are you waiting for?  Get out there and build something.  Anything.  Figure something out.  Learn something new.  The reward is the journey.  Remember: You Can't, You Won't, And You Don't Stop.
 
My Earworm Of The Day: Now It Is Yours...

Saturday, November 12, 2011

Build Your Own Davis Console Datalogger!!!

It all started off with my seminal post, Davis Weatherlink Software Not Required, to which I added not one, not two, but three exclamation points to get across the enormity of the discovery.  With a $15 USB to Serial Adapter, you no longer had to pay the exorbitant sum charged by Davis to get a computer connection to your Davis weather station console.  Enthusiastic enthusiasts then charged ahead with several wireless solutions.  How about a wireless XBee link as written up by af4ex on this wxforum post?   Or what about gwynethh's Wi-Fi interface via the almost perpetually out of stock Roving Networks RN-XV (only $35!) as written up on this wxforum post?  If you don't think a weather station with its own TCP/IP stack is cool, then you have no soul.  Or you don't care.  One or the other.

But there were still murmurs of discontent in wx-land, and they centered on two bits of criticism.  The first, of course, was this was no plug and play solution.  Wires would need to be cut and soldering irons plugged in to get anywhere.  That was until SLOweather pitched in and started selling ready to go serial adapters based on the console logger pinout.  It is nice to know that this discovery enabled a cottage industry to spring up, though it must be said that it is an extremely small cottage.

The second criticism was that my hack did not have a data logging feature.  Indeed, this did suck.  I knew the pinout at the back of the console, but this wasn't enough for me to figure out how the logging function worked.
The Pinout That Started It All

It wasn't until I tripped over this post by wxforum member wxtech that things got really interesting.  This is a guy who obviously isn't afraid of letting the magic smoke out of his electronic devices.  He actually unpotted the Davis dongle to see what made it tick.  He wrote "U1 is an Atmel 45DB memory", and it was already well known that the logger had one megabit of memory.  That was all we really needed to figure out the datasheet for the Atmel 45DB011 Dataflash chip.

Technically, it all became clear with the datasheet in hand.  The console talks to the flash chip via I2C, and the remote PC talks to the console.  The remote PC is not directly connected to the flash chip.  That's why my homebrew serial interface works: the datalogger and interface functions are completely separate.  And that's why Davis brought out the I2C lines to the rear connector.

It gets better.  The 1Mbit version of the 45DB011 will set you back less than a dollar.  So you know what that means...
It Means A Cheap Excuse To Embed A Song I Really Like

After a summer spent preparing to feed the rabbits this winter, I got off my butt and ordered up some parts to see if I could make a DIY version of the Datalogger.  I ended up putting my order in to Mouser Electronics,  rather than the usual suspect.  The reason was quite simple really.  They were the only outfit I could find that both stocked 1mm pitch ribbon cable by the foot rather than the roll and also had an SOIC breakout board.  The flash chips can be found just about anywhere.  Here is what I ordered up.
  • A couple Atmel 4Mbit Flash Chips and a couple 1MBit Flash Chips to store my data.  I wanted to try an experiment here to see if the console could actually read chips of the larger capacity.  I bought a couple of each just in case I wrecked one. 
  • A 20 pin, dual row, 2mm pitch IDC header to plug into the back of the console.  I bought four of these to stock up.
  • A 16 pin SOIC to DIP adapter so I could prototype this on a breadboard.  Why 16 pins for 8 pin parts?  My plan was to solder on one chip of each capacity, and try the bigger one first to see if it would work.  This way I wouldn't have to mess with desoldering one to try the other.
  • Some 1mm pitch ribbon cable to connect it all together.  I bought three feet, so I could make a couple cables if need be.  Note that the pitch of the ribbon cable is twice as fine as the header, because it has to pack twice as many conductors in to the same width.
You'll need solder and a fine-tipped soldering iron, of course.  While I intend to buy myself a Hakko FX-888 at some point this winter, I continue to get by against all odds with a pencil-type soldering iron I bought at Radio Shack sometime in the 80's.  You'll also want some kind of solder flux.  I have a flux pen (looks kind of like a highlighter) and it works great.

This first shot at things was going to take a prototype approach in case I had any wiring incorrect.  A 1Mbit and a 4 Mbit flash chip were soldered to the SOIC to DIP adapter.  I followed the Curious Inventor's most excellent instructions for soldering these fine pitch components like I did when I built my GoodFET.

And here is how it came out.  The stuff that looks like water droplets on there is just some flux that didn't burn off.  This is way bigger than actual size, BTW.  4 Mbit on the left, 1 Mbit on the right.
Not Bad, Given My Crappy Eyesight
I would figure out only later that I screwed up the chip on the right: the 1MBit part.  See how this is a 16 DIP breakout and yet there are 24 connections to solder to?  The rightmost pads don't actually connect to anything.  They are apparently there just to mess with people's heads.

Undaunted, I next built up my cable to go from the console to the breadboard.  It is easy to build up your own insulation-displacement flat ribbon cables as you can see here.  All you need is a vise or some kind of flat clamp to apply even pressure across the connector as the insulation is displaced in each contact (hence the name, Insulation Displacement Connector).  It actually takes a decent amount of force to press these on, so don't think you can do it with your fingers or mash it on with a screwdriver.  That will just ruin the connector and make you angry.

Of course, Davis would throw a wrench into things.  The connection on the back of the console doesn't leave room for the top clip on the IDC connector or the key that makes sure you get the orientation right.  I had to pull the top clip off and use an Exacto knife to shave the extraneous plastic bits off.  That got the console side of the cable done.  On the other side, I tinned the wires and soldered them to some 0.1" breakout headers stuck through a piece of perfboard.  This gave me something that was fairly robust with lots of flexibility for future prototyping.
Turned Out Pretty Well, I Must Say

Next I had to wire things up.  Based on the datasheet and the expansion port pinout, I came up with this pinout to connect the console to the flash memory chip.
Console Pin   45DB0x1 Pin
1 - SS        4 - CS*
2 - SCLK      2 - SCK
3 - MOSI      1 - SI
4 - MISO      8 - SO
7 - RST       3 - RESET*
14 - VCC      6 - VCC
14 - VCC      5 - WP*
16 - GND      7 - GND
And now a word of caution:
Before you get all excited and start wiring something yourself, be aware of this: in the pinout diagram above, Pin 1 is shown on the bottom right.  If you use an IDC connector like I did, Pin 1 will be on the top right.  So the blue edge of the cable that normally represents Pin 1 will actually be Pin 2, the second wire over will be Pin 1, etc.  Now don't go blaming me for the confusion.  Way back when I was determining the pinout, I picked Pin 1 as I did because that one has the square pad on the circuit board where the rest are round (proof here).  So I called that pin to be Pin 1 because Davis did.  Now we are stuck with that.  Just remember that the console pin numbers shown above correspond to the diagram at the top of this post and you should be fine.
I wired the cable connecting to the breadboard to the 4Mbit part for my first attempt.  I then powered off the console and plugged in the cable.  Note that the console only looks for the logger on powerup.  If you plug it in after that, it won't be recognized.  Note also that Davis recommends that you enter setup mode before popping the batteries on the console (press and hold Done, then press the '-' down arrow button).

Here is what everything looked like plugged into my breadboard.
L-R: USB to Serial Converter, Cable to Console, SOIC to DIP Breakout with Two Flash Chips

So once I hooked everything up, I powered up the console and none of the magic smoke escaped from the station or my circuit.  A good sign.  I then fired up Cumulus, told it to use the datalogger, and set the archive interval.  I then shut Cumulus down and left it for 10 minutes, hoping to see archived data when I fired it back up.

Nada.

I did't get it.  When I fired up Cumulus, I saw the LED activity lights on my USB to Serial interface flashing like crazy for some length of time, but there was no data?  It didn't make sense.  I thought it might have been because I started with the 4Mbit part, but it did seem to recognize the chip or the converter LED's wouldn't have been flashing like they were.  I tried a bunch of things until I came across this post on the Sandaysoft forums.  Just because you specify to use the datalogger on the GUI and are able to set the archive interval, that doesn't mean that it actually configures the console to use the datalogger or sets the archive interval.

Argh.

That post said you "have to" use Davis' Weatherlink software to actually activate archiving and set the interval, but that isn't exactly true.  You just need the Davis serial protocol document I linked back in the original post.

Here is the magic incantations I entered. 
"SETPER 1": Sets archive period to 1 minute. 1, 5, 10, 15, 30, 60, and 120 are OK too
"START": Enables the creation of archive records.
Remember you need these commands to be entered using a terminal program set to 19,200 8N1.  Set half duplex to see what you are typing and make sure all commands ARE ALL IN CAPS.  Like this:
Activating The Logger... Hopefully

So I gave that a shot and fired up Cumulus again.  This time it spent less time looking for the data but actually showed a progress bar during the download - something it didn't do before.  And then I got this.
Six Records Is More Than Zero
Success!  Now ask Cumulus to show me some graphs:
First Third Party Archived Data Ever
w00t!  We are Free At Last!  And all it took was a few bucks in parts.  You can actually build something up even  cheaper than the route I took here.  You could use this SOIC breakout for less than two bucks, and you might even be able to take an Exacto knife to a 2.5" laptop IDE cable you have lying around that has the correct 2mm pin spacing.  Either way, you are in business for around $5 - $10.  That plus the $15 Sparkfun converter, and you've got a bulletproof console interface with data logging capability.  But of course it goes without saying that if you try to build one of these things and break your console in the process, then you get to keep both pieces and I will disavow all knowledge of your mission.

By the way, this is the capacity of the standard 1MBit data logger.
1 Minute Archive Interval . . . . . . . . .  . . . . . . . . . . . 42 hours
5 Minute Archive Interval . . . . . . . . . . . . . . . . . . . . . 8 days
10 Minute Archive Interval . . . . . . . . . . . . . . . . . . . . 17 days
15 Minute Archive Interval . . . . . . . . . . . . . . . . . . . . 26 days
30 Minute Archive Interval . . . . . . . . . . . . . . . . . . . . 53 days
60 Minute Archive Interval . . . . . . . . . . . . . . . . . . . . 106 days
120 Minute Archive Interval . . . . . . . . . . . . . . . . . . . 213 days
Will I get more capacity because I'm using a 4Mbit part?  I guess I'll find out in a few days.  I'll let you know in a future post.

So like the post that started all this off, the title of this blog also has not one, not two, but three exclamation points.  I thought it rated that.  Good luck to anyone else that gives this a shot.  I'll keep an eye on the comments for anybody who needs a hand.