The next step in my exploration of the wonders of the IndieWeb is being able to syndicate content from my blog (here) to social media.  This is enabled by the IndieWeb plugins I’ve installed here via WordPress along with the syndication service Bridgy.  Let’s see if this works…

Also on:

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.

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.begin(9600);
  Serial.println("Gathering data...");

  // Attach our interrupt service routine to INT0
  attachInterrupt(0,anemom_cnt,RISING);
}

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: ");
    Serial.println(interruptCnt);

    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()
{
  interruptCnt++;
}

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…

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…

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@10.1.10.202:test18.jpg .

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.