Friday, March 23, 2012

Buzzing XBees

It's been a while since I've written, but I just have to share my experiences with this. I recently bought a pair of XBee Series 2 radios along with XBee Explorer break-out boards. I first heard about these radios in general back in school when I was working with CU's RECUV group, and then again in Tom Igoe's excellent book Making Things Talk, and I've been itching to try them out ever since. They're a bit like Wi-Fi or Bluetooth, but seem to lend themselves better to microprocessor projects, generally use less power, and have some unique features that are great for sensor networks. I understand they're also being used for modern home automation products.


However, getting these things configured and tested wasn't exactly a walk in the park! As it turns out, I probably should've gotten the Series 1 radios, as they use the simpler 802.15.4 protocol. Series 2 uses the Zigbee protocol, which allows for more advanced network topologies but is also harder to configure. In the end, though, it wasn't really that difficult, and I appreciate the greater flexibility, so I'm happy with my purchase. Because of my difficulty in the first few steps, I'm taking it upon myself to write a little about my lessons learned in getting these going.


Once I soldered headers onto the Explorer boards, my next task was to hook them up to USB-to-serial adapters to program them. There are Explorer boards with built-in serial adapters, but they're more expensive, and I already have a separate adapter. However, this meant I could only hook up one radio at a time, and it turned out to be very handy to hook up both. I eventually found a blog post that indirectly guided me to using my Arduino's USB-to-serial chip as a sort of pass-through. If you hook a jumper wire from GND to the RESET pin on the Arduino board, that effectively disables the ATmega chip so it doesn't interfere with the UART pins. (You can also remove the chip from the socket, but the jumper is easier.) After that you can hook up +5V, GND, and the two signal wires from the Arduino to the Explorer. In this case, the Explorer is acting as the UART's device, so you have to hook up RX to DIN and TX to DOUT in a straight-through configuration, instead of crossed-over as in normal device-to-device serial.


In that configuration, I was able to start two copies of the X-CTU configuration program (v. 5.2.7.5 under the General Diagnostics, Utilities and MIBs tab as I write), and start setting up the radios' software. On the opening tab, PC Settings, I set one copy of the program to each COM port (4 and 6 in my case) and made sure I could Test/Query both radios. My radios came set to 9600 baud.


After that, I started poking around in the Modem Configuration tab. By clicking Read, I was able to find out that both of my radios came loaded with the Zigbee Router AT firmware. If you read the Product Manual, you'll learn that a ZigBee network must have exactly one radio with Coordinator firmware, even for simple point-to-point connections. With that in mind, I changed one of the radios to a Coordinator by selecting Zigbee Coordinator AT in the Function Set dropdown box and then writing the new firmware. On both modules, I set the same PAN ID. In Zigbee (as opposed to plain 802.15.4), the 16-bit network address is either implicitly 0 for the coordinator, or randomly set for all other nodes, so those fields aren't editable. Since I'm starting with a point-to-point network, for both modules I set the destination address (DH and DL) to the serial number (SH and SL) of the other device.


I could be forgetting something, but that should be enough to get point-to-point communication going. From the Terminal tab on both windows, I'm able to type on one side and watch the other side receive. In the photo, blue is what I typed, and red is what was received by the other radio.


Once all of that was established, I decided to hook up the radio to the Arduino "for real." To switch the Arduino from a pass-through to a microcontroller, I just removed the wire from the RESET pin, and swapped the signal wires so that I had RX to DOUT and TX to DIN (as in normal, crossed-over serial communication). After that, I loaded the Arduino with a simple program using the Serial object. The sketch just listens to serial in, and when it gets a byte, increments it and writes it back out.


As you can see, the module attached to the computer (and visible through the X-CTU window) sends a letter (in blue). The radio attached to the Arduino gets the letter and passes it to the Arduino. The Arduino increments the letter, passes it back to the attached radio, which sends the new letter to the computer's radio and back to the terminal (in red).

That's the extent of my exploration so far. Nothing too exciting, but I'm quite pleased that I'm this far. Next up, maybe I'll control a servo on one Arduino using a potentiometer on another. We'll see!

Sunday, October 9, 2011

My Robot Friend

It's been a bit since I've posted, but fear not! Things are going well, and some exciting things are taking shape!

