Electronics, IT and photography blog focusing on Pentax equipment, AVR Micro-controllers and Open Source (mainly Linux and FreeBSD topics)
vrijdag 2 november 2012
A 555 based simple low power boost converter
vrijdag 14 september 2012
Solar powered Arduino and attiny projects
Intro
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
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 http://motp.sourceforge.net 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.
http://code.google.com/p/mod-authn-otp/ 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
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/mod_authn_otp.so
Now we need to create the OTP user configuration. Create a directory
/usr/local/etc/apache22/otp/users
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.
Dynamic Desktop Background
- Load the image recursively from a tree of directories
- Skip portrait orientation images (these will not show nicely on you wide screen)
- Skip small images (thumbnails)
So I wrote my own script to dust of my (bash) scripting skills:
RandomBG
It requires the installation of ImageMagick and jhead from your distribution. These are needed for determining the orientation of the image.
Store the script on your computer ($HOME/bin is a good place) and invoke it with two arguments, the image directory (tree) and the delay in seconds between refreshments, e.g.:
RandomBG /data/MyImageCollection 300
You can start the script when you login on your desktop by adding it to the list of startup programs. On Ubuntu Natty you can find this setting as Startup Applications under System Settings.
The default minimum size of an image is 200k. You can easily change it in the script on line 44 by adapting the find command.
Adapting it for KDE or XFCE would require just replacing the single gconftool command.
Update for Ubuntu 11.10 Oneiric Ocelot Unity desktop:
replace the gconftool line with
dconf write /org/gnome/desktop/background/picture-uri "'file:///$foto'"
#!/bin/bash
DIR=${1:?Need an image dir for this arg}
SLEEP=${2:-300}
function Ori()
{
FILE="$1"
ORI=`jhead -v "$FILE"|grep "Orientation ="`
set `identify -format "%w %h" "$FILE"`
W=$1
H=$2
if [[ "$ORI" == "" || "$ORI" =~ 256 ]]
then
if (( $W > $H ))
then
echo "l"
else
echo "p"
fi
else
if [[ "$ORI" =~ 1 ]]
then
if (( $W > $H ))
then
echo "l"
else
echo "p"
fi
else
if [[ "$ORI" =~ 6 ]]
then
echo "p"
else
echo "-p"
fi
fi
fi
}
OLDIFS=$IFS
IFS=$'\n'
fotos=( $(find $DIR \( -name '*.jpg' -o -name '*.JPG' \) -size +200k) )
IFS=$OLDIFS
while :
do
ori="x"
while test $ori != "l";
do
foto="${fotos[ $RANDOM % ${#fotos[@]} ]}"
ori=$(Ori "$foto");
done
echo $foto
gconftool -t string -s /desktop/gnome/background/picture_filename "$foto"
sleep $SLEEP
done
zondag 3 mei 2009
Pentax shake reduction with long lenses
Result: good, moderate, decent
and with SR off: bad, bad, bad
Conclusions, even with my old trusty K10D a very decent result!
First the three SR images, followed by 3 without SR:





zondag 29 maart 2009
Pentax 540 and Metz 58 comparison

I've had a Metz58 flash for a year and a half and received a Pentax 540FGZ a few months ago.
I wanted to test various combinations of these flashes, see the effect of contrast control, etc.
First some remarks not related to the flash behavior:
I like both units, the bodies of both feel sturdy. I would perhaps rate the feel of the 540 flash head higher than the Metz. On the other hand the 540 has a battery cover which feels fragile, I operate it with care. Also the control sliders of the 540 feel less solid, but not in such a way that I feel that they are likely to malfunction.
Completely subjective: the 540 has slightly better looks.
You can find the complete 21 page test report in PDF form here (Updated June 2009).
Final conclusions:
Contrast mode
Contrast mode works, but not in the way I would expect, c.q. wish it to work. The flash with contrast-on emits less light, but contrast-on does not work for the on camera master. So one cannot have the on camera master act as fill.
Contrast mode implementation on the Metz and 540 are not completely similar. The 540 produces slightly different results (lower ratio for the off camera slave?) than the Metz as off camera slave.
When using 2 slaves the contrast-on option gives inconsistent results. If the Metz has contrast-on then the option has no effect. If the 540 has the option on then the Metz does not fire.
In a controlled environment one should use manual for really predictable results.
In a dynamic environment with a master flash on the camera one should move the slave flash away/towards the subject to change the master/slave ratio or play with exposure compensation on both flashes.
Which Flash?
Both the Metz-58 as the Pentax 540 are really nice flashes. I think I prefer the Metz as on camera bounce flash with the option to use the second reflector as fill. The 540 is really good as off camera flash and even has an optical slave mode.
I also considered the Metz-48 and Pentax 360 flashes. They are good options as long as one is not interested in using multiple flashes. The drawback of the Metz-48 is that it cannot act as a master/controller on camera, otherwise it would be a great second flash for me. The main drawback for me of the Pentax 360 is not that it doesn't have the swivel head (I assume I could live with that), but that off camera the automatic power off option cannot be disabled. I use off camera flashes a lot with optical or radio triggers and having to turn the 360 manually on after a few minutes (and restoring all its settings) is no option for me.
See Mattdm's site: http://pttl.mattdm.org/
for more flash options and all kinds of details about the flashes.
zaterdag 28 maart 2009
An Ultra Narrow Grid Spot for your flash
Last week I made a grid spot from drinking straws for my flashes. You can read about these DIY devices here.It took me a few hours to build one with 4.5 cm straw fragments. The result was nice. The spot creates a circle of light about 20 cm wide when used from a distance of about 1.5 meters. (Note: In The Netherlands you can find these black straws at the Xenos or the Ikea)
I wished however for a tighter beam of light and wondered if I could use the complete straws in a construction. I'm a bit lazy and didn't want to glue a cardboard/straw assembly together only to discover that it did not work. So I tried the following:

I bundled two packs of straws with two rubber bands (a band on each end) so that they formed a nice circle. I used an already home made snoot as container, c.q. flash mounting device. To prevent light leakage I wrapped a black cloth (a.k.a. a pair of socks) around the straws and put this in the front of the flash mounted snoot:

The result was great! This grid created a spot as shown on the first image. The hot spot is about 5 cm when used from a distance of about 1.5 meters. Not only was it quick to assemble, but this way the snoot can function as a snoot AND a grid spot. So the bundle of straws and the sock get a nice permanent place in my flash bag...





