Archive for September, 2009

Arduino Project: Intervalometer for Fuji cameras

Posted by admin on September 19, 2009
Arduino, Processing, Projects / 8 Comments

This post is about an arduino-based intervalometer I built for my camera, a Fuji S9600 dSLR.

I decided to go for a very simple interface: a rotary switch in the middle of a plastic box which would allow me to select 12 pre-defined intervals. I went for a switch and not a potentiometer because I wanted to be certain about the option I select: the reassuring “click” of the rotary switch does exactly that!

Also, I wanted to make the device easy to use, so the labelling of the different options around the rotary switch was very important too.

The Fuji S9600 (a.k.a. Fuji S9100 in the States) has a mini-B USB connector on the side which is used, amongst other things, for a remote shutter release cable. Bob Mahar has “dissected” an original Fuji RR-80 remote release cable and has revealed that the device is actually very simple inside; Bob’s great page on the Fuji RR-80 is here: http://www.trafficshaper.com/RR-80/RR-80.html.

Based on Bob’s page, I came up with the following diagram for the RR-80:

circuit_rr80_5_w500

The circuit of the RR80 is simple to build, but I couldn’t find a suitable mini-B USB plug: remember, the camera uses the 5th pin, which is not always available on the plugs you can buy online or at Maplin’s.
http://en.wikipedia.org/wiki/Universal_Serial_Bus
http://en.wikipedia.org/wiki/File:Types-usb_new.svg

After a couple of failed attempts to source a 5-pin USB mini-B connector, I ended up buying a cheap Chinese RR80 clone:

dscf0890_w500

I was actually lucky, because this model has a 2.5″ jack on the side, which allows two cameras to be sync’d (not all the clones have this, I think the JJC clones marked “MA” have it). This meant that I could use a 2.5″ stereo connector in order to connect the arduino with the remote. All the arduino has to do in order to take a photo is to short 2 of the 3 parts of the stereo connector.

dscf0893_w500

I used an old Sparkfun Skinny arduino (it is called “Arduino Pro” now and it’s not red anymore):

dscf1065_w500

This is a 12-pole rotary switch from Maplin and 12 resistors:

dscf1050_w500

I found a simple plastic box at Muji:

Muji Box

First things first: I converted the rotary switch into a “potentiometer”:

dscf1097_w500

In case it’s not clear from the image above, I connected all the pins in the periphery with resistors. The yellow cable coming out from the middle pin of the switch goes to the analog In pin (pin 5 here). The black cable coming out from the 12th pin of the switch goes to the ground and the red cable coming out from the 1st pin of the switch goes to the 3.3V arduino output.

At the opposite side of the arduino board, I used a blue LED on pin 13 (and ground) and on pin 12 I connected a transistor, 2N222A: http://en.wikipedia.org/wiki/File:2n2222A_and_schema.jpg) and the cable (twisted red-black) from the 2.5″ connector.

dscf1078_w500

Here is a better diagram of the wiring of the transistor (to keep things simple, only the transistor is shown here):
transistor1

For more information on the use of transistors as switches: http://en.wikipedia.org/wiki/Bipolar_junction_transistor

After a few minor tweaks, the prototype was up and running:
dscf1077_w500

The code loaded on the arduino is pretty simple really:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
///////////////////////////////////////////////////
int swPin  =  5;  // 12-step switch
int ledPin = 13;  // Blue & pcb leds
int camPin = 12;  // Camera pin
 
int sw    = 0;  // 12-step resistance value
int stage = 1;  // 12-step stage (i.e. 1 - 12)
 
// this delay is specified by the rotary switch
int  delaySec;   
 
// this is the current second count
long currentSec = 0;   
 
// this is how long the shutter switch will be on
long shutterSec  = 100; 
 
///////////////////////////////////////////////////
void setup() {
 
  // declare the swPin & ledPin as an OUTPUTs
  pinMode(ledPin, OUTPUT);  
  pinMode(swPin,  OUTPUT);
 
// the serial is only used for debugging and for
// the calibration of the rotary switch  
//  Serial.begin(9600); 
 
}
 
///////////////////////////////////////////////////
// I 
void loop() {
  readSwitch();
  timeCheck();
 
// printLine is only used for debugging and for
// the calibration of the rotary switch
//  printLine(); 
}
 
