I’m spending the day today at IndieWebCamp SF Decentralized Web Hackers Day hosted in Mozilla’s San Francisco office as a lead-up to this week’s Distributed Web Summit.  My personal adventure today is getting up to speed on IndieWeb basics and enabling as many of them here on orangemoose.com as time (and trial & error) allows.

Decentralization is one of the core aspects of the IndieWeb, which aims at enabling a people-focused alternative to today’s very (if not alarmingly) centralized “corporate web”, but doing so by applying familiar, existing technologies in careful ways that keep the user in control of their data including identity, posts, code, created content, location, and more.

Happily today’s Hackers Day is set up to encourage hands-on experimentation and adoption, and the room is full of wonderfully knowledgeable people eager to help.   Look for another post after the day is done, and we’ll see how well I do.

Exploring Arduino Interrupts

I’ve been wanting to add wind & rain sensors to my home-built Arduino-powered weather station and thanks to a recent sale at Sparkfun have acquired their nicely-built set.  As a result, though, I have two interesting problems to solve in getting those sensors integrated to the temperature and barometric pressure ones I have deployed today.  First, I need to work out where and how to install the wind/rain sensors as placement is critical in getting good readings  Of more immediate concern, however, is that I need to rethink my weather station application in order to properly integrate the new sensors, especially the anemometer and rain gauge.

At the moment my weather station code uses basic clock timing to read temperature and barometric pressure sensors periodically, average their values, and display the readings on a small attached OLED. Temperature and pressure sensors are continuous so their values are always available and can be read whenever desired just based on the Arduino’s internal clock. While my new wind vane sensor also provides a continuous reading, the new anemometer and rain gauge don’t work that way.  Instead they report data discontinuously whenever they have something to share.

In the case of the anemometer it closes an internal switch every time the cups rotate through one revolution.  Deriving wind speed from the anemometer means counting the number of revolutions over some specific period of time and calculating the number of revolutions per second. Multiplying revolutions-per-second by a fixed factor based on the size and geometry of the anemometer lets you determine average wind speed over that period of time.  You can’t simply poll the anemometer and ask it to tell you what it is observing as you can with temperature, pressure, or wind direction sensors.

Similarly the rain gauge can’t provide a continuously-available reading, but instead closes a switch every time its internal self-emptying bucket fills and dumps.  The volume of the tiny bucket is known, so keeping track of how many times it has emptied over a specific period of time lets you figure out how much rain has fallen.

Therefore a different approach is needed to read sporadic sensors like the anemometer and rain gauge and keep track of every time their internal switches close, whenever that turns out to be and no matter how often.  The asynchronous, switch-closing nature of those sensors is a perfect case for interrupt-driven data gathering.

A good overview on interrupts and how they work on Arduino is available over at EngBlaze. In my case I need to modify my weather station code to add logic to handle the calculations to be done whenever either the anemometer or rain gauge closes their internal switch. Just as with reading my other sensors, I need to devote an Arduino pin to each of the anemometer and rain gauge so I can detect their respective switch closures.  This turns out to be pretty easy as Arduino has already set aside pins to handle two external interrupts: interrupt number 0 (or INT0) on digital pin 2 and interrupt number 1 (or INT1) on digital pin 3.  All you need to do is connect the interrupt-generating device to one of those two pins, write a simple handler function you want to be called every time an interrupt occurs, and use the special built-in attachInterrupt function to associate your handler with the chosen pin.

A simple example is provided in the Arduino reference for attachInterrupt(). Here’s another one aligned with my intent to use interrupts to read my anemometer and calculate wind speed:

 * Example program for Arduino external interrupts, in this case to read
 * an anemometer connected to digital pin 2 (which is INT0).
 * Author: David Bryant (david@orangemoose.com)

volatile int interruptCnt = 0;  // Counts anemometer interrupts

unsigned long sampleDelayMs = 30*1000; // Sample interval, milliseconds
unsigned long prevSampleMs = 0;        // Timestamp for previous sample

void setup()
  Serial.println("Gathering data...");

  // Attach our interrupt service routine to INT0

