Eat, code, love.

Hi. I’m Fredrik Appelberg.

My first board

I’m immensely proud of the fact that I soldered together my first prototype board last night. It holds two DS18B20s; one naked sensor soldered straight onto the board and one on a waterproof cable that I’ve hung out the window. This lets me measure current indoor and outdoor temperature.

The board is connected to my Raspberry Pi, where a node.js program using sensorjs is regularly sending the sensor data to a TempoDB database.


pi

Hardware is hard

Where I live there aren’t really any options for electronics shopping, so I was resigned to do it mostly through mail order. Fortunately I discovered that Kjell & Co., which is probably the closest thing to Radio Shack we have in Sweden, not only carries a lot of Arduino stuff, but also has an shop in the next town over (LuleĆ„, about 50km away).

So I got myself a soldering station, some lead-free solder1 some sensors and grab bag of diodes, resistors and cables to play with. It must be something like 25 years since I last had a soldering iron in my hands, but putting the T-cobbler together I all just came back to me. Even the smell was exactly as I remembered it.

I had some problems getting the DHT11 sensor up and running. All the examples I could find had a four-legged sensor, but mine came pre-mounted on a board with only three. Also, the configuration of the legs had been switched around. That one took some figuring out.

The DS18B20 however, just plain refused to show up as a device in /sys/bus/w1/devices. I tried everything: reflashed the SD card, checked the kernel messages, double-checked my connections (twice), moved things around on the bread board in case there was a break (which incidently there is; the vertical strips break in the middle, but this didn’t affect my wiring) and tried every combination of power and GND I could find on the breakout board in case I had done a bad soldering job (which I hadn’t). I did countless reboots. Still nothing.

I had just about written that sensor off when I discovered that the pullup resistor2 I’d used wasn’t yellow-purple-red as specified, but yellow-purple-yellow. 470K instead of 4.7K. Oops.

Hardware is hard.


  1. Which everyone seems to think is terrible, but I haven’t had any problems with. Yet.

  2. I confess I have no idea what a pullup resistor actually does.


Hello, World

Since I pretty much do node.js full-time nowadays, I was curious if I’d be able to run it on my Pi as well. Turns out that’s no big deal; there are binaries available for download so you don’t have to go through the hassle of compiling (which I hear can take quite some time).

Interfacing with the PiFace is another matter. There is a module called piface-node, but I couldn’t get it to do anything, and looking at the source code I could see that it was a bit too low-level for what I wanted to do. However, I did find a C library called libpifacecad, and started hacking to see if I could write a node wrapper around it.

After a few evenings worth of work I am at a point where I can read the sensors pretty reliably and writing to the screen somewhat less so (it works maybe one time out of three). That’s not the fault of the underlying library though, it seems pretty solid. Rather, I suspect there’s either a race condition somewhere (possibly), or I’m making assumptions about C++ memory management that’s not entirely true (probably), or I need to rethink how to do I/O in the node.js event loop (almost certainly).



The Joy of Hardware

Last year Jfokus ran an embedded systems track alongside the main conference, and this was met with considerable enthusiasm. It was a friendly refuge from corporate keynotes and enterprise bloatware seminars, a place where you could escape the buzzwords and marketing people. I discovered that the Raspberry Pi was an actual thing that existed and could be ordered from the internet, and within 60 minutes I had done just that.

Apart from putting together the odd PC back in the late 90’s, I’m generally clueless about hardware. I don’t know what the state of the art for RAM or CPUs are nowadays; in fact I don’t even know how many cores the MacBook I’m typing this on is running. Hardware is a nuisance; the problems that interest me all lie deep into software country.

However, the Raspberry Pi has awakened my curiosity for circuit boards, ports and capacitors. I want to learn about microcontrollers, I want to find out how GPIO works. God help me, I want to solder.

Karin from r-pi.se had a table at the conference, and seemed to be doing a brisk trade. This photo was taken during a lull in traffic, but usually it was so crowded you couldn’t even see the table.

I couldn’t resist getting a PiFace board; I’ve been wanting to add a display to my pi as I tend to run it headless and it would be nice to have some way of displaying status information. And adding a wi-fi dongle seemed like a good idea for a machine like this.

Admittedly, these are toys. Pure indulgence, a guilty pleasure, as I still don’t know what I will do with the Pi. It will be interesting finding out, though.


Emacs Protip: org-mode

Man, where do I start? org-mode is Emacs’ Killer Application. It started out as an very capable outlining tool, but has grown and mutated and now people use it for time management, blogging, presentations, spreadsheets, GTD, you name it. Org-mode is the reason I returned to Emacs after several years as an Eclipse refugee. I needed a system for handling my ToDos, and after hearing good things about org-mode I installed Emacs again and gave it a go. And here I am several years later and I pretty much live and breathe Emacs now.

In other words: if you haven’t tried org-mode, you’re probably missing out. Here, have a look at this screencast. It’s short and sweet and you know you want to.



Emacs Protip: ido-mode

If you are using emacs for anything more involved than editing config files every now and then you owe it to yourself try out a productivity enhancer like ido-mode. It lives in the minibuffer and provides way better completion for file names, emacs commands, buffers, you name it. Seriously, check it out if you haven’t already.

