alexba.in

A technical blog about open source hardware and software.

Native Gem Extensions Failing to Install

| Comments

Recently I’ve had trouble installing native gem extensions on my OSX 10.8.2 laptop. It appears that some gems are specifically looking for /usr/bin/gcc-4.2 and fail to compile if that’s missing. When I checked /usr/bin I could only find /usr/bin/gcc.

I tried creating a symlink to gcc-4.2 and everything installed correctly:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

Hope this helps someone!

ArduSat: Doing It.

| Comments

I’ve been enamored with space for as long as I can remember. The barrier of entry for space/satellites, however, has always been a bit outside of the individual’s grasp.

Until now. The other day I stumbled across an amazing Kickstarter project - the ArduSat. The goal of the project is to be the first open platform for individuals to design and run their own space experiments. Yup. That’s right. For $325 you can now run your own space experiments.

For the first time you can get access to a satellite and execute whatever code you like to gather data, run experiments, or otherwise just take photos from space. It’s an amazing idea and one I’m proud to say I’m a backer of.

I haven’t decided what to do with the time yet. Since photography is such a passion of mine, however, I’d love to find some way to analyze the surroundings, determine if something interesting is happening, and start taking photographs. Given that the user has good control over the camera I was thinking that some HDR shots might end up being beautiful.

Hopefully my output from this will be a beautiful print I can hang in my home to remember the first (of many, I can only hope) time I was able to run code in space.

Universal Remote Experiments

| Comments

Over the past few months I’ve decided to teach myself a bit about embedded microcontrollers and electronics. I’ve never worked with hardware before and, after a bit of Googling, found an amazing Maker / Open Hardware movement going on that I could leverage to help bootstrap my ideas.

Since I’ve found the best way to motivate myself is with a concrete project I decided that, for my first project, I wanted to build a universal remote that I could control from my phone. I have a Harmony remote, which I use regularly, but it’s limited by line of sight and requires customization through a cumbersome software interface.

My initial requirements were:

  • Must be small enough to place discreetly in the room
  • Must be WiFi enabled
  • Must have great IR range and coverage
  • Must be able to learn existing commands
  • Must have a responsive web interface

Version 1: Arduino

The first prototype I built was using an Arduino Uno microcontroller along with Ken Shirriff’s multi protocol IR library. I had wired a 940nm IR LED to one of the Arduino’s pins and was able to get about two feet of range out of it.

Next, I extended the code and attached a Roving Networks RN-XV WiFi chip to my project so it was WiFi enabled. So far so good. I could now send or receive IR commands (relatively well, it wasn’t perfect) over Wifi with about a two foot range for the IR signal. I also had to hard code the WiFi credentials which meant the device wasn’t very portable, but at least it worked. This was version 1.1.

Version 1.2 was an updated hardware schematic that added a 2N2222 transistor to the mix. Using a transistor meant that the output from the Arduino’s pin was not trying to power the LED but just telling a transitor to switch current on and off. Since the transistor switches current significantly better than the output pin of the Arduino I was able to extend the range for the IR blaster to about 15ft. This change was inspired by open source schematics like TV-B-Gone.

Version 1.3 was to be the version with the web interface. This was where I realized the limitations of the Arduino platform. I could not easily run a WiFi libray, an IR library, and a web server off of an 8bit micro controller. I simply didn’t have the resources.

I had considered a few alternatives:

  • Run a webserver on my laptop and just send commands to/from the Arduino
  • Run a webserver on the internet and relay commands that way
  • Purchase a device like a RaspberryPi or Beaglebone and run the web server on that device. Communicate with the Arduino perhaps via XBee or over WiFi.

Ultimately I decided that adding a second device increased the complexity of the project beyond what I wanted. So, I scrapped the idea of using an Arduino and I’m starting over with a RaspberryPi.

Version 2: RaspberryPi

The RaspberryPi is a completely different beast than the Arduino. The RaspberryPi is about as powerful as a mobile phone. It’s got an ARM processor, ethernet port, RAM, SD card for storage, and a bunch of GPIO pins for a hardware interface.

So first up was finding an IR software package (designed for a Linux OS) that could handle the transmission and receiving of IR signals. This lead me to LIRC - the Linux Infrared Remote Control project. This project has been around for a while, has a bunch of hardware schematics available (sending and receiving) for it, and is open source. Perfect.

This lead me to getting LIRC working on my RaspberryPi. Luckily a chap who goes by the name ar0n has already opened a pull request that adds preliminary LIRC support to the RaspberryPi linux kernel.

So, at this very moment, I am attempting to recompile the RaspberryPi linux kernel with LIRC support. Once this step is done I’ll wire up some hardware to test sending and receiving. Once that works I should be back to “adding a web platform” which will be significantly easier when powered by an entire Linux stack.