Work is as exciting as ever. There are new challenges almost every day it seems, yet nothing that seems to be impossible. Our systems environment is ever-changing, and the causes and motivations are numerous, but it's all in a day's work. I've also taken it upon myself to start implementing measurable quality metrics in my work, and that has been an interesting journey. I'm starting to learn a number of tools and techniques for automated building, testing, and deployment, and those are skills that should serve me anywhere on any project.

Outside work, I got the itch to do some engineering mentoring, and so I got a hold of my local high school. They don't currently have any programs like the old "computer club" that I attended when I was there (it was really just 3 or 4 of us that would hang around in the computer lab after school). However, just as I contacted them, the tech lab teacher was gearing up a team for a robotics competition called BEST. Basically, over a 6 week period, the team of high schoolers must design and build a fair-size robot (maximum 2 feet cubed) out of basic provided materials, like plywood and PVC pipes, plus an electronics kit. The robot must then perform certain game tasks in competition. I've been volunteering my time with them, and I'm really having a blast, even if there isn't all that much programming. Many general engineering principles, like designing to meet goals and building prototypes, are still useful. Maybe after the competition, I can keep something going through the rest of the school year. We'll see.

Sunday, September 11, 2011

Ten Years Ago, Today

I was in the 10th grade. The morning started off as any other, with my morning bike to school. My first class was Spanish. There were rumors of confused news reports about a small plane accidentally glancing off of the World Trade Center, but our teacher would allow no distractions. Our class plowed through the planned material.

But when I arrived at 2nd period chemistry, it was clear that this was no normal day, no small news story, and no accident. Our chemistry teacher didn't say much, and didn't attempt to teach class. We listened to the radio reports from shocked and confused journalists in New York. We heard that commercial airliners had been hijacked and crashed into the towers and the Pentagon; that both towers had just fallen; that the streets of Manhattan were rivers of dust and ash; that tens of thousands were injured, trapped, or dead.

It took time for the magnitude of the reports to crystallize in my head. This had happened on American soil? The shock was profound to me, a teenager who had never heard of a disaster of this scale in my own country during my own lifetime. The next few hours are now just a blur, but I know the question eventually solidified: what was going to be attacked next? Every feeling of comfort and safety was shattered, for myself and everybody around me.

I remember sitting with friends in the school cafeteria at lunch time. Half of the students had already left school. In my recollection, there was no official release by the administration, but our teachers were also in shock, and knew that on this day, nobody was thinking of anything else. Some kids had left or been pulled out by their parents so they could be with their families. Some kids left because they were afraid that the school might be targeted, images of Columbine High School still fresh in their minds. Other kids didn't immediately grip the gravity of the event, saw the reign of chaos in the school, and left because they smelled the opportunity for a day of freedom.

When I got home, I sat in a daze in front of the TV news reports. The hijackers had been foreign terrorists. My train of thought was, "Really? Who would want to do that to us? We're Americans! We have our faults, but no one actually hates us, do they?" There had been four planes, and one had mysteriously gone down in a field in Pennsylvania; there were hazy reports that the passengers might have fought the hijackers and forced the plane down. The whole thing was entirely surreal.

The end of the day seemed drained of hope, but over the next weeks and months, I saw the country come together in strength and hope. Out of the wreckage, miraculous stories of heroism, courage and compassion emerged. For every mention of the innocent lives lost, there were tales of the brave people that selflessly gave for their fellow human beings. That day touched the life of every American, and I like to think that we've become better for it, as a nation and a people.

Sunday, July 10, 2011

Google Map Maker

For those that don't know, Google Maps just opened up the Google Map Maker web application to allow normal users to enter data into Google Maps. After a review process, those edits can be published into the public Google Maps for the world to see. I was pretty excited when I learned about it in April, and I've been pretty active.

Recently I received an e-mail from the Google Map Maker Community Team. Because I'm "one of the top mappers in the United States," they offered to send me a free t-shirt, and invited me to the Google Geo User Summit in Mountain View. I had to regretfully decline the offer to attend the summit, but the t-shirt is pretty awesome.

From July 2011

My friends and I were trying to figure out what the map on the front is showing. At first glance, it looks like a map of the world's lights at night, but some major countries, like the US, Canada, UK, France, and Russia are not lit up. So what do the white areas represent? My speculation is that those represent major road systems that Map Maker users have added which were not previously recorded in Google Maps, but I'm not sure. Does anyone know?

Friday, July 8, 2011

