Friday, 26 September 2014

How to make an ATtiny85-powered programmable intervalometer for Canon DSLR?

Remember that intervalometer I mentioned some time ago? Well, I made one for myself and since it's been working great for the last couple of weeks, I decided to share how I made it. If you'd like to build one yourself and shoot photos like this one:

or videos like this one (I strongly recommend downloading it as vimeo dramatically reduced its quality and frame rate - 60FPS was cut down to 30FPS):

01092014 Full HD 60FPS from Let Zweindaut on Vimeo.

, you will need:
  1. Perf board/stripboard:
  2. 8 Pin DIL IC Socket for the ATtiny85:
  3. 3.5mm stereo audio jack:
  4. NPN Transistor:
  5. 1MΩ resistor:
  6. Power source (in my case - a double AAA battery pack):
  7. Some sort of internally isolated enlosure (completely optional):

After you have all components prepared, you can start soldering, following the schematic:

I did it in following order, but it's completely up to you:
  1. I decided to start with the DIL socket:

  2. Next up, audio jack. Before you start soldering, let's take a closer look at this part:

    I am using only the shutter pin, but you can get creative and use the focus pin as well if you plan to focus automatically. The idea behind the build will remain similar.

  3. Followed by a transistor:

    Notice how transistor's collector is connected to the shutter pin, emitter to the ground pin (through a bridge) and base is not connected to anything yet. If you're having trouble telling which pin is the collector and which is the emmiter, take a look at this website.
  4. Resistor. This part connects transistor's base to ATtiny85's operational pin (in my case 0).

  5. Power source:

  6. And a ground reference (very sloppy, I know...):
  7. And it's finished!

Now, let's program it!