I’ll post another update down the road once I’ve gotten this step working.

Testing for Missing Images in JavaScript

| Comments

Recently I had to determine if an image URL was properly rendering or not. Since this image URL was provided by a user there was a chance that it had been deleted or moved since they first set it. In that case I wanted to show a different image - perhaps a “missing user” image - rather than just an empty box.

My solution was to bind a callback to the onerror event that fires on an Image object if the image source could not be loaded. By binding a callback to this error I was able to replace a missing image with an image of my choice.

Here’s a sample implementation that binds a callback onto the onerror event:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var checkForMissingImage = function (url, callback) {

  // Create an Image object in memory
  var img = new Image();

  // Bind the callback to the onerror event
  img.onerror = function() {
    callback();
  };

  // Set the src of the image to the url provided
  img.src = url;

};

Here’s an example that involves replacing all images with class userpic on a page.

1
2
3
4
5
<!-- Userpic that will render as a missing image and needs replacing -->
<img src="http://brokenhost.com/does_not_exist.png" class="userpic" />

<!-- Userpic that will render properly -->
<img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/200/287.jpg" class="userpic" />
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$(function() {

  // Define a custom image to replace all missing images with
  var replacementImage = 'http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg';

  // Find all userpics on the page
  $('.userpic').each(function (i, userpic) {

    // Create a cached reference of this userpic
    var $userpic = $(userpic);

    // Get the source of the userpic
    var src = $userpic.attr('src');

    // Check to see if this image still exists. If it does not exist, execute
    // the callback function and replace it.
    checkForMissingImage(src, function() {

      // Update the missing image with our replacement image.
      $userpic.attr('src', replacementImage);

    });

  });

});

As onerror support isn’t universal across every browser this should be considered a visual enhancement for users with modern browsers.

Undefined Macro: AC_PROG_LIBTOOL

| Comments

While trying to install LIRC on my RaspberryPi I ran into this error:

configure.ac:24: error: possibly undefined macro: AC_PROG_LIBTOOL

The solution that worked for me (on Debian Wheezy) was:

sudo apt-get install libtools

Hope that helps someone else out there.

Opening Chrome From the OSX Terminal

| Comments

Have you ever wanted to open an HTML file in Chrome, directly from the OSX terminal? I have. Here’s how to do it:

  • Open ~/.bash_profile in your editor of choice.
  • Append this to the bottom of your ~/.bash_profile:
.bash_profile
1
2
3
  chrome () {
    open -a "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" "$1"
  }
  • Save and close the file.
  • Run source ~/.bash_profile from the terminal to reload it.
  • Enjoy being able to type things like chrome index.html from the terminal.

TTI: Time to Information

| Comments

Information. Not long ago information was scarce. If you needed information you’d have to embark on a quest to seek it out. You’d go to a library or book store, search for a book, (hopefully) find one, and read it. Perhaps you were lucky and the first book you read had the information you needed. If you weren’t lucky and you still had the drive to continue, you could try again with another book or resource. It could take days (or weeks) just to physically find the information needed. That does not include the time required to parse the information once in your possession. Information’s physical location was a fundamental limitation to the speed with which information could be parsed and understood.

Then, late in the 20th century, something amazing happened. Information was liberated from books and became something that machines could parse. Information stored on machines could be called up and presented on our screens in a timescale measured by minutes or seconds, not days or weeks. You could store thousands of books on your computer and search through them at blazing speeds. Now, in the 21st century, information no longer needs to reside on a machine you own. Information can be found on any machine connected to the internet. The world’s information is fast becoming a digital commodity that is accessible simply by moving our fingers across a keyboard. We are no longer obligated to go to the information - the information can be delivered directly to us, at any time, in high definition, at no cost. Information is now mobile.

The astounding technological accomplishments that go into delivering information directly to your screen, while insurmountably fascinating, are not what this article is about. This article is about my personal explorations in developing a terminology that can adequately describe and measure the human ability to find and parse the information available to us.

I don’t claim to have any answers. I don’t even claim to have developed a definitive terminology. I simply find this topic so fascinating that I can’t help but ask the questions and try to answer them. With further research and trial and error I hope to develop a series of techniques and tools to allow for more efficient information retrieval, presentation, and parsing. The ultimate goal of this pursuit is to find (or create) mental or technological hacks to minimize the time between a thought and knowledge.

So, with a goal clearly outlined, it’s time to define a metric to measure progress towards the goal. Why define a metric? I firmly believe that unless you have a way to measure progress towards a goal, you’ll be unable able to tell if you’ve succeeded at your task.

Defining Time to Information (TTI)