void loop()
  unsigned long currentMillis = millis();    // Get current timer value
  /* See if it is time to calculate wind speed */
  if( (currentMillis - prevSampleMs) >= sampleDelayMs) {
    Serial.print("Anemometer count: ");

    prevSampleMs = currentMillis;   // Remember clock time
    interruptCnt = 0;               // Reset counter

 * Interrupt service routine called when the anemometer switch closes.
 * All it needs to do is increment the interrupt counter.
void anemom_cnt()

This works well enough and is quite straightforward, but I’m not completely happy with it.  To add my anemometer and rain gauge I need two interrupts, but I’d like to make broader use of interrupts in my weather station code. For example, I’m currently using a push button to step through a series of screens on an attached OLED so a user can browse a variety of information from the sensor including maximum and minimum readings, system statistics, etc.  At the moment that push button is read periodically as part of the sensor timing loop but it’d make more sense to have it generate an interrupt to trigger stepping to the next screen.  It may also make sense to use interrupts to handle other sensors I could add, or support other system functions. Using all the available external interrupts just for the anemometer and rain gauge seems short sighted.

Happily the Arduino supports handling interrupts on every pin, both analog and digital, through a different mechanism than INT0/INT1 and their attachInterrupt function.  That means there’s lots of room for expansion, but it requires a bit more low-level knowledge and coding.  That’s a good subject for another blog post…

Thanks to special help from a good friend my son and I had a chance to attend this year’s PAX Prime conference.   In 2004 Jerry Holkins and Mike Krahulik, creators of the “Penny Arcade” web comic, decided the world needed a conference solely dedicated to celebrating gamer culture and the Penny Arcade eXpo (PAX) was born.  Originally hosted just in Seattle, PAX is now a global phenomenon with events in Boston (PAX East), Melbourne Australia (PAX Australia) and still in Seattle (PAX Prime).  As long-time game players my son and I had talked about attending PAX but had never managed it, so were absolutely delighted when the opportunity arose this year.

Naturally the first year at a conference is a major learning experience, especially a large and diverse one like PAX Prime.  We were only attending for just over one day out of the four days overall so had to make some compromises in what we attempted to do.  Here are some highlights of our rookie experience, which will definitely help us plan for return visits (if we’re lucky enough to get tickets) and perhaps inform others as well.

See new games – Game publishers like to use PAX to showcase games that are close to being launched. This means attendees have lots of opportunities to take a look at pre-released game content. This year we saw/played “Borderlands 2: TK Baha’s Bloody Harvest“, “XCOM: Enemy Within“, “Wolfenstein: The New Order“, and some great indie games such as “Escape Goat 2” and “Audiosurf 2“.

Try existing games – In addition to unreleased games PAX offers ample opportunity to play current games that you just haven’t had the time (or money) to try.  We checked out “Dragon’s Prophet“, “Assassin’s Creed IV“, “The Bureau: XCOM Declassified“, “Rogue Legacy“, “Portal 2“, “Left 4 Dead 2“, and “Transistor“. Often these games are used to help demo gaming gear in vendor booths.  The NVIDIA booth was a great place to play games while at the same time see new graphics cards and handhelds.

Visit the Free Play areas – When you need a break from the expo and panels go find one of the free play areas and plop down in front of a PC or console to unwind with some games.  The PC area has hundreds of high-end machines each with dozens of pre-loaded games and while we didn’t visit the console area I presume it’s equally large.   Free play is limited to 45 minutes at a time so while there may a line of folks waiting for a chance to play the line moves pretty steadily.  The area is managed by a timekeeper that can allocate groups of people to adjacent available computers, enabling co-op group free play if you like.  (We had all kinds of trouble with the voice chat set-up so being next to each other is the only way you can game together.)  Free play areas are open late into the evening so you can get in some game play after the expo closes and panels end, though lines are longer then as a result.

Check out new gamer gear – Vendors like Corsair, NVIDIA, Skullcandy, Kingston, and Logitech, are on hand to show off current and new gaming gear including graphics cards, keyboards, mice, headsets, and accessories (like the Stinky Footboard and Cooler Master Skorpion). It’s great to be able to ask in-depth questions, try everything out, and compare performance in real game situations. You may also be able to take advantage of special show prices or packages.

Go Indie – The “Indie Megabooth” is a special area of the expo set aside just for indie games, and you should definitely spend time there to talk to the developers and share in their creative energy.  Equally important is the “PAX 10“, a collection of ten indie games selected by a panel of experts for exemplary game play and fun.  The PAX 10 was not part of the Indie Megabooth so we made sure to reserve time to see both areas.

Decide how much you want to stand in line – Mobs of people will stand for hours in long lines just for a glimpse at a new game or a chance at some special give-aways.   Ask what a line is for and decide how long you’re willing to wait.

Collect & Scavenge – Acquiring and trading collectable pins and buttons has long been an aspect of PAX Prime and it has become a formal part of the conference through “Pinny Arcade”. You’ll see lots of folks wearing lots of pins and buttons, and they’re generally looking to trade to grow their collection. Also, several vendors offer scavenger hunt promotions in which you need to visit different booths, collect stamps or information (or both), then redeem the full set for some prize.  PAX Prime does this too by hiding special QR codes throughout the venue and encouraging you to collect them all and earn a special “PAX XP” prize.

Overall PAX Prime was an extraordinary experience and is well worth attending for any gamer even if you can only get there for a day.

I’ll have more to add in a separate post on my impressions of particular games and gear.

One of the things that attracted me to the Raspberry Pi from the beginning was their announced intention to make an add-on camera module available. It took a while but I finally received notification that they were in stock so quickly jumped on-line and placed an order.

While waiting for the camera to arrive I prepared by reading through all the camera-board postings on RaspberryPi.org, studying the official documentation, and watching the installation video. By the time the box arrived I was sure I was ready.

Installation of the hardware was not particularly difficult though does require care to make sure the ribbon cable is oriented properly with the exposed contacts facing away from the Ethernet connector.  (The video spells this out very clearly.)  Once installed the camera looks like this:

Raspberry Pi & camera

Setting up the camera software is also straightforward. First, update to the latest Linux kernel and system software:

Then enable camera support by using the raspi-config utility:

You’ll need to use the cursor keys to select the ‘enable camera’ command and confirm that’s what you want to do.  Exiting raspi-config prompts for a reboot, which is required to alter GPU operations so the camera works properly.  Eagerly I waited for the reboot, logged back in, and tried to take a picture using the command line utility:

Instead I received a cryptic error message:

This wasn’t covered in the camera documentation and I had no idea what ‘vchiq‘ was.  Naturally I did what you always do in situations like this – google the text of the error message and see if you can find anything to help explain what to do.  Happily I came across a blog post describing exactly the same situation and with a fix, namely that the user must be a member of the ‘video‘ group. This can be accomplished as follows:

Eagerly I logged out and back in and tried the raspistill command again.  Voilà, the view out the window near my workbench as my first test image:

Test image

More to come…

For the record the blog you’re viewing is based on the open source WordPress content management system, which is widely used for blogs but also has broad, general web site capabilities. WordPress enables easy customization through add-on themes, hundreds of which have been created by the community and shared freely across WordPress sites.  I’m using the ‘Admired‘ theme by Brad Thomas with its Orange skin, plus some minor modifications by me to better match the rest of orangemoose.com and suit my personal tastes.

Most of the content is rendered using the open source ‘PT Sans’ font by ParaType, available through Google Fonts.  The page headline, footer content and some other random bits use the open source ‘Mountains of Christmas’ font by Tart Workshop, also available through Google Fonts.

Where I need to embed source code in a post or page I’m using the ‘SyntaxHighlighter Evolved‘ plug-in for WordPress, based on a nifty JavaScript package by Alex Gorbatchev that can also be used separately in web applications and content beyond WordPress.

Oh, and all this is running on DreamHost, a web hosting provider that came highly recommended by friends. I’m still learning my way around their services but I’ve been very impressed so far thanks to the open environment and excellent compatibility with the tools necessary to create content and manage my site.

Welcome to my “new” blog.  Part of the overall reason for orangemoose.com is to provide a place for me to capture and share what I’m up to, both just generally as part of my work, home and hobby life, and for any of the steady stream of projects I can’t seem but help to undertake.  I’ve made attempts at blogging before, first on Tumblr and then on WordPress.com, but failed to develop the regular habit of posting. That struck me as odd as I post to Twitter quite frequently and often struggle to fit my answer to Twitter’s “What are you doing?” question in 140 characters. Meanwhile my blog had never gotten beyond a very small number of longer, carefully constructed magazine article-style posts and so failed in its intended role as a diary shared via the web.

So, the blog idea is reborn with two key tweaks. First, I’m going to lean towards more frequent, shorter posts that complement (and probably extend) my Twitter utterances.  Second, it’s part of orangemoose.com where I’ll be more regularly tending a variety of posting efforts including software, web applications, and shared media, and therefore where I can work separately on detailed expositions as articles outside the flow of my blog.

Let’s see if it works…

Welcome to WordPress. This is a test post just to see how content, fonts and formatting all come together based on some ongoing tinkering with the ‘Admired’ theme I’ve selected for use with WordPress.  Here comes a couple of cut/pasted paragraphs to give this a feel of a normal post.  Don’t get too attached to it as it’ll eventually go away.

I’m an engineer and tinkerer and needed a place where I could use the Internet to publish results of some of my projects. Facebook, Tumblr and blogs like WordPress are great for some things but they don’t give you complete freedom to combine information and images with active web content like Javascript. They also have limited ability to provide content for tablets, mobile devices, and the coming connectivity revolution associated with the Internet of Things. While I was able to avoid it for quite a few years, eventually I knew I’d need my own hosted web presence. So here we are…

Now some test code. First the full SyntaxHighlighter Extended plugin:

#body {
    background-color: #a0a0a0;
    font-family: MountainsofChristmas;

and then the ‘light’ rendering option of SyntaxHighlighter Extended:

% scp dbryant@ .

and finally use of the <pre> tag:

Raspberry Pi & cameraAnd a paragraph with a picture.  This is a photo of my Raspberry Pi with the camera attached. Installation is not hard, but you do need to be careful with the connector.