x

Tuesday 26 February 2013

Random blog banner - Part 1

You probably have noticed: the banner image of this blog changes every time you refresh the page. Those are stitched panorama from many pictures, sometimes spanning a full 360 degrees, sometimes less (I will write something about stitching these panoramas at some point...).

The code to do randomize the banner image is easily available online, I took it from this page, but it is found in so many places that I'm not sure who wrote it first.

My updated version follows:
<script type="text/javascript">
var banner= new Array()
var shift= new Array()
var information= new Array()
banner[0]="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNXX68HJ-zGPBvn2ZPOIPfpV0tnIJ8yXM9yxoKh3FEW9ycY0883_oXfM2TNYOis319rf2H2YvI-hloChdei3v1o8yXiNaBqnvPRktWXBjooDsFqJKtpz0pxXASYPc98QMuzvnlKpArbJCL/s1600/101P.jpg"
shift[0]="no-repeat center -50px"
information[0]="Jiufen - Taiwan"

//...
var random=Math.floor(banner.length*Math.random());
var query = window.location.search.substring(1);
var match = query.match(/.*headerimage=([0-9]+).*/);
if (match) {
document.write("Manual image index:");
document.write(match[1]);
random = match[1];
}
document.write("<style>");
document.write(".body-fauxcolumn-outer .cap-top {");
document.write(' background: #FFFFFF url("' + banner[random] + '") ' + shift[random] + ';');
document.write(" }");
document.write("</style>");
document.getElementById('headerinformation').innerHTML = information[random];
</script>
Let's take it step by step. I define 3 arrays: banner, shift, and information, each index representing one image:
  • banner contains the URL of the image. I extract the public link from the Picasa Web Albums. This URL can be obtained by a right-click on the image, and then "View Image". The URL looks like this: https://lh6.googleusercontent.com/.../s1600/X.jpg. The number after the letter s is particularly interesting: it defines the width of the image. I you change it, Google will very nicely resize it to the size you want. Using s0 gives you the original resolution.
  • shift contains some extra CSS style information. For full 360° panoramas, the image can be repeated endlessly without seems, so the parameter repeat is used, otherwise, the panorama is shown only once. Also, you can set an offset, so that the image gets centered vertically, so you don't get only sky or only land/sea in the banner.
  • information contains some short description about the image.
Then, I pick a random number in the list, unless the URL is something like http://drinkcat.blogspot.com/?headerimage=0 : In that case I force displaying image 0. That's useful for debugging.

Finally, the code generates a little piece of CSS style, that will set the banner image. Also, it modifies the HTML element with id headerinformation, so that it shows the image information. In my case, this element is at the bottom of the banner, aligned to the right, and tells you where the image was taken.

All right. All for now, next post will show how to generate the script, as well as this page, automatically.

Wednesday 20 February 2013

Triggering Panasonic Lumix from Arduino

As mentioned in the post about how to build a remote trigger, we can also use an electronic device, such as an Arduino, to trigger the camera.

There are several way of accomplishing this, a simple MOSFET may do the trick, but I decided to use a optocoupler. The optocoupler electrically separates the Arduino and camera circuitry: This decreases risks of damaging the camera because of incorrect wirings on the Arduino side.

Camera detection circuit

If you remember from this post, the triggering mechanism for Panasonic cameras is a little unusual: The resistance across 2 pins defines the trigger status: around 41.1kOhm at rest, 5.1kOhm to pre-focus the camera, 2.2kOhm to trigger a shot.

Understanding a bit more of the detection circuit inside the camera is useful here. This can be done by measuring the voltage across the 2 pins in different combinations:

State Measured resistance Voltage measured
Open circuit (infinite) 3.08V
Trigger present ~41.4 kOhm 2.49V
Focus ~5.0 kOhm 1.05V
Trigger ~2.1 kOhm 0.56V

We can make an educated guess on the detection circuit used by the camera, making use of a simple voltage divider, and reading out the voltage drop on the remote trigger.
Possible detection circuit on the camera (the camera resistor may be connected on the ground side, and may be more complicated to avoid the need for an analog to digital converter)
Obtaining Vcamera is straightforward: it is the open circuit voltage. We can guess Rcamera entering resistances Rtrigger and Vdetect in the following equation:
Moving terms around, we get:
For the 3 values above, we get, respectively, Rcamera = 9.8, 9.7 and 9.45 kOhm. So we have a resistor around 9.5 kOhm on the camera side.

Triggering circuit 

Now comes the triggering circuit itself, as shown in the next figure.