The initial metric I’ve been using has been “Time to Information.” I’m defining Time to Information (or TTI, as I’ll refer to it from now on) as the length of time between when you decide to seek out a piece of information and when you have processed enough information to consider the thought resolved.

Time to Information: Within your control

There are at least four factors involved in information retrieval that are in your direct control.

  • The amount of self control you have to stay focused on the task at hand.
  • The services you select to find your information.
  • The speed with which you can parse the information returned by the services.
  • The time it takes to process the parsed information and determine if it resolves your thought.

Time to Information: Outside of your control

As this metric is primarily geared towards information retrieval over the internet, which relies heavily on third party services, it would be remiss not to at least articulate a few aspects of TTI that are not in your direct control.

  • The availability of the service.
  • The network latency between you and the service.
  • The quality of information the service contains.
  • The relevancy of the information returned from a service when given a well formed query.
  • The usability of the interface presenting the information.

Each of these aspects have a huge potential impact on TTI. If a service performs poorly enough in any of these categories I believe improving upon it will provide a benefit to user experience and satisfaction. In the coming years, as the number of information services multiply, I think that services which present well formatted, relevant, easy to understand information will have a competitive edge against those that do not.

Measuring Time to Information

This is the next step. I need to develop a way where I can painlessly log the timestamp of the “start” of a thought and the timestamp where I’ve acquired enough information to call it resolved. I’ll also need to find ways to categorize and represent these thoughts with data such as:

  • Device used
  • Tool or service used
  • An “ease of use” index to measure an overall quality of experience?
  • ???

If you have any suggestions or ideas on the kind of data that would be relevant in this exploration please get in touch.

I do have an initial idea to start logging this data. I’ll post that idea as well as some initial findings in the coming weeks as I find time.

Adventures With Microprocessors

| Comments

I’ve always been fascinated by embedded systems but haven’t taken the time to dive into them or hack on ‘em. Over the past few weeks, however, the Arduino platform caught my eye and I’ve started reading about it and understanding what it’s capable of.

My verdict? It seems like the perfect introductory platform to start measureing sensor data. So, last night I took the plunge and purchased the Inventor’s Kit from Sparkfun electronics. It should arrive next week (right before I leave for France!). I’ll take some unboxing shots when it arrives. I can’t wait to experiment with it and start hacking together some novel ideas. I plan to post all of the code I write in a GitHub repo for others to grab and run with.

However, to get my feet wet, I busted out a TI eZ430 Chronos watch that my good friend Jeff gave me a while back and started playing around with it’s default firmware. I’m not able to do anything too exciting yet, since I don’t have the firmware reprogrammer, but I was able to capture some of the button events from the watch and route them out to Pusher.com, a free WebSockets API.

The next step is to write a Chrome extension that watches for those WebSockets events and does something interesting. I’ve got a few ideas and I’ll post about them here once it’s up and running.

If you’re curious, check out the Ruby script that gets the watch talking with Pusher.com.

JavaScript Equivalence Operators

| Comments

JavaScript has two sets of equivalence operators. One set is type converting while the other set is strict.

Here’s a quick example that demonstrates these two types of operators:

Equivalence operators in JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> var a = 4;
4
> var b = 4;
4
> var c = "4";
"4"
> a == b
true
> a === b
true
> a == c
true
// fails due to type mismatch
> a === c
false

The key point is noting that while a == c is true, a === c is false.

Why? When using the == operator the string "4" is type cast into a 4 which is compared to 4. As 4 is equivalent to 4, this evaluates to true.

However, when using the === operator the string "4" is directly compared to the number 4. This fails because a String is not equivalent to a Number.

Here are the specific rules that the JavaScript interpreter follows:

If either operand is a number or a boolean, the operands are converted to numbers if possible; else if either operand is a string, the other operand is converted to a string if possible. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory. Mozilla Developer Network

So, if you’re ever trying to figure out why a comparison is evaluating to true when it should be evaluating to false, double check that you’re not accidentally type casting one of the operands.

Want to dive deeper? Check out these articles for even more information:

First Post

| Comments

Hi!

I’ve started this blog to document the things I find of interest in the realm of front end web development (JavaScript, CSS3, HTML5), Ruby on Rails, and Cognitive Science.

My hope is that you’ll find some of these posts either interesting or educational.

This blog is powered by:

Considering Octopress? I’d recommend it. My first impressions of Octopress are very positive. It’s easy to setup, easy to configure, and very customizable. As long as you’re comfortable with the command line, Markdown, and GitHub, it’s a fantastic option.

As time goes on I’ll be implementing some theme/front end tweaks I have in mind.

Want to look under the hood? Feel free to explore the source code.

Thanks for stopping by. Please subscribe to the RSS feed to follow future updates.