In all fairness, I should probably point out icicles as well as it seems to provide much of the same functionality as ido-mode. But since I’ve never used it I can’t really comment on it.


My best friend

My best friend was a sometimes melancholy brown cat called Yojimbo. That wasn’t his actual name, but it was the one that stuck in my head as we pulled into the driveway to collect him. He was twelve weeks old.

We took him to the summer house. This was the first time in his life he had been outdoors. He sat petrified beside me on the porch for fifteen minutes before demanding to be let in again.

When my best friend was six months old he decided to leap out into a stairwell, plunging two floors and landing on concrete. I will never forget that moment. We took him to the vet, worried about concussion or internal bleeding. She said he had bruised a toe, but that was about it.

My best friend caught a cold, which developed into a nasty cough. It never seemed to get better. Turned out it was asthma. Turned out it was treatable. Two times a day we helped him breathe into a special inhaler. If we were late, or forgot, he would gently remind us.

My best friend had faults. He was a coward, but despised weakness in others. He could be downright mean to other animals. He methodically destroyed our sofa. But we loved him, and he loved us.

He was in an accident and crushed his paw. A very talented surgeon put everything back in place. He wore a cast for two months. Every ten days we would get in the car and drove for 90 minutes to get his foot X-rayed and the cast changed. We went to physiotherapy and did exercises. He didn’t understand, but accepted it. He was three years old.

We moved to another town. Our new place had a garden. My best friend would spend hours lying in wait under the big fir in the back. Once he was chased by a Rottweiler, and was gone for four hours. I wondered if he would find his way back home.

My best friend had an enemy. A large red cat that lived three houses away. They had a huge fight in our garden shed, and then a fragile truce.

Our oldest cat got very ill. One day we had to take her to the vet and she didn’t come back with us. My best friend was upset, and searched for her everywhere. We cried often that summer.

I would go away on business trips. When I packed my bags he ran away and hid. He hated goodbyes. When I got back I was ignored at first, then quickly forgiven.

My best friend got constipated. We tried laxatives and massage. He wouldn’t eat. He grew weak. Again we took him to the vet. Turned out it was a tumour. Turned out this time there was nothing we could do for him. My best friend died on the operating table. It was a very bleak february. He was just about to turn six.


Inbox

It’s funny how things change. I used to hang out on a lot of mailing lists back in the day, some pretty high-volume ones. Two that come to mind were the Belle and Sebastian fan list and an extremely casual chat list for bored young IT professionals. I had my email client of choice (mutt) fired up and checked it obsessively throughout the day.

I could get hundreds of emails in one day, most of the fairly uninteresting. But I read them all none the less. In a way, this was social networking before orkut, friendster and facebook.

A couple of years ago things started to shift. I noticed this at first when going through the inbox of my new email client of choice (gmail). Most of my traffic were just notifications about interactions happening elsewhere. Someone wants to friend you och Facebook. You’ve got a PM on Twitter. Someone endorsed your XML skills on LinkedIn.

(Side note: I never use LinkedIn. The only time I go there is to dutifully accept someone’s network request, and this happens once every six months or so. I suspect I’m not the only one doing this. LinkedIn is where social interaction goes to die.)

Anyway, I realized that my email inbox was slowly being turned into a dumping ground for online services while at the same time most of my actual interactions were moving elsewhere. I found it easier to just fire off a Facebook or Twitter PM than taking the time to compose an email. Which is kind of ironic considering how a decade earlier email had killed off regular letter writing in much the same fashion.

What came next was that I started dreading getting email. I still haven’t figured out the the reason behind this. All I know is that opening my inbox filled me with anxiety. The emails I got were mostly spam for products I didn’t want or sad status notifications from services I no longer used. And there were all the mass mailings about Good Causes (WSPA, Avaaz, Sea Shepherds); well-intended but very depressing. What few actual human interactions I still had got buried in this crap. And it made me shy away from the medium that I used to love and spend every waking moment on.

When Google rolled out their recent gmail changes that split your inbox into separate buckets for the important stuff (Primary) and the rest (Social, Promotions, Forums, etc.) and then applied their strange cloud powers to create an automatic categorization scheme that actually worked, I was delighted. It sounded perfect. It felt as if they built this feature just for me. The wheat got separated from the chaff and it all worked! Well, most of the time anyway.

It’s not enough, though. As long as the other buckets fill up with messages I’ll still feel anxious that I’m missing something. There’s a compulsion to read them all, even though I know I don’t have the motivation or capacity to act on them in any meaningful way. I’m still unhappy and stressed out.

I’ve started a new email regimen:

  1. Unsubscribe mercilessly. Unsubscribe from the product updates, the marketing emails, the service notifications. You don’t need them. Unsubscribe from mailing lists you haven’t read in a while; you can always resubscribe later. Unsubscribe from charity mass mailings; if you really want to contribute there are better ways than sitting at your computer, feeling impotent.

  2. Filter what you cannot unsubscribe. Create rules that automatically mark stuff as read, or send it directly to trash. Train your spamfilter like a rabid pitbull.

  3. Delete what you cannot filter. Seriously. You ain’t gonna need it.