Coins bulied…

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…

Arduino-controlled IKEA Lamp

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.

Automating Screenshots with AutoHotKey

This is a tiny little script that can be extremely useful.

1
2
3
4
5
6
7
8
9
10
loop
{
; /capture=0 takes a screenshot of the whole desktop
; /capture=1 takes a screenshot of the active window
; /capture=2 takes a screenshot of the client area of the active window
Run, "%A_ProgramFiles%\IrfanView\i_view32.exe" /capture=1 /convert=d:\screenshot\capture_$U(`%Y-`%m-`%d_`%H`%M`%S).png
sleep, 30000
leftclick, 100, 10
}
return

This script will
1. take a screenshot of your active window (capture=1),
2. save it on your D:\ drive,
3. wait for 30 secs (30,000 millis)
4. click at the (100,10) point of your screen
5. … it will start the loop again.

Notes on PCB

This is more of a list of notes on custom PCB design rather than a proper post…

There is a pretty good tutorial on how to use Eagle on SparkFun.com. Eagle (the freeware version) can be downloaded for free here.

There is also a very useful library with most of the components available on Sparkfun.com here.

if you want to create a custom Arduino shield, a good starting point is this Proto Shield on ladyada.net.

There is a good list of companies that can produce pcbs on the cadsoft website.

SparkFun (through BatchPCB.com) and nuElectronics offer custom pcb manufacturing services; BatchPCB is basically sending everything to China and I’m assuming nuElectronics does the same.

Arduino & LCD Smartie

This weekend I played with the Arduino/LCD Smartie combination and I was impressed both by the results and by the simplicity of the whole project. If you have the right LCD shield and you don’t have to do any soldering, you can be up and running in 10-15 minutes.

For those who are not familiar with LCD Smartie (from the LCD Smartie website on sourceforge.net): LCD Smartie is software for Windows that you can use to show lots of different types of information on your LCD/VFD.

To use LCD Smartie with the arduino board, an LCD is required (duh…). I used a 16×2 LCD Shield, made by nuelectronics.

To get this up and running, I downloaded the modified 4 bit LCD library and LCD Smartie on Arduino sketch (both files are available here. This takes less than 5 minutes.

After that, it’s only a matter of setting up the LCD Smartie options. I spent most of my time trying to decide which messages I would like to see on the screen.

Here are a few examples:

Free space on D: Drive

The above example, shows the space available on my D: drive.

CPU & Memory usage

This one shows the the CPU and RAM usage.

Uptime and current IP address
This example shows the uptime and the current IP address.

Buttons

You can set LCD Smartie up to rotate the messages. I set mine to 3 secs per message. If you have many messages and you need to quickly get to get to a specific message, you can use the buttons on the shield for navigation.

Other available messages include title of incoming emails, RSS feeds, Winamp info (title, artist etc).

Now all I need is to build a nice little box for it… 🙂

simpleDateFormat in Processing

I spent about an hour, trying to figure out how to use the simpleDateFormat java library in Processing… It seemed so straight forward, yet I couldn’t get it to work…

Well, it seems that the only thing I had to add is a try/catch.

So, this example works:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.text.*;
Date myDate;
 
void setup(){
SimpleDateFormat myDateFormat = new SimpleDateFormat("yyyyMMdd");
 
try {
myDate = myDateFormat.parse("20001010");
} catch (Exception e) {
  println("Unable to parse date stamp");
} 
 
println(myDate);
}

but this one does not, even though there is no error to catch…

1
2
3
4
5
6
7
8
import java.text.*;
Date myDate;
 
void setup(){
SimpleDateFormat myDateFormat = new SimpleDateFormat("yyyyMMdd");
myDate = myDateFormat.parse("20001010");
println(myDate);
}

I’m not sure why this is the case. If anyone does, please let me know!