Triggering circuit (optocoupler drawing from Wikipedia).
Note: The polarity of the camera connector is important: if you reverse the pins, no current can flow through the the optocoupler (no damage to the camera, it just won't work).
In my case, Rled = 200 Ohm, Rp = 36 kOhm, Rt = 0

The optocoupler provides a separation between the Arduino circuit on the right, and the camera on the left. When Pin 2 on the Arduino is grounded, no current flows through the LED, and the transistor on the right is in the "off" state, i.e. it does not let any current through. When a voltage is applied to Pin 2 (digital 1 = 5V), the led shines on the transistor, allowing current through it ("on" state).

In this case I used a TLP627 optocoupler. The easiest parameter to compute is Rled: As indicated in the datasheet, the forward voltage of the LED is 1.15V, and we want a maximum of 25mA. A simple calculation (or an online tool) will tell you that a 200 Ohm resistor is required.

What we want here is the circuit to have a 44kOhm resistance (~2.5V) in the rest state, and drop the resistance to 2 kOhm (~0.5V) when the optocoupler is on. A simple solution would be to set Rp to 42 kOhm, and Rt to 2.1 kOhm. When the optocoupler is off, the total resistance is 44 kOhm, when it is on, the optocoupler shorts Rp, and the total becomes 2.1 kOhm.

If you try this combination, you will realise that it is not enough to trigger the camera: the voltage drops, but only enough to pre-focus the camera, that is a voltage around 1 V.

What is happening? In reality, the optocoupler is not an ideal switch: in the "on" state, it has a small, but finite, voltage drop. In my case, this voltage drop is around 0.5 V, just what we need to trigger the camera. Therefore, we can get rid of Rt, and simply set Rp to 44 kOhm. I did not have a 44 kOhm resistor, but I realised that 36 kOhm also works, so I used that.

I'm not 100% sure of the theory behind, but I suspect that the transistor can only conduct current when it is close to its saturation voltage. However, for the TLP627, the saturation voltage is anywhere between 0.3 to 1.2V, according to the datasheet. Therefore, you may need to adjust Rp depending on the individual properties of your optocoupler, or you may not be able to trigger the camera at all.

These guys use a LTV-355T optocoupler, with Rp=1 kOhm. I'm not sure what makes that optocoupler better, if it is better. I did not use it because it is only available as a surface mount component, while the TLP627 is available as 4DIP package, compatible with breadboards and stripboards.

If there is an electrical engineer in the room, maybe that person can shed some light on this. I stopped thinking about it, because the circuit works, and that is all I need ,-)

Finished circuit on a breadboard, connected to a Freeduino (Arduino clone).

Arduino sample code

The following code will trigger the Arduino every 10 seconds. This is useful for simple time-lapse photography:
int trigger = 2;
int led = 13;

int time = 10; /* time between shots, in seconds */

void setup()  {
  Serial.begin(9600);
  analogReference(INTERNAL);
  pinMode(trigger, OUTPUT);
  pinMode(led, OUTPUT);
  digitalWrite(trigger, LOW);
}

void loop()  {
  for (int i = time-1; i > 0; i--) {
    delay(1000);
  }
  delay(900);
  digitalWrite(trigger, HIGH);
  digitalWrite(led, HIGH);
  delay(100);
  digitalWrite(trigger, LOW);
  digitalWrite(led, LOW);
}
This code "holds down" the shutter for 100 milliseconds, enough to allow the camera to autofocus. It also blinks the Arduino LED on pin 13, to give you a visual feedback that the code is running, in case the camera does not trigger (wrong polarity, etc.).

Tuesday 12 February 2013

Tilt adapter for Micro Four Third - Part 3 - Simple adapter

This is the third part of the series on a tilt adapter for Micro Four Third system. Please read the introduction first, and the lens selection guide.

This article will show you how to build a very simple DIY tilt adapter using a body cap, a lens cap, and some plastic bag.

Make the adapter

You will need the following items:
  • A lens (read the lens selection guide, you can find a suitable Olympus OM lens on eBay for 20-30 USD)
  • Micro Four Third body cap (<3$ on eBay)
  • Lens cap (<2$ on eBay). For Olympus OM lenses, a Four Third cap (not Micro Four Third!) also works (the mount is very similar).
  • Opaque plastic bag (thick but flexible plastic is best)
  • (Optional) Some black paper
Left: Olympus OM lens cap. Right: Micro Four Third body cap



Thursday 7 February 2013

Tilt adapter for Micro Four Third - Part 2 - Lens selection

This is the second part of the series on a tilt adapter for Micro Four Third system. Please read the introduction first. The next article shows you how to build a simple adapter.

The first thing you need is to find a suitable lens. If you read the plungercam tutorial, you need to check 2 things: the flange focal distance, and the image sensor/film size.

Flange focal distance

The flange focal distance tells you the distance between the lens mount and the image sensor. For tilt-shift, you want to be able to move the lens around without hitting the camera, therefore, you need a lens with a flange focal distance larger than the one of the camera.

Flange range on a DSLR (top), versus mirror-less camera (bottom).
Drawn by Shigeru23 on Wikipedia (CC BY-SA 3.0).

Monday 4 February 2013

Tilt adapter for Micro Four Third - Part 1 - Introduction

This post is an introduction to the topic. See the next article for some advise on lens selection, and the following one for instructions to build a simple adapter.

Tilt-shift pictures are getting quite popular nowadays, especially the tilt effect that gives a miniature effect to pictures. This is especially beautiful in videos, an example is shown below.