///////////////////////////////////////////////////
///////////////////////////////////////////////////
void timeCheck(){
  if(delaySec<=currentSec){
 
    digitalWrite(ledPin, HIGH);  // turn the ledPin on
    digitalWrite(camPin, HIGH);  // turn the camPin on
 
    delay(shutterSec); // keep the led and the switch on
 
    digitalWrite(ledPin, LOW);   // turn the ledPin off
    digitalWrite(camPin, LOW);   // turn the camPin off
 
    delay(1000-shutterSec);
    currentSec = 0;
  }
 
  else{
    delay(1000);
    currentSec = currentSec + 1;
  }
}
///////////////////////////////////////////////////
void readSwitch(){
 
  // read the value from the sensor
  sw = analogRead(swPin);  
 
// the serial is only used for debugging and for
// the calibration of the rotary switch 
//  Serial.print(sw);
 
  if(sw>=0  && sw< 20) {
    stage =  1; 
    delaySec =   10;
  } // 10 secs
  if(sw>=20  && sw< 110) {
    stage =  2; 
    delaySec =   20;
  } // 20 secs
  if(sw>=110  && sw< 200) {
    stage =  3; 
    delaySec =   30;
  } // 30 secs
  if(sw>=200  && sw< 290) {
    stage =  4; 
    delaySec =   60;
  } // 1 min
  if(sw>=290  && sw< 380) {
    stage =  5; 
    delaySec =   90;
  } // 1.5 mins
  if(sw>=380  && sw< 480) {
    stage =  6; 
    delaySec =  120;
  } // 2 mins
  if(sw>=480  && sw< 570) {
    stage =  7; 
    delaySec =  180;
  } // 3 mins
  if(sw>=570  && sw< 660) {
    stage =  8; 
    delaySec =  300;
  } // 5 mins
  if(sw>=660  && sw<750) {
    stage =  9; 
    delaySec =  600;
  } // 10 mins
  if(sw>=750 && sw<850) {
    stage = 10; 
    delaySec =  900;
  } // 15 mins
  if(sw>=850 && sw<950) {
    stage = 11; 
    delaySec = 1200;
  } // 20 mins 
  if(sw>=950 && sw<1024) {
    stage = 12; 
    delaySec = 1800;
  } // 30 mins
}
///////////////////////////////////////////////////
void printLine(){
  Serial.print(" - Stage: ");
  Serial.print(stage);  
  Serial.print(" (");
  Serial.print(delaySec);    
  Serial.print(") - Next shot in: ");
  Serial.print(delaySec - currentSec);    
  Serial.println();
}
///////////////////////////////////////////////////

