My Notebook

Random starfield generator for THREE.js

Author
Andreas Rohner
Date

Any kind of 3d space simulation needs a skybox with a starfield as background decoration. At first I wanted to get this right and use a realistic starfield with real stars in their correct positions, but it is really hard to get those for free in high resolutions.

This website has a very good description of the problems associated with star fields and some free sample textures.

Most of the time you get low resolution starfields and you are not allowed to redistribute them. However it is much easier to just generate your own random texture on the fly.

read more...

A platform independent way for a C# program to update itself

Author
Andreas Rohner
Date

In Windows you cannot write to an executable file while it is still running, because the file is locked by the file system. Therefore a running application can never delete or update itself without the help of another process that does the actual work. However, this rule doesn't apply to Batch-scripts. They are interpreted line by line by cmd.exe and can delete themselves. This post demonstrates a simple trick how you can use this fact to generate a temporary self-removing Batch-script in C# to update your application. read more...

How to use an object as a key in JavaScript

Author
Andreas Rohner
Date

At first glance it seems perfectly reasonable to use an object as a key in JavaScript, but it doesn't work as you might expect it to. This is a dangerous pitfall, because there are no warnings or error messages and the resulting code seems to work fine. The nasty bugs, introduced by this, surface months later and are very hard to track down. read more...

My DIY wireless solar powered temperature sensor network

Author
Andreas Rohner
Date

This post describes my DIY wireless solar powered temperature and humidity sensor network, which I have installed in my apartment. Everybody can buy a cheap solar powered weather station, but I wanted to build it myself and learn a thing or two about electronics in the process. read more...

New Arduino library for 433 MHz AM radio modules

Author
Andreas Rohner
Date

I have just finished my new Arduino library for 433 MHz AM radio modules with a focus on reliable one-way communication and forward error correction. There already are a few libraries that work with these cheap little modules, namely VirtualWire and its successor RadioHead as well as rc-switch, but I wasn't quite happy with either of them. read more...

How to make the Watchdog timer work on an Arduino Pro Mini by replacing the bootloader

Author
Andreas Rohner
Date

I have just spent several hours debugging a very annoying issue with the Arduino Pro Minis Watchdog timer, until I finally realized that the fault wasn't in my code, but in the bootloader. The Watchdog timer is used to reset the microcontroller, if it is non-reactive for a certain period of time. The microcontroller can crash or enter an infinite loop for any number of reasons, so an automatic recovery from these states is an important feature. read more...

Polymorphic file that is a valid Windows-Batch, Bourne-Shell and Powershell script

Author
Andreas Rohner
Date

The following file is a valid Windows-Batch, Bourne-Shell and Powershell script all at the same time. It probably isn't very useful, but I find polymorphic files really fascinating in and off themselves. I created it by trail and error, so there is probably a nicer version of something like this somewhere on the Internet. read more...

How to set the PWM-frequency for the Attiny84

Author
Andreas Rohner
Date

Pulse-width modulation can be used by a microcontroller to control the power supplied to other devices like LEDs or motors. It works by switching a digital pin on and off at a high frequency. The power supplied to the device is determined by the length of time the pin is on versus off. This relation is given as a percentage and is called the duty cycle. read more...

How to implement part of the Open-Document-Speadsheet file format using only Bash

Author
Andreas Rohner
Date

The Open-Document-Format is an open XML-based standard for spreadsheets, presentations and word processing. In its simplest form it is just a single XML-file in a ZIP-Archive. So there is no need for bloated libraries to create simple documents. All you need is a simple Bash-script and a few common Linux commands. read more...

Some simple animated fractals using HTML5 Canvas

Author
Andreas Rohner
Date

A fractal is a kind of mathematical function that creates infinitely self-similar patterns. In its simplest form a fractal can consist of only a few construction rules that describe how to get from one iteration to the next. Every iteration of these rules reveals finer and finer details until an intricate pattern emerges. In practice we have to stop after a finite number of iterations, but the mathematical fractal space goes on into infinity. read more...

How to fix device permissions for the USBasp programmer

Author
Andreas Rohner
Date

If you try to use the popular, open-hardware ISP programmer USBasp in Linux as a regular non-privileged user, you get an error message like this:

avrdude: Warning: cannot open USB device: Permission denied
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp'
read more...

Simple orbital camera controls for THREE.js

Author
Andreas Rohner
Date

This post shows how to implement orbital camera controls with only a few lines of code and without a plugin. This enables the user to move the camera with the mouse along the surface of a sphere, whereby the camera always points to the center. At the center of the sphere there is an object that can be intuitively viewed from every angle. By increasing or decreasing the radius, the camera can zoom in or out. read more...

How to recover the raw data from a bitmap chart

Author
Andreas Rohner
Date

This post describes a simple hack to recover the raw data from a bitmap chart. If you want to cite a line-chart from another document, you often only have access to a low resolution bitmap version of it. Ideally you would like to replot the graph with your own fonts and labels, but the original raw data is not available. In that case this simple technique can help. read more...

How to synchronize a Gulp-task that starts multiple streams in a loop

Author
Andreas Rohner
Date

How to create one Gulp-task that depends on another task is well documented in the Gulp API Reference. Gulp offers three options for doing this, namely accept a callback function, return a stream or return a promise. But what if you have a really complex Gulp-task that starts multiple asynchronous streams in a loop and you need to synchronize that with other tasks? Unfortunately there seems to be no simple solution for that at the moment, but I found a reasonable work-around: read more...

How to modify an Arduino Pro Mini (clone) for low power consumption

Author
Andreas Rohner
Date

Yesterday I decided to do a little project with my cheap Arduino Pro Mini clone, which had been lying around for a while. I decided to power it with normal AA batteries and I assumed that this tiny board would already use the minimal possible amount of power. But I soon discovered that it had an annoyingly bright power LED, which couldn't be turned off. While searching for a solution, I came across lots of articles and posts with catchy titles like "How to run an Arduino (clone) on (AA) batteries for over a year", but I couldn't find a step by step guide for a total beginner like me. Since my Arduino clone had cost me only 7 €, I decided to warm up my soldering iron and start messing with it. read more...