The program I'm using is just a slightly modified version of Arduino's sample Blink program. I added the initial delay, which will give you those few extra seconds before the shutter closes for the first time (I usually use that time to switch the camera's display off). My code looks like this:

int operationalPin = 0; // microcontroller's pin to be used
int initialDelay = 10000; // defines when the first photo should be taken, expressed in milliseconds
int shutterCloseTime = 100; // defines for how long the shutter should be closed, expressed in milliseconds
int gapBetweenShots = 3000; // defines the gap between every photo, expressed in milliseconds

void setup()
pinMode(operationalPin, OUTPUT);
delay(initialDelay); // initial delay

void loop()
digitalWrite(operationalPin, HIGH); // shutter closes
delay(shutterCloseTime); // keeping the shutter closed
digitalWrite(operationalPin, LOW); // shutter opens
delay(gapBetweenShots); // keeping the sutter open

The process of programming the ATtiny85 (actually getting the compiled code on the chip) is not covered here, but if you have an Arduino or a Teensy 3.1, you can take a look at an article I wrote some time ago on how to do it (it's here).

This concludes my tutorial, I hope it will prove useful to somebody. If you think it can be improved or have your own ideas for modifications, plese let me know in the comments section. If you'd like to share your intervalometer photos/videos, I *strongly* encourage you to do so!

Thanks and have a nice weekend!

Thursday, 11 September 2014

How to use a trimpot (or any three-legged potentiometer)?

First time I saw a trimpot (trim-pot as trimmer potentiometer, 10KΩ in my case) I immediaty started wondering why the heck does it have 3 pins. Would 2 not be just enough? I started googling and, surprisingly, the answer was not that easy to find. I'll share what I found out, but first, let me answer the title question: how to use a trimpot?
  1. First of all, if you flip the trimpot over, you will see 3 pins, just as on the diagram I clumsily prepared:

    That is the back of your trimpot. Well, you get the idea.

  2. Let's describe what's on the diagram. The two horizontally aligned pins (let's call them A and B) are your reference points and the third pin is called wiper.
  3. Now, the idea behind the trimpot is *brutally* simple:
    • Resistance between A and B is always constant (in my case, 10KΩ)
    • Restistance A-wiper and B-wiper varies depending on the trimpot's knob (or screw, whatever you have) so that if A-wiper is 10% of trimpot's nominal value, B-wiper will be (100% - 10%) of trimpot's nominal value.
And that's it, there's nothing more when it comes to trimpots. However, if you want some examples or if you're genuinely interested in what I have to say, please read on!

To follow up, let me list a couple of interesting facts about trimpots. Great majority of them has 3 pins, but there actually are trimpots with just two pins, like this one:

Why 3 and not 2 then? From what I've read, two most popular reasons are:
  • To keep soldered trimpots in place while adjusting their values. A lot of people simply ignore either pin A or B.
  • To utilise the fact that when the resistance on one side increases (e.g. A-wiper), the other one decreases (e.g. B-wiper), and vice-versa.
Additionally, as it turns out, trimpots are not really designed for adjusting their values too frequently - they are expected to work following the adjust-seal-forget formula. If you expect the resistance to change often, potentiometers are probably a better choice.

To illustrate how trimpots exactly work, I ran a couple of simple measurements (top: wiper, left: A, right: B). Before I start, though, please keep in mind that neighter my multimeter nor the trimpot are perfect, so expect some measurement imperfections. Also, the multimeter measures resistance in .

Trimpot's knob goes all the way down the B-wiper side. Whole resistance is allocated between A and wiper.
A-wiper measurement B-wiper measurement

Trimpot's knob goes all the way down the A-wiper side. Whole resistance is allocated between B and wiper.
A-wiper measurement B-wiper measurement

Trimpot's knob is somewhere in the middle of the range. Whole resistance is shared equally between A-wiper and B-wiper.
A-wiper measurement. I expected something around 5KΩ, but 5.00KΩ exactly is pure concidence. B-wiper measurement. 5.07KΩ - that's more like it!

Trimpot's knob is somewhere on the B-wiper side which means this side's resistance will be lower compared to the A-wiper side. Additionally, 7.00KΩ + 3.06KΩ = ~10KΩ, which is the nominal value of the trimpot.
A-wiper measurement. B-wiper measurement.

And finally, even though the trimpot's knob goes all the way down the B-wiper side, A-B resistance is always constant.
A-B measurement.

Sunday, 24 August 2014

Teensy 3.1 ISP - program an ATtiny85 with your Teensy!

A couple of weeks ago I had this brilliant idea of building an intervalometer for my canon 450D. As I already had my Teensy 3.1 at that stage, it was an obvious choice for me. I implemented a *very* simple Arduino code, uploaded it to my Teensy, hooked up some wires together and had a blast shooting some time lapse videos (see here for example).

However, I quickly realised that I want my intervalometer to be smaller, more portable and battery powered (no USB cable required). I started googling and discovered that people use their Arduinos as In-System Programmers (ISP, see here) to program smaller AVR chips like ATtiny85. What a brilliant idea! I quickly ordered some ATtinys and started building. Here are my results - who knows, maybe somebody will find them useful?

  1. First of all, you'll need to have the Teensy 3.1 configured and working with the Arduino IDE. To make sure everything is working as it should, please follow PJRC's tutorial. If you have already set up your Teensy 3.1, you can obviously skip this step.
  2. Open the Arduino IDE (I'm using version 1.0.5-r2). You should already see the ArduinoISP sketch in the Examples section (File -> Examples -> ArduinoISP).
    Select it and take a quick look at the source code. You should see a section where RESET, LED_HB, LED_ERR, etc. macros are defined. Since RESET's original value is SS, let's change it to 10. Additionally, make sure that the function start_pmode() calls spi_init() before anything else. Save the sketch and upload it to your Teensy 3.1.
  3. Now, let's wire the programmer's LEDs up. They will give you an indication of what your ISP is currently doing. And if it's not doing anything, you can always rely on the heartbeat LED. There are 3 LEDs I'm using:
    • Heartbeat (YELLOW, LED_HB, pin 9)
    • Error (RED, LED_ERR, pin 8)
    • Write (GREEN, LED_PMODE, pin 7)
  4. Now, the next step is to install the ATtiny85 definition in your Arduino IDE. David A. Mellis was kind enough to prepare ATtiny support libraries for the Arduino IDE and share it on GitHub (you can get the zip directly here).

    Once you download the zip, extract it and you should see a folder called attiny inside the package (attiny-master -> attiny). Copy the attiny folder to your Arduino's sketchbook folder's hardware subfolder (it should go like this: Arduino -> hardware -> attiny). Start or restart your Arduino IDE. You should see a list of newly added ATtiny definitions in the Board menu (Tools -> Board -> ATtiny...)

  5. Make sure your Teensy acts as a programmer from now on by choosing appropriate Programmer option (Tools -> Programmer -> Arduino as ISP):

    Select the basic Blink example and choose your board from the new list. I'm working with ATtiny85, so my choice is ATtiny85 (internal 1MHz clock) (I don't want it to consume too much energy, as it's going to be battery powered).

    The last thing before connecting the ATtiny is to make sure we are using correct pin number to drive the LED. ATtiny doesn't have pin 13 (otherwise it wouldn't be so tiny!), so let's change the value of the led variable to 0 (which, funnily enough, is ATtiny's pin number 5).

  6. Now, let's connect the ATtiny. Disconnect the Teensy and stick the ATtiny on a breadboard. Look closely at the top surface of the chip, you should see a small circular shape indicating where the RESET pin is. It will look like this:

    Connect the pins as follows:

    ATtiny85 Teensy 3.1
    RESET (1) 10
    VCC (8) 3.3V
    GND (4) GND
    7 13
    6 12
    5 11

    using the ATtiny's pinout sheet as a reference:

    Your connections should look like this:

  7. Now you are ready to program your ATtiny85. Connect your Teensy 3.1 again and, having the Blink example in front of you, simply upload it. If you connected everything correctly, avrdude should upload the Blink code with no problems reporting something like this:

    avrdude: verifying ...
    avrdude: 836 bytes of flash verified
    avrdude: Send: Q [51] [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]

    avrdude done. Thank you.

  8. Now your ATtiny85 is programmed and you can test it:
I had a couple of problems in the process, but it was mostly due to wrong connections. If avrdude complains about invalid ATtiny's signature (whether it's 0x000000 or 0xFFFFFF), double check the wires and try to connect everything again. I hope this is useful and I encourage you to let me know if it worked in for you.

Thanks and happy hacking!

Monday, 14 April 2014

Raspberry Pi - micro OS template

Just a very quick post to share my micro OS template for Raspberry Pi. I've been playing with this little device for the last two months and it's been a lot of fun for me. My main area of interest is the ARM assembly language which I can learn on a real device right now.

The template is written to serve as a starting point for those who want direct framebuffer access and nothing else (small GPU projects, simple debugger etc.). To use it, simply build it using YAGARTO (as soon as you install it, just run the 'make' command) and stick it on a SD card replacing an existing linux kernel (I'm using Arch Linux for Raspberry Pi).

As I'm not a professional ARM developer, I'm sure this code can be greatly improved, so your feedback is welcome!

Please find the project here:

Sunday, 12 January 2014

Multivariate polynomial representation library for .NET

Please feel free to take a look at my multivariate polynomial representation library for .NET:

I couldn't find any .NET libraries supporting representation of (single or multivariate) polynomials, so I wrote my own. It can help in machine learning-related tasks, such as polynomial regression, or just in any class of tasks where changing polynomial's coefficients and indeterminates is required.

Your feedback is welcome!