Diary of a Tinkerer http://johan.beyers.co.za/ Opinions and things en-us Fri, 06 Oct 2017 00:00:00 +0200 http://johan.beyers.co.za/2017/10/06/building_a_speedometer_for_my_dog.html http://johan.beyers.co.za/2017/10/06/building_a_speedometer_for_my_dog.html <![CDATA[Building a Speedometer for my Dog]]> Building a Speedometer for my Dog

TL;DR: I built a Persistence of Vision speed indicator for my dog, using an Arduino, a few LEDs and resistors, and less than 40 lines of code. This is the story of the process and results.

The beginning

I’ve had an arduino for ages, but didn’t really have a project that I wanted to build. Then, at the end of 2012, I had an idea: Why not build something interesting and a little bit crazy? Thus, the dog speedometer was born.

Pippi being enthusiastic about squirrels

Our dog, Pippi, a Jack Russell of sorts, is always brimming over with enthusiasm and happiness. One day, watching her tearing through the garden, I started thinking about how to measure how fast she runs.

There are many ways to measure speed, but I wanted something very simple with a visual indication. I’ve always liked Persistence Of Vision displays, and thought that showing her speed using a POV display would be cool. Since a POV display has to be attached to something that’s moving, it would work well if the display could show how fast it’s going.

The idea

I’m always looking for ways to get functionality out of the minimum amount of hardware, so options like gps and inertial measurement were right out.

Slowly the idea formed that the display itself could be the speed measurement.

Hi spelled out in sweeties in a POV way

A POV display works by moving a line of LEDs and lighting them up with exact timings so that they leave an after-image in your sight. The stop-motion example above shows the white line of sweets representing the LEDs and the blue ones showing the after-image if they are lit up in sequence.

Since it’s a POV display, could I skew the line of leds and time the signals so that they only line up at specific speeds?

Same light sequence, different speeds

This stop-motion sequence shows the basic idea: Skew the line of LEDs to an arrow shape. All the arrows are flashing the same pattern with the same timing, but they are moving at different speeds. The middle line is moving at a speed that results in a perfectly straight line. The top line is moving at half that speed, and the bottom line is moving at 1.5x the speed.


There was a regular weekly maker meetup at the local university. At one of these nights, I implemented a simple version of the board to demonstrate the idea.

Breadboard build

The initial build was very crude, built on a breadboard.

Google is a great calculator

I programmed it to show the numbers 1-9 in sequence. Each number is shown at a slightly different rate, so that the undistorted number would be the speed I was moving at. Breadboard spacing is 1/10th of an inch and the LEDs are placed 2 holes apart, so an 18ms delay is roughly equivalent to 1 km/h.

# The binary sequence to output to the port for each number.

byte one[] = {B0, B10001, B1010, B100, B0};
byte two[] = {B10001, B10011, B10101, B01100, B100};
byte three[] = {B100, B100, B10101, B11011, B10001};
byte four[] = {B100, B1100, B10100, B1010, B10001};
byte five[] = {B10001, B11001, B10101, B110, B100};
byte six[] = {B100, B1110, B10101, B10011, B10001};
byte seven[] = {B0, B0, B10100, B11010, B10001};
byte eight[] = {B100, B1110, B10101, B11011, B10001};
byte nine[] = {B100, B1100, B10101, B11011, B10001};
byte zero[] = {B100, B1010, B10101, B11011, B10001};

int i = 0;

# Prep the output port