In order to calibrate the rotary switch, I had enabled the printLine() function (which is commented out in the loop() above and I got the following results on the terminal window (the first number on each line is the pin5 analog in reading):

serial_settings

Now it’s time to put everything in the box. I used my soldering iron to make the necessary holes on the box (I have a tip which I only use to make holes on plastic). Here is everything placed in the box for the first time (to make sure that everything fits the way it should).

dscf1099_w500

dscf1090_w500

The black surfaces you see on bottom of the box are foam boards; you can find them at art supplies shops. The foam boards are easy to cut and shape and, in this case, prevent the battery and the remote control moving around the box.

Bare box #1

My next task was to come up with a way of indicating the time interval of each one of the 12 stages of the rotary switch. I didn’t think twice – this was a nice and easy job for processing. I created this image, which I got printed as a 5″ x 7″ in matt paper at photobox.com (10 s = 10 seconds, 1 m = 1 minute):

frame_w500

The Processing code below created the above image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
PFont myFont;
PFont myFont2;
 
float thisStage;
float nextStage;
 
float tp24 = TWO_PI/24;
 
void setup() {
  size(750, 1070);
  background(255);
 
  smooth();
  noStroke();
 
  float adj = -17 * tp24; 
  float space = TWO_PI/120;
  int diameter = 400;
 
  String[] stage = {    
    "10 s", "20 s", "30 s" , "1 m", 
    "1.5 m", "2 m", "3 m", "5 m", 
    "10 m", "15 m", "20 m", "30 m"  };
 
 
//remember to create the Arial-BoldMT-48 font
//otherwise this is not going to work...
  myFont = createFont("Arial-BoldMT-48", 18,true);
  myFont2 = createFont("Arial-BoldMT-48", 38,true);
 
  for (int i = 0; i < stage.length; i++){
 
    thisStage = (TWO_PI * i /12  - adj);
    nextStage = (TWO_PI *(i+1)/12 - adj);
 
    fill(0,50,100);
    noStroke();
    arc(width/2, 225, diameter, diameter, thisStage, nextStage);
    fill(255);
    arc(width/2, 225, diameter, diameter, nextStage  - space, nextStage);
    arc(width/2, 225, diameter, diameter, thisStage, thisStage + space);
 
    fill(150);
    stroke(150);
    textFont(myFont); 
 
    textAlign(CENTER,CENTER); 
    text(stage[i],(width/2) + diameter * 0.43 * cos( thisStage + tp24 ), 
225 + diameter * 0.43 *sin(thisStage + tp24 ));   
 
  }
 
  //this is the middle white circle
  fill(255);
  ellipse(width/2, 225, diameter * 0.6, diameter * 0.6);
 
  fill(0,50,100);
  noStroke();
  rect(0,0,150,150);
  rect(width-150,0,150,150);
  rect(0,450,width,150);
  rect(0,height-150,width,150);
 
  fill(0);
  stroke(0);
 
  textFont(myFont2); 
  textAlign(CENTER,CENTER); 
  text("Arduino-based Intervalometer 
\n for Fuji Digital SLRs", width/2,height -150 - (450/2) );   
 
  textFont(myFont); 
  textAlign(CENTER,CENTER); 
  text("www.arkadian.eu", width/2,height -200);   
 
  fill(0,50,100,100);
  noStroke();
  for(int x = 1; x < 30; x++){
    rect(int(random(0,width)),int(random(450,height-150)),20,20);
  }
  saveFrame("frame.png"); 
}

The 7″ x 5″ prints in matt paper (the glossy photo paper would get fingerprints):

dscf1121_w500

I had to make two more holes at the top part of the box to secure the cover.

Here is my intervalometer in its final form.

dscf1136_w500

dscf1125_w500

As you can see from the photo below, the intervals are clearly visible:

dscf1131_w500

That’s it, the end… In the next few weeks I will post a couple of videos put together using frames taken with this brand new intervalometer.

This must be my longest post ever…

Tags: , , , ,

Coins bulied…

Posted by admin on September 09, 2009
Videos / Comments Off

This post is about a stop-motion animation clip I made, using my new remote shutter gadget for my digital camera.

Basically, I took about 360 shots within about an hour using my Fuji FinePix S9600 on a tripod, my newly acquired remote shutter control and a few coins. All the shots were taken at 9 megapixels and then resized using IrfanView (freeware) to a more manageable size. I then used MonkeyJam (freeware) to put together this 30 seconds clip.

I know… my finger appears a few times, but remember: this is was only supposed to be a test :)

Note: No coins were harmed during filming…

Tags: ,

Arduino-controlled IKEA Lamp

Posted by admin on September 07, 2009
Arduino, Projects / 10 Comments

This is a project I have been working on for the past 2-3 weeks. I wanted to create a night light which had to be very simple to use and with no parts that can be consumed by babies! :)

