zaterdag 24 december 2016

An ESP8266 scrolling display with a 5x8 WS2812 matrix

See for the LUA code (loaded on the ESP-8266) and the python driver with the fonts.

zondag 7 februari 2016

The SIMH PDP11 and VAX simulator

This weekend I made a nostalgic trip back in time by recreating the computer environment I used at the university in 1982 and later.

The Computer History Simulation Project created the SIMH emulator ( which I used to simulate a PDP11/70 and a VAX 780. On the PDP11/70 I loaded the original Unix v7 tapes and on the Vax I loaded BSD4.1 and BSD4.3. describes the procedure step by step, but states that the networking does not work.

I used the latest version of SIMH from Github (4.0 beta) and figured out how to get the Ethernet running on the Vax 780.

The trick is to add:

set xu enable
attach xu msk0

to your boot.ini file.

You should replace msk0 by the name of your physical netwerk interface, eg eth0 on your Linux machine, and start it with sudo vax780 boot.ini

See for details and other configuration options.

The last step is to rebuild the kernel, you need to add

device          de0     at uba? csr 0174510     vector deintr

to /usr/sys/conf/GENERIC and rebuild the kernel:

bsd43# cd /usr/sys/conf
bsd43# config GENERIC
Don't forget to run "make depend"
bsd43# cd ../GENERIC
bsd43# make depend
bsd43# make
bsd43# cp vmunix /

create a /etc/resolv.conf with:


reboot, and you can FTP and telnet to every host on the Internet with software which was compiled in 1986. Amazing isn't it?!

As an exercise I changed the date.c program because it would not let me set a date after 1999, and I changed the timezone to 0 in GENERIC, but after those changes the clock/calendar are OK.

bsd43# date
Sun Feb  7 20:31:58 WET 2016

I also fixed the printing of the man pages so they don't show as year 116 ;-)

Finally I created a program to convert the simulated tapes to normal files, an adaption of which works the other way around.

Get it from my Raspberry Pi-1 running FreeBSD 11-current:

donderdag 31 december 2015

FreeBSD video console (vidconsole) on the Raspberry Pi

In the default configuration with FreeBSD on the Raspberry console messages are written on the serial console.

After a "shutdown now" one cannot enter commands from a connected USB keyboard.

I tried to enable the video console but adding


to /boot/loader.conf just results in an error message from the bootloader.



to /etc/sysctl.conf does the trick!

Note that one still cannot enter input for the bootloader in the early boot stages. I have not found a solution for that issue (probably needs different options for UBLDR), you will have to use a serial console for now.

woensdag 23 december 2015

Booting a Freebsd image on a usb stick with the Raspberry Pi

It took me some time to figure out how to do this, but it's actually very simple.

Create an USB stick (or disk) with the Freebsd image you want to boot and connect it to a USB port on your Pi.

Create a small standard Freebsd image on a small SD-card and place it in the Raspberry SD slot.

Boot it and create as superuser the file:
with the following content:
Now reboot and your Pi will boot the image on the USB stick.

Note that when you create a standard image on the stick, that it will have two partitions. The first FAT partition with the firmware and config.txt is not used in this setup. The firmware and config is always loaded from the SD card. You can remove this unused partition (and replace s2a by s1a in loader.conf) or replace it by a swap partition or just leave it as it is.

vrijdag 2 november 2012

A 555 based simple low power boost converter

I'm experimenting with boost converters to increase the voltage delivered by NiMH or solar cells.

I played around with the TL499A which is a moderately priced IC, about 3€. It can convert from 1.1V upwards. A pricier modern alternative is the LT1073 for about 8€. If you just need to convert from 3V upwards then you're lucky, the MC34063A is available for 50 cents! Finally, an interesting 1.0V to 3.3V (or 5V) ready to use breakout board.

When you just need to double the voltage and have modest current requirements (e.g. less than 10mA) then a charge pump voltage doubler is an option. The Intersil ICL7660S is a modern and efficient solution for 1.75€. You can also build one yourself, e.g. with a 555 timer IC, there exist plenty of references on the internet. Note that you loose about 0.8 volt, so 2.4V fed to the doubler, will result in about 4 volts. I used these doublers to trickle charge super capacitors or NiMHs from solar cells at dark locations. The cells deliver e.g. 0.5 mA at 2V. That is insufficient voltage to light a led, but by using a doubler you can charge a (super)capacitor/battery with 0.25mA to 3V, and use it to power your (AtTiny) micro controller, so it can flash the led. Note that if you build one yourself that you should use the CMOS 555 versions. The normal 555s will not run at these low voltages and use far too much power to be useful in low power applications.

Ok, so you decided to build your own boost converter. The schema shown below is quite versatile. It will accept an input in the 2V to 12V range and the output can be in the 2V to 24V range. Note that you NEED a CMOS 555 for input voltages below 4.5V! Output currents in the 20-100 mA range should be no problem with the schema as shown.

How does it work? The concept is simple, the 555 generates an on/off signal in the 100kHz range which is used to switch the Darlington transistor pair.

As soon as the required output voltage is reached the 555 stops oscillating for a while because the BC547 pulls the 555 reset pin to the ground.

The values shown in the schema allow you to triple the input voltage, or even more if you have low output current requirements, e.g. under 5mA. If you want more then you should experiment with changing the duty factor of the 555. Replacing R2 with a 100k resistor will increase the duty factor from the default 50%, so that the inductor will store more energy. Increasing the value (inductance and max current specification) of the inductor might be needed to prevent saturation.

I used a 10p timing capacitor on the bread board which will result in a 100kHz (due to stray capacitance) and near 50% duty cycle with low energy consumption. If you want more exact timings for higher duty cycles then you could use eg 100pF, 10k and 33k for the 555 timing network.

Converting 2.4V input to 5.0V output and loading the output with a 100ohm resistor (50mA) results in a 62% efficiency (170mA input) in the R2=100k configuration. Note that the converter is most efficient when it can operate in continuous mode, this means that the switching frequency, duty cycle, inductor values and output voltage and current are matched. Use the default values for e.g. 50% efficiency at a large range of input/output voltages.

The Darlington can be replaced by an N-Channel (Power) MosFET, which will improve efficiency a lot. If you use input voltages over 4V then the IRLZ34 Logic Level power MosFET will allow you to scale up your power requirements. The Darlington has a 0.8V collector emitter drop at moderate currents, so at 2.4V input we will loose about 33% efficiency. The IRLZ34 has a milli-Ohm resistance for gate-source voltages over 4V. The best MosFETs I could find which should switch efficiently at 2.4V are the (SMD sot23) IRLML2502 and the FDN339AN which should be fine at 2.0V or even a bit lower!

Note that the output Zener should not be used as a regulator when you want high efficiency. You should calculate the duty factor of the 555 and the Zener should only become active when the output voltage rises over the desired upper output voltage limit because of a very low output load.

You can replace the Zener diode with a TL431 programmable voltage regulator as shown in the next schema if you want to experiment:

Interesting links:

A very clear explanation about the concepts and the calculations for converters. You really should study this if you want to adapt my example converter for optimal efficiency.

If you want more power, an interesting schema for a 6 to 12V converter.

You don't need a precise output voltage and have a square wave signal from eg a micro-controller? Look here.

The MC34063A is your preferred solution? A handy calculator aid.

Another simple converter circuit.

vrijdag 14 september 2012

Solar powered Arduino and attiny projects


I've started creating a solar powered base platform for attiny or Arduino based projects. What is the real life need for such a project, you might ask.

Well, the Atmel processors are amazingly energy efficient when programmed in the right way. Your project might run for over a year on a set of 2 normal 1.5V AA batteries.

The example project to which I link in the end of this blog will signal the battery voltage level by blinking a led several times every 10 seconds. Each blink represents 0.1V over the 2.0V base voltage. So 7 blinks means we have a battery voltage of 2.7V.

How long will this project run from batteries? Let's calculate an approximation:

In sleep mode my attiny84 uses 0.004mA. When calculating it uses about 20mA, but it is sleeping most of the time. Running at 8MHz it will only execute code for about 1ms every 10 seconds, so it's average contribution to the power usage is 20/10000= 0.2mA.

The led draws about 3mA when lit. You can measure the current by reading the voltage over the led serie resistor: 1.0V over 330ohm. It blinks 7 times for 125ms every 10s, so it contributes about 7*125/10000*3= 0.26mA on average.

Total average usage is about 0.3 (led) + 0.2 (micro controller)= 0.5mA. A 2000mAh battery will result in 2000/0.5= 4000h battery time, that is about half a year. Note that you should use low discharge NiMH cells (the pre-charged variety) or normal alkaline cells for long running low power applications. If you use solar charging then self discharge is not an issue.

If your project is more power hungry and runs only for a few weeks from a set of batteries, then a solar powered solution makes really sense. Another reason to use solar power is when the application is on a location where changing batteries is difficult.

Charging NiMH batteries

is in general hard when you want to do it optimally. For a start, you cannot charge cells in series reliably. A good NiMH charger will charge each cell individually, because they tend to get out of sync after a while. It's a good idea to charge the cells in a good charger before using them in your attiny project, and e.g. once in a year. For the same reason you should use identical cells of the same make and previous usage. Don't worry too much about these aspects, in reality your solar powered project will run just fine.

Over charging and trickle loading

Over charging NiMH batteries should be prevented. A simple way is to just use a low charge current over a long time. A C/20 current which is interrupted every 12 hours (because it gets dark :-) or a C/40 24 hour constant current (trickle charging) is absolutely safe. For 2000mAh cells this means 100mA or 50mA. Now the good news! You'll have to buy quite a big solar panel to risk over charging your batteries. Just use a small one which compensates the average power usage of your project. Measure charge current during sunny periods and you should be happy if you exceed 100mA or even 50mA. Our example project uses about 12mAh in a day. An average of 15 minutes of 50mA sun charge each day will keep your cells full. So no need to worry about over charging or too less charge capacity in general. If you measure about 2.7V over your two cells then they are fully charged. 2.8V means you're charging. Over 2.9V means that you are charging quite fast. In the latter case measure charge current and consider using a charge current limiter. The cheapest way is to use a smaller solar panel.

The Solar Panel

I used two small 4V/40mA panels in series:

3V is an absolute minimum if you want to get any charge current into your two NiMH cells in series. The cells have 2.4V when they are not full. The dark current diode has a 0.3V forward drop when you use a germanium or Schottky diode, so charging starts at 2.7V. It will start at 3.1V if you use a normal silicon diode which has a forward drop of 0.7V.

Note that the voltage/current specifications of panels are in very bright sunshine. If you need to charge in low light environments then it's better to use a panel which has a voltage specification well over 3V.

If you use a solar panel which provides over 5.5V then you should take care that you do not disconnect the NiMH cells in bright light. The connected NiMH cells will prevent a high voltage, but when they are disconnected the voltage provided by the solar cells may rise over 5.5V and your attiny chip may be damaged. You can add a 5.6V zener diode to prevent damage.

The schema and other components

I've already mentioned the diode which prevents a discharge of the NiMH cells over the solar panel when it's dark. You can use any diode, but for optimal power efficiency you could use a germanium or Schottky diode.

In order to measure the NiMH voltage with the attiny ADC we use a voltage divider composed of two resistors. The attiny has an internal reference voltage of 1.1V, so we cannot measure voltages over 1.1V. The two resistors (1MOhm and 330kOhm) in series divide the voltage approximately by 4, so we'll be able to measure 0 - 4.4V. If you use 4 cells in series then replace the 330kOhm by e.g. 220kOhm, so you can measure up to 6.1V. I used large resistors so that the current loss is very small, less than 3uA. In my example code, get it here from github, I calibrated the resistors and 1.1V reference voltage by measuring the voltage on the ADC input. Note that the 100nF capacitor between the ADC input and ground is really needed to eliminate high frequency noise on the ADC input. Without it your ADC measurements will be all over the place. I also added a capacitor over Vcc and GND just to be safe.

I tested with a power supply of 3.43V. The ADC returns a value in the range 0 - 1023. The expected ADC value would be:

330/(1000+330) * 3.43 / 1.1 * 1024 = 792

I got 775, a 1.5% error, not too bad considering the 5% resistors I used.

How to proceed from here

Now that I have a stable base platform I plan to use it as a remote wireless sensor. I'll be adding a radio transmitter (eg a Bluetooth slave which you already see on the bread board) to send temperature and barometric pressure info to my server. The goal is to intercept this info from a commercial 433Mhz outdoor weather station. Its data will be added to the graph (from another Arduino project) which shows current temperature and humidity in my work room:

The transmitter will need more than 2.7V so I'll either use a DC/DC converter or switch to 4 NiMH cells, but more about that in another blog entry...

Powering a normal Arduino

In this blog entry I described powering an attiny from 2 NiMH cells. The principle is easy to adapt to normal Arduinos. Just use 4 NiMH cells in series (results in 4.8 - 5.5V voltage) and connect it with a diode to a small solar panel which supplies at least 6V when the sun shines. That's all.

You can monitor the charge voltage or (charge) current with a cheap multimeter and check that all is fine. Connect your normal arduino to the NiMH cells and it will run just fine.

If you want to connect the NiMH cells to the power regulator input of the Arduino then you'll have to add more cells for a higher voltage (at least 6V) if you really want to run the Arduino at 5V, but you'll waste some (solar) power. Arduinos will not really need the full 5.0V (except the original atmega8) when they run at 16Mhz, so you can safely use the regulator. As a side effect the Arduino will draw less current because the voltage is now lower. Compared to a standalone attiny the Arduino power led and support circuits will always waste energy, but if your solar panel is not too small it will keep running.

Some measured data:

4 NiMH cells connected to unregulated 5V pin: 45mA current due to led and not in sleep mode.

NiMH connected on regulated Vin pin: 34mA current due to led and not in sleep mode. The 5V pin is now on 4.3V while the 4 NiMH cells provide 5.25V. At this rate (34mA) you'll need to charge every other day, so a solar based charger really makes sense.

Arduino in sleep mode in above setup: I estimate that it will use less than 5mA. This means that a normal Arduino might run a few weeks on 4 charged NiMH cells, and adding a small solar panel will extend this to ever.

vrijdag 22 juli 2011

Adding One Time Passwords to Apache

If you have some restricted information on your website then you would want to protect access to it. The standard procedure to just add a static user/password pair is not very secure. Even when using an encrypted HTTPS site the password is not fully secure from being intercepted. The transmission over the internet is encrypted, but in many cases you are not in full control over the browser you use.

When you are using a browser in an Internet cafe it may have been tampered with and it might pass information you enter to others. Even in some corporate environments the browser has been modified to use a proxy with so called Deep Packet Inspection. The IT department will install a new trusted CA certificate in the browser you use and with or without your knowledge all HTTPS traffic (including private passwords) will be decrypted and inspected for eg virus contamination or other suspicious activities.

So using a static password is not very safe. A common solution for this problem is using One Time Passwords combined with Two Factor authentication.

The concept is simple, allow a password to be used only once or let it have a very limited lifetime. When your password has been intercepted and an intruder wants to use it, then he'll discover that it is no longer valid.

So how do we get One Time passwords?

Simply use an App on your smart-phone. Each time you need to login you enter your 4 digit PIN in the App and you'll receive a one time password in return.

Many OTP apps exist, you should start at to find one for your device. My favorite is DroidOTP for my Android device. You can find it in the Android market.

The other part of the solution is configuring your Apache for MOTP. I'll describe the procedure for an installed Apache22 on FreeBSD, but the Linux procedure would be the same. hosts the code you need. Download the file (currently mod_authn_otp-1.1.4.tar.gz) and extract it in a directory of your choice.

Simply executing:

make install

installed it without any problems or warnings on my machine.

The next step is to adapt the httpd.conf.

Add the following line to load the module:

LoadModule authn_otp_module libexec/apache22/

Now we need to create the OTP user configuration. Create a directory


and create a file users in it. The owner should be www and the permissions should be 600. The information in it should only be readable by the Apache server because it contains the secret information for the One Time password generation for each user.

cd /usr/local/etc/apache22/otp/users
touch users
chown www users
chmod 600 users

Now add a single line for each user to this file, eg:

MOTP yourname 1234 1234abcdef567812

The first field specifies that we are using the MOTP implementation, the second field is the name of the user, the third a private PIN you have choosen and finally the secret which is used to configure the smart-phone App. How you get this secret depends on the App you use. Most Apps generate this secret for you when you start using them. They show it once and you should copy it to the users file.

With all this in place usage is quite simple. Just enter the following configuration in the .htaccess file in the directory with content you want to protect:

AuthType Basic
AuthName "My restricted data"
AuthBasicProvider OTP
OTPAuthUsersFile /usr/local/etc/apache22/otp/users
OTPAuthLogoutOnIPChange on
OTPAuthMaxOTPFailure 4
OTPAuthMaxLinger 1800
Require user yourname

When you access the content with your browser then you need to enter your username and the OTP password. Grab your phone and start your MOTP App. Enter your pin and type the 6 character string you receive from the App in the password field.

Now you can browse for 1800 seconds. After this period you are asked to enter a new OTP password. If you are paranoid you can lower the 1800 interval.