void setup() {
  DDRD = 0xff;

void loop() {

  # One is shown at 18ms delay.

  for (i=0; i<5; i++) {
    PORTD = one[i];

  # Two is shown at 9ms delay.

  for (i=0; i<5; i++) {
    PORTD = two[i];

# ------------------- etc.

The program above is shortened for clarity. Note that those binary sequences are the reversed ones (see the inverted arrow of the next build).

Walking at different speeds in a corridor

I took it out to a dark corridor and did a few tests. I walked along at different speeds, with the result showing in the separate lines. The top one shows a faster walk.

Note that in all these lines, the flashing sequence is exactly the same. What you see depends on the walking speed.

Also, at this point I did not know about the Arduino microseconds timer, so it was all milliseconds.

More permanent build

Having proved that it worked in principle, it was time for a bit more robust build.

Some things I noticed from the test build:

  • The arrow idea works, but it points the wrong way. I would like the skewing to point towards the correct value, not away from it.
  • The arrow shape needs to be more pronounced, otherwise the result is very skewed in the slow direction, but almost straight in the fast direction.
  • Since a slow speed indication takes up a lot of space, it’s best to pick a range of expected speeds so that the slowest speed does not take up several meters to render.

For the final run I chose a speed range of 10 to 30 km/h. Showing every value in that range would also take up too much space, so I picked a simple scheme: I would show a vertical line representing 10km/h, the number 15 to represent 15km/h, another vertical line for 20km/h, 25km/h as a number, and a line for 30km/h.

It should look something like this:

1 15 1 25 1

(but skewed, of course)

Business end of the board

The build itself was done on a simple piece of veroboard. The hole spacing is 1/10th inch, and the build is simple enough for an out-of-practice solderer like me. The button is actually not needed.

Soldering horror

If the veroboard build uses only a few pins, you can leave out the weirdly-spaced ones on the one row of the Arduino, so you don’t even have to bend any pins.

I have larger photos and v2 code up on github:


Test run

She did not like this

Pippi was not crazy about wearing the harness. We had real trouble getting her to run while wearing it.

Going for a run

Success! Running at about 20 km/h.


  • It works! You can get a good speed indication to within 1 km/h.
  • You need a camera to really see the result clearly. The speed shown is too slow for a good POV effect.
  • If you want to use a normal camera, you have to shoot in low light so you get a long exposure. I used CHDK on a Canon camera to get a long enough exposure.
  • Obviously, this only works with an object moving from left to right.
  • It should work well on bicycles, rc cars, drones and merry-go-rounds.
  • Less than 40 lines of code in total. This is a really simple project.


I made a demo video of the speedo in action. Not on the dog, but on a special rig I built to show the principle.



I had planned to do a custom board design and some other refinements, but I got distracted with some other projects. I may still do this.

Fri, 06 Oct 2017 00:00:00 +0200
http://johan.beyers.co.za/2014/10/22/impressions_of_beijing.html http://johan.beyers.co.za/2014/10/22/impressions_of_beijing.html <![CDATA[Impressions of Beijing]]> Impressions of Beijing

Our family went on a 10-day trip to Beijing at the beginning of October. I won’t give a blow-by-blow account, just note some of my impressions.

We were invited by Astrid’s parents, and stayed with them. Her father is a guest professor at the Beijing Forestry University for a few months each year. While we did all the touristy things, we had a chance to experience some aspects of Beijing city life that the typical short-term tourist does not see.

Since we stayed in Beijing except for an outing to the Great Wall, our experience is limited, so these impressions should be taken in that context.


The first few days we had good weather. Since it was their National Day Golden Week holiday, most of the factories were closed or not running at full capacity.

Towards the end of our stay, we saw how bad the pollution could be. Levels reached heights that only happen once or twice a year. The smog was so bad that most people wore masks. Apparently the masks do not help much. Visibility was down to 50-100 meters, and the sun looked like a red, angry moon.

The Chinese are very aware of the problem, and in conversations I got the idea that they consider cycling, electric bikes and public transportation as a duty to lessen it. However, this fact alone would deter me from spending a large amount of time in big Chinese cities.


On the streets, I was immediately struck by the amount of electric bicycles, mopeds and cargo trikes. Maybe one out of several thousand mopeds are powered by internal combustion. The cargo trikes, being mostly older and probably used for a much larger part of the day, were mostly non-electric. There were also a lot of electrified bicycles, consisting of a lengthened frame with space for a battery pack and an extra seat at the back. The battery packs are removable and are plugged into mains power for charging. Altogether a great system.

Cycling is also big, helped by the fact that Beijing is pretty flat. The underground is fast and cheap (2 yuan per trip irrespective of distance), so pretty full.

Cars are only allowed on the road on alternative days, determined according to the number plate. Apparently rich people have 2 cars to enable them to drive any day.

The traffic is chaotic. People push in front of you whenever they can, and give way easily. This actually results in remarkably smooth-flowing traffic, since it’s all predictable: There is no hesitation, trying to figure out what the other person will do: They will take any gap, without hesitation. The cars, bicycles and people intermingle and flow.


I found the chinese people very friendly, and very curious. The fact that Caucasian people are a relative rarity, and that we were generally the tallest people in the room, probably contributed to that. People asked us where we came from, asked to pose with us for photos (mostly with my daughters), and were clearly curious.

We spent one Friday evening at the Renmin University English corner, where people come to practice their english. We were questioned about our lifestyle (do we have cars?), animals (We are from Africa, after all), and on our impressions of China. Seems that the people are very proud of their country, with a strong desire to grow China as well as themselves.

Workdays are long, and many people work 6 or 7 days a week.


We ate many things, a lot of which I could not identify. Staple is rice, with usually some stew over it. There is a lot of mushrooms and tofu, and some vegetables. We actually had donkey meat once.

The custom seems to be to have enormous amounts of food. Several times I could not finish a meal, even a takeaway, and this is something that happens very seldom to me. On the occasions we were invited to a meal by Chinese people, we generally managed to eat at most half of the food on the table. This is a cultural thing: Eating all the food implies that the host is stingy...

Food in general was cheap, except for Western fast food. Coffee is hideously expensive.

Although we had stir-fried food on occasion, I got the impression that food is mostly boiled or steamed, with very little of the panfried tastes that westerners are used to.

We never saw any seasoning like salt and pepper anywhere. The food usually comes with a sauce, which is spicy/tasty enough. I did miss the pepper on fried egg, though.

I think that the food has a lot less fat than Western food. The Chinese are generally slim, and the only dangerously obese people I saw were Western tourists.


This is not a priority. From conversations I gathered that the concept of excercise for health is very foreign to the Chinese people.

On the other hand, a lot of people use public transport or cycle, which leads to a minimum of physical activity much higher than a car-bound western lifestyle. Maybe this is another reason you don’t see fat people.

Culture and history

This was simply astounding. It is weirdly different to the feeling you get in Europe. In Europe, you see various churches and cathedrals, in all kinds of different styles that indicates their relative ages.

In China, I was struck by how similar all the palaces and temples were. This starts to feel boring for a while, until you realise the implication: These people had a very consistent culture and way of doing things for a long, long time. It seems like their history is a lot more cohesive than western history, which makes you realise that the current communist government is a mere blip in their history.


Of course, China can be a shopping experience of note. Since I’m not into many of the typical wares available, I found the shopping not as enjoyable as I would have liked. I think it helps in bargaining to know some Mandarin.


This was a fascinating trip. We saw, did and experienced so much, and came back enriched by the experience. Seeing a different culture and way of life both broadens my perspective on my own life, and makes me very glad to be living where I do.

Wed, 22 Oct 2014 00:00:00 +0200
http://johan.beyers.co.za/2014/09/26/using_pocket.html http://johan.beyers.co.za/2014/09/26/using_pocket.html <![CDATA[Using Pocket]]> Using Pocket

I’ve been using Pocket (formerly Readitlater) for a few years now, and I find it indispensable. It’s simple and fits easily into the way I handle links.

Bookmarking and baggage

Putting bookmarks into a browser bookmarking hierarchy is the digital equivalent of hoarding. I never go back to the bookmarks, so they just become a mental burden. Every few years, I move to a different browser and either lose all the bookmarks, or copy them over, never to be looked at again. When I started my Pocket system, I imported 1600 links into pocket, many of which were not active anymore, and most of which I could not even remember having added.

So what about other online bookmarking services? While they are more portable, they suffer from the same basic problem: I never go back, they are cumbersome to organise and they require me to categorise.

Enter Pocket

Pocket has a few advantages compared to other systems:

  • It’s designed around a single stream of information, organised by the date you place the link into Pocket.
  • It has browser plugins and Android actions.
  • It has offline readers for Android and iOS.
  • It has an API, so I can get access to my queue from scripts.

Getting stuff in

I have 2 ways to get info into pocket: Sharing from my phone and saving from the browser.

On my phone I usually save items directly from my twitter feed. Pocket places a sharing option on the Android context menu, so I can save tweets with links directly from my timeline. The only problem I have with this is the case where a tweet has 2 links. Pocket then only saves the first one.

In my browsers on my computer I have the Pocket addons, so I just hit the button to save a page for later viewing. Firefox is really nice here: The tab closes automatically when I save a page to Pocket, so it’s a quick one-click operation.

The thing to note here is that I don’t do any filtering or categorising when putting content into the list. If I might want to look at something later, it goes into the list. Takes less than a second.

Getting stuff out

If I only used Pocket as a general reading list, it would have been OK, but I would sit with the same problem: Too many links, neglected and forgotten. Instead, I have a system that automatically recycles the links, courtesy of some scripts I set up:

Every day, some time after 5pm, my browser automatically opens between 10 and 20 links from my Pocket queue. These are the oldest links in the queue. I then have some choices:

If I don’t want to spend time on these links, I just close the tabs quickly. This keeps the links and they will re-open the next day.

If I have time, I read through them. The plugin automatically removes them from Pocket if I view a tab for more than 5 seconds.

If I want to keep the link around for a while, I just push it back into Pocket. This puts it back into the queue as a new link, so I’ll only see it when it comes round again.

The end result

Using this system, I cycle through the full queue roughly every two to three weeks. It blocks out time for reading them, and is not distracting at any other time. I can confidently just push things into Pocket and forget about them, knowing that I’ll get around to them soon.

Since the Pocket list is searchable, I can refer back to items on it if I recall something that piqued my interest recently.

An interesting side effect is the serendipity of random connections: Every so often I see a link that triggers some insight, just at the right time. It’s a bit like putting your music on shuffle and listening to a song that randomly captures the exact mood.

Fri, 26 Sep 2014 00:00:00 +0200
http://johan.beyers.co.za/2014/09/21/a_trick_to_autonumber_in_zpt.html http://johan.beyers.co.za/2014/09/21/a_trick_to_autonumber_in_zpt.html <![CDATA[A trick to autonumber in ZPT]]> A trick to autonumber in ZPT

I had an interesting issue a few months ago. I was doing some work where I needed to create a pdf from a template. This was a numbered legal document with optional clauses. The problem is this:

How do you make some clauses conditional, but then autonumber the rest?

Normally, you would hardcode clause numbers into the paragraphs, but if you did that, the paragraphs following on the optional ones would be incorrectly numbered.

My coworker came up with the idea of using python’s ‘next’ functionality to just increment an iterator. I was skeptical, since I did not think of a page template as an environment where python objects would be able to keep state outside of tal statements. I was wrong.

The final solution is remarkably simple. In this case, the numbers for the first 20 clauses were hardcoded. We start off with a tal statement to get an iterator:

<body tal:define=”clause_numbers python:iter(range(21,28));”>

This allows you to number up to clause 27.

In each clause, just do the following:

<span tal:content=”python:clause_numbers.next();”></span>

and it works!

In retrospect, this does make sense, since the template is backed by persistent code objects, so an iterator should do the job.

Sun, 21 Sep 2014 00:00:00 +0200
http://johan.beyers.co.za/2013/09/24/configuration_tools__a_few_thoughts.html http://johan.beyers.co.za/2013/09/24/configuration_tools__a_few_thoughts.html <![CDATA[Configuration tools: A few thoughts]]> Configuration tools: A few thoughts

I just found a post in my drafts folder, summing up my thoughts about CM (Configuration Management) tools from a little under a year ago. Since then, I’ve started using Ansible to set up servers. I’m still not fully converted, but I find Ansible a very useful tool. I have 7 active machines at home, and running my update scripts on each of those is a pain. Ansible makes it a lot easier.


Tue, 24 Sep 2013 00:00:00 +0200
http://johan.beyers.co.za/2013/01/26/setting_up_a_simple_smtp_server_for_testing.html http://johan.beyers.co.za/2013/01/26/setting_up_a_simple_smtp_server_for_testing.html <![CDATA[Setting up a simple smtp server for testing]]> Setting up a simple smtp server for testing

On many websites, there is a need for sending mail from the webserver. While testing, it’s sometimes painful to get a working smtp server to test this.

I’ve used this script for a while now, since it’s the simplest way to get a mailserver running. It will accept any smtp connection and print the mail to the terminal where you started it from.

The script:

import smtpd, asyncore
print 'Mailserver is on port 8025. Press ctrl-c to stop.'
server = smtpd.DebuggingServer(('localhost', 8025), None)

Place those four lines into a python file (I used dummymailserver.py) and then run the python file:

python dummymailserver.py

And you’re done!

Sat, 26 Jan 2013 00:00:00 +0200
http://johan.beyers.co.za/2012/10/21/plone_conference__a_great_experience.html http://johan.beyers.co.za/2012/10/21/plone_conference__a_great_experience.html <![CDATA[Plone Conference: A great experience]]> Plone Conference: A great experience

I went to the Plone Conf 2012 in October. This was my first Plone conference, although I’ve been working on Plone since 2006. The conference was from Wednesday 10 to Friday 12 October in Arnhem in the Netherlands. I also stayed for the coding sprint on the 13th and 14th.

TL;DR: The conference was awesome. I had an incredible time, learned a lot and came back energised and enthusiastic about contributing to Plone and the community.


Sun, 21 Oct 2012 00:00:00 +0200
http://johan.beyers.co.za/2012/09/28/100_words.html http://johan.beyers.co.za/2012/09/28/100_words.html <![CDATA[100 Words]]> 100 Words

100 words each day. That’s the goal.

I have almost started a blog for a few years now. I get going with a post, and then the impetus to finish just kind of peters out.

So I’ve decided to take another tack: Just write consistently each day.


Fri, 28 Sep 2012 00:00:00 +0200
http://johan.beyers.co.za/2012/09/23/using_fabric_to_manage_your_deployments.html http://johan.beyers.co.za/2012/09/23/using_fabric_to_manage_your_deployments.html <![CDATA[Using Fabric to manage your deployments]]> Using Fabric to manage your deployments

I’m using Fabric very successfully to manage deployments of projects on my servers. Fabric is simple enough that it does not add extra layers of complexity to the setup, and easy enough to use that it makes deployments easy and much less error-prone. This blogpost is an updated and expanded version of a presentation that I did at the local Plone users group.


Sun, 23 Sep 2012 00:00:00 +0200
http://johan.beyers.co.za/2012/08/23/polycaprolactone__wonderful_stuff.html http://johan.beyers.co.za/2012/08/23/polycaprolactone__wonderful_stuff.html <![CDATA[Polycaprolactone: Wonderful stuff]]> Polycaprolactone: Wonderful stuff

I recently got my hands on some polycaprolactone, and I’m really enjoying playing with it. It is one of the most useful materials I’ve seen in a long time.

This is a summary of a talk I gave at #HackSTB on 21 August.


Thu, 23 Aug 2012 00:00:00 +0200
http://johan.beyers.co.za/2012/07/26/hello_world_.html http://johan.beyers.co.za/2012/07/26/hello_world_.html <![CDATA[Hello World!]]> Hello World!

Well, first post. Let’s see what develops...

Thu, 26 Jul 2012 00:00:00 +0200