I used 20 RGB LEDs (which I got from www.oomlout.co.uk), an old Eriksson phone charger and, of course an arduino board (actually I used an old SparkFun clone). And a push button… And an Ikea lamp (”Lampan”, currently priced at £2.59 in the UK, around $5 in the States, http://www.ikea.com/gb/en/catalog/products/40055420). This is a very cheap lamp, very hackable and safe for kids too (as all the components are safely hidden away). Many projects are based around this lamp:
http://ikeahacker.blogspot.com/2007/08/new-look-for-lampan-lamp.html
http://www.instructables.com/id/Big-lamps-from-Ikea-lampan-lamps./

I found that the old Eriksson charger delivers approx 6V, which is good enough for the Arduino. I removed the original plug from the charger and added a standard 9V clip instead.

erikkson adapter

I did the same on the IKEA lamp – I added 9V clips on both sides of the cable.
lamp_inside

Charger Connected

I fitted the 20 LEDs on one board. It’s important to note that the LEDs fit nicely on a standard board if you put them diagonally. I’m not good at soldering, but putting together this board was actually easier than I originally anticipated.
For more information on these RGB LEDs, have a look at this great one page summary kindly put together from the Oomlout team: http://oomlout.com/RGBL/RGBL-Guide.pdf

20_leds

leds_diagonal

A useful, probably obvious, tip is that it helps if, throughout the project, you are using colour coded cables (i.e. red cable for the red pins etc…).
leds_back

Here is the final lamp:
combination

Here is a video demonstration – at the end of the video you can see the random mode, where the colours change gradually:

Arduino-powered IKEA Lampan Lamp from Arkadian.Eu on Vimeo.

… and here is the arduino code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <EEPROM.h>
 
//RGB LED pins - These pins must be PWM
//here: 9 = redPin, 10 = greenPin, 11 = bluePin
int ledAnalogOne[] = {
  9, 10, 11}; 
 
// Push button, any free digital pin will do
int myButton = 7;
// I will fix pin 13 at HIGH at setup and use it as another voltage pin.
// It also lights the onboard led.
int my13 = 13;
 
// Reading the previous selection from the eeprom memory
int myOption = EEPROM.read(0);
 
int options = 15;
 
// these following are useful for debouncing
int mydelay = 10;
int reading = 0;
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 300;   // the debounce time; increase if the output flickers
 
//Defined Colors (different RGB (red, green, blue) values for colors
const byte RED[] =     {255, 0, 0}; 
const byte ORANGE[] =  {83, 4, 0}; 
const byte YELLOW[] =  {255, 255, 0}; 
const byte GREEN[] =   {0, 255, 0}; 
const byte BLUE[] =    {0, 0, 255}; 
const byte WHITE[] =   {255, 255, 255}; 
const byte BLACK[] =   {0, 0, 0}; 
const byte PINK[] =    {158, 4, 79}; 
const byte B2[] =      {0, 128, 255}; 
const byte G2[] =      {128, 255, 0}; 
const byte R2[] =      {255, 128, 0}; 
const byte B3[] =      {128, 0, 255}; 
const byte G3[] =      {0, 255, 128}; 
const byte R3[] =      {255, 0, 128}; 
 
byte myOldC[] = {255, 255, 255};
 
void setup(){
for(int i = 0; i < 3; i++){pinMode(ledAnalogOne[i], OUTPUT);}
setColor(ledAnalogOne, BLACK);       //Turn off led 1
pinMode(my13, OUTPUT);   
digitalWrite(my13, HIGH);
Serial.begin (9600);
}
 
void loop(){  
 
  readButton();
 
    if(myOption==0){
    mydelay = 15;
    randomC();
    }
 
    if(myOption==1){
    mydelay = 0;
    setColor(ledAnalogOne, RED);
    }    
 
    if(myOption==2){
    mydelay = 0;
    setColor(ledAnalogOne, BLUE);
    }       
 
    if(myOption==3){
    mydelay = 0;
    setColor(ledAnalogOne, GREEN);
    }  
 
    if(myOption==4){
    mydelay = 0;
    setColor(ledAnalogOne, YELLOW);
    }  
 
    if(myOption==5){
    mydelay = 0;
    setColor(ledAnalogOne, PINK);
    }    
 
    if(myOption==6){
    mydelay = 0;
    setColor(ledAnalogOne, ORANGE);
    } 
 
    if(myOption==7){
    mydelay = 0;
    setColor(ledAnalogOne, B2);
    }  
 
    if(myOption==8){
    mydelay = 0;
    setColor(ledAnalogOne, G2);
    }  
 
    if(myOption==9){
    mydelay = 0;
    setColor(ledAnalogOne, R2);
    }     
 
    if(myOption==10){
    mydelay = 0;
    setColor(ledAnalogOne, B3);
    }  
 
    if(myOption==11){
    mydelay = 0;
    setColor(ledAnalogOne, G3);
    }  
 
    if(myOption==12){
    mydelay = 0;
    setColor(ledAnalogOne, R3);
    }     
 
    if(myOption==13){
    mydelay = 0;
    setColor(ledAnalogOne, WHITE);
    }    
 
    if(myOption==14){
    mydelay = 0;
    setColor(ledAnalogOne, BLACK);
    } 
}
//////////////////////////////////////////////////////////////
 
void readButton(){
 
   reading = digitalRead(myButton);
   if ((millis() - lastDebounceTime) > debounceDelay && digitalRead(myButton)== HIGH) {
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:
     lastDebounceTime = millis();
 
   myOption = (myOption + 1) % options;
   EEPROM.write(0, myOption);
//   Serial.print ("PRESSED - ");
//   Serial.println (myOption);
   }
}
 
 
//////////////////////////////////////////////////////////////
void randomC(){
 int tmp = int(random(0,12));
 byte myRandomC[] = {0,0,0};
 
  if(tmp == 0){for(int i = 0; i < 3; i++){myRandomC[i] = RED[i];}}
  if(tmp == 1){for(int i = 0; i < 3; i++){myRandomC[i] = ORANGE[i];}}
  if(tmp == 2){for(int i = 0; i < 3; i++){myRandomC[i] = YELLOW[i];}}
  if(tmp == 3){for(int i = 0; i < 3; i++){myRandomC[i] = GREEN[i];}}
  if(tmp == 4){for(int i = 0; i < 3; i++){myRandomC[i] = BLUE[i];}}
  if(tmp == 5){for(int i = 0; i < 3; i++){myRandomC[i] = B2[i];}}
  if(tmp == 6){for(int i = 0; i < 3; i++){myRandomC[i] = G2[i];}}
  if(tmp == 7){for(int i = 0; i < 3; i++){myRandomC[i] = R2[i];}}
  if(tmp == 8){for(int i = 0; i < 3; i++){myRandomC[i] = B3[i];}}
  if(tmp == 9){for(int i = 0; i < 3; i++){myRandomC[i] = G3[i];}}
  if(tmp ==10){for(int i = 0; i < 3; i++){myRandomC[i] = R3[i];}}
  if(tmp ==11){for(int i = 0; i < 3; i++){myRandomC[i] = WHITE[i];}}
  if(tmp ==12){for(int i = 0; i < 3; i++){myRandomC[i] = PINK[i];}}
 
    fadeToColor(ledAnalogOne, myOldC, myRandomC,  mydelay );     
 
    myOldC[0]= myRandomC[0];
    myOldC[1]= myRandomC[1];
    myOldC[2]= myRandomC[2];
}
 
//////////////////////////////////////////////////////////////
////////////// Functions from oomlout.co.uk.... //////////////
//////////////////////////////////////////////////////////////
/* Sets the color of the LED to any RGB Value
 led - (int array of three values defining the LEDs pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin))
 color - (byte array of three values defing an RGB color to display (color[0] = new Red value, color[1] = new Green value, color[2] = new Red value
 */
void setColor(int* led, byte* color){
  for(int i = 0; i < 3; i++){             //iterate through each of the three pins (red green blue)
    analogWrite(led[i], 255 - color[i]);  //set the analog output value of each pin to the input value (ie led[0] (red pin) to 255- color[0] (red input color)
    //we use 255 - the value because our RGB LED is common anode, this means a color is full on when we output analogWrite(pin, 0)
    //and off when we output analogWrite(pin, 255). 
  }
}
 
/* A version of setColor that takes a predefined color (neccesary to allow const int pre-defined colors */
void setColor(int* led, const byte* color){
  byte tempByte[] = {color[0], color[1], color[2]};
  setColor(led, tempByte);
}
 
/* Fades the LED from a start color to an end color at fadeSpeed
 led - (int array of three values defining the LEDs pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin))
 startCcolor - (byte array of three values defing the start RGB color (startColor[0] = start Red value, startColor[1] = start Green value, startColor[2] = start Red value
 endCcolor - (byte array of three values defing the finished RGB color (endColor[0] = end Red value, endColor[1] = end Green value, endColor[2] = end Red value
 fadeSpeed - this is the delay in milliseconds between steps, defines the speed of the fade
 */
void fadeToColor(int* led, byte* startColor, byte* endColor, int fadeSpeed){
  int changeRed = endColor[0] - startColor[0];                            //the difference in the two colors for the red channel
  int changeGreen = endColor[1] - startColor[1];                          //the difference in the two colors for the green channel 
  int changeBlue = endColor[2] - startColor[2];                           //the difference in the two colors for the blue channel
  int steps = max(abs(changeRed),max(abs(changeGreen), abs(changeBlue))); //make the number of change steps the maximum channel change
 
    for(int i = 0 ; i < steps; i++){                                       //iterate for the channel with the maximum change
    byte newRed = startColor[0] + (i * changeRed / steps);                 //the newRed intensity dependant on the start intensity and the change determined above
    byte newGreen = startColor[1] + (i * changeGreen / steps);             //the newGreen intensity
    byte newBlue = startColor[2] + (i * changeBlue / steps);               //the newBlue intensity
    byte newColor[] = {newRed, newGreen, newBlue};                         //Define an RGB color array for the new color
    setColor(led, newColor);    //Set the LED to the calculated value
    readButton();  
    if(myOption==0){delay(fadeSpeed);}  
  }
  setColor(led, endColor);                 //The LED should be at the endColor but set to endColor to avoid rounding errors
}
 
/* A version of fadeToColor that takes predefined colors (neccesary to allow const int pre-defined colors */
void fadeToColor(int* led, const byte* startColor, const byte* endColor, int fadeSpeed){
  byte tempByte1[] = {startColor[0], startColor[1], startColor[2]};
  byte tempByte2[] = {endColor[0], endColor[1], endColor[2]};
  fadeToColor(led, tempByte1, tempByte2, fadeSpeed);
}
//////////////////////////////////////////////////////////////

If you are thinking of building something similar and you have any questions, just drop me a line.

Tags: , , , ,