Graduation Videos

Check these out! Courtesy of Munchkin, thanks friend!



Sunday, July 3, 2011

Exploring Google App Engine with Restlet and Objectify

Warning: this post is excessively geeky for my usual audience. Non-programmers, feel free to skip.

I've been doing a little more exploration with Google App Engine. I've used it before, first for my Weasley Clock, and also for one of my classes, Object-Oriented Analysis and Design. In that OOAD class, my team and I had a short amount of time to build an Android app backed by a RESTful web service on GAE. We ended up using JAX-RS/Jersey as a RESTful framework, JAX-B for server-side XML serialization, and JDO for the datastore API. Then on the Android client, we used the Apache HTTP client and SAX parsers. That worked out alright, but recently I've wanted to explore what other options are out there.

I've been interested in Restlet for a while; in OOAD, I explored that first before moving to JAX-RS. It seems to be a pretty comprehensive solution. They provide both server and client libraries for many platforms, with flexible configuration for many needs, such as filters. What turned me off last time, and almost again this time, was that the source code for the "first application" example didn't work out of the box. I had to decide which version of the library I needed, download four different editions, and figure out which .jars to put where. Then for a long while, I was stuck on an interesting bug. Apparently, GAE doesn't support chunked encoding (whatever that means), so their current stable 2.0.8 libraries won't work for GAE/Android communication. Their 2.1m5 libraries have a workaround, but one must manually specify that entities must be buffered (once again, what?). I also paired their 2.0 "first application" example with 2.1m5 libraries without realizing that there was a difference, because their wiki wasn't clear about which version of the sample application you were looking at.

So far, I would say that Restlet is a well-built library for RESTful communication, both server and client-side, but their documentation and examples could really use some organization help. The answers are on their site, but sometimes they seem to be hidden away in dark corners of the wiki.

After I got the Restlet "first application" working, I wanted to bolt on datastore support. I wanted to try something other than JDO, and so looked at JPA. However, these both seem to be cumbersome and ill-fit when it comes to the GAE datastore. Then somehow I stumbled across Objectify, a relatively thin library that works on top of the datastore low-level API. Some of the attractive features were a less-cranky Key interface, using POJOs instead of GAE-specific Entities, and GWT compatibility without DTO's. I did have trouble with that GWT part for a while, because I thought that my POJOs still needed to be annotated with java.persistence.Entity. I think that was causing problems when the DataNucleus Enhancer went and did its magic; the server-side class looked different than what GWT was expecting on the client side, which ended up throwing a SerializationException. However, I finally figured out that stored entities don't need the Entity annotation. The only thing that the POJOs need is a java.persistence.Id annotation on the primary key field.

I have yet to really explore this thoroughly, but so far both libraries seem to be doing their job and playing nicely. The best part was not having to write DTOs! I did have to fight with both libraries for a while, but hopefully this post will help somebody else avoid those pitfalls.

Thursday, June 23, 2011

Hit the Ground Running

My time between finishing school and starting work was relaxing, but too short, of course. I did keep myself busy with projects, planning for our first camping trip of the season, and preparing for work. I was able to get some stepping motors to ressurrect the Wesley clock. I finished all of the software last summer, but still haven't gotten around to building the darn thing!

I started work the week before Memorial Day, so it was a fairly relaxing time to come in. So far I like the people, and the work is interesting. My co-workers are a pretty tight-knit group and have some nice traditions. "The Phat Club" is an agreement among about a dozen people to bring in breakfast for everyone else once a week on a rotating basis. Every day at a certain time, everyone who isn't busy with something will take a short walk down to the "snack room" to stretch our legs and shoot the breeze. Some of us even took an afternoon off to see a Rockies game. That was a lot of fun!

One thing that's in stark contrast to my previous experiences is the level of isolation. Communication is restricted in order to protect proprietary information, so we can't have cell phones inside our building. It's a little unnerving, but it's a necessary evil and I'm learning to adapt. But there also seems to be some technological isolation. I don't know if it's just my project, but there's a lot less use of libraries and frameworks than even some of my school projects; instead, everything is built from scratch. It's well-built from what I can tell, but open-source frameworks have the advantage of public scrutiny, industry approval and large support communities. Working on this project could certainly be a learning opportunity in relying on my own design and coding ability, but I will need to spend time outside work to keep my finger on the pulse of the industry.