Archive for » septembre, 2008 «

Samedi, septembre 27th, 2008 | Author: admin

Sometimes, it could be handy if your router (in this case, a WRT54G) could restart the device that connects it to the internet. For instance, if your ADSL modem needs some reboot or your cable modem needs a kick, having the WRT to do this would be nice.

This could be especially useful if the modem+router are deployed as an access point somewhere in the wild.

This usage is not limitating : we’re gonna build a WRT managed relay. What you switch on/off with this relay is your problem. A modem seems a reasonable idea, but you could switch a coffee pot (in this case, you should go with HTCPCP [http://www.ietf.org/rfc/rfc2324.txt]), lights, etc…

All this is possible with little modification. The behaviour of the system here is to switch the relay for approx. 14 seconds, but this time is also easy to change. You can even use a trim pot instead to make it fully tunable.

Schematics

Relay board schematic

Relay board schematic

The schematic is rather simple. The board is connected to the internal WRT54G serial port (TX pin). This pin uses LV-TLL signals (0, +3.3V), and logic high is 0V. In other words, when nothing is send out to the serial port by the WRT, the level is low and the TX pin show 3.3V. What we want is to activate the relay when voltage on this pins drop. The trick is to feed the TX pin to the Threshold pin of a 555 timer (see those excellent 555 links in Electronics Club and Mecanno Electronique in french). And this is what happens when we the WRT sends data to the serial port : square wave comes out of second serial port TX pin and triggers the 555. For this to work, the 555 is powered at 6V, and thus triggered when TX voltage drops below 2V (approx 1/3 of VCC). The 6V feed is very primitive and comes from WRT power (12V) sliced in half by a voltage divider. It would be wiser to use a voltage regulator (7805 or al.), but we’re going the easy way here.

The trigger from the 555 is fed at the base of the 2N2222 transistor which in turns feed the coil enough current to switch.

Primitive, as I said.

Assembling it

First, be aware that doing the bad things below will void your WRT warranty, your modem warranty. You also can burn things or yourself in the process, etc… So do at your own risk. This being said, that stuff has been my first electronics project so it is really easy. “my first electronics project” should also be taken as a warning.

  • Open your WRT54G (or GS, or GL) by pulling the blue cover out
  • Take the WRT PCB out.
  • Solder a wire in the TX pin (pin 3) of the serial port

Soldering this port is really easy, even I did it without breaking anything or melting the router to a shapeless plastic blob. You’ll find more info and pictures on the LinkSys WRT5G/GS Dual Port Mod Page. You don’t need IDC headers or high end stuff like this. Just solder in the hole. It will be ok as long as you don’t pull too much on the wire.

The blue front cover has holes inside. These holes can’t be seen from the outside because of the stickers. This is a good place to make a complete hole with a hot wire if you plan to put your PCB relay outside the WRT. For recent models, like the GL, the PCB can probably fit inside.

  • Pull the TX cable through the blue cover and assemble the WRT back
  • Solder the wires with the DC power jacks on the board
  • Cut power cables from modem and WRT. Be sure to cut it at the right place ! You need enough cable to plug the wall wart and enough cable to plug the modem and WRT.
  • Remove some insulating material from the power wires and insert them in the screm clamps. Don’t mess with polarity or which wire go where. You would burn something for sure.
  • Now we need software to get this going. The basic idea is to ping some IP address, and when consecutive failures are detected, the relay is activated and the stuff behind it reboots. You can push the shell script to the WRT running Sveasoft firmware under Administration/Diagnostocs/Run, then paster script and click “Save Startup”. You can do the same with OpenWRT and probably with other firmwares.

wrt.sh


#!/bin/sh

########### Tunable Variables #############
# which host to check
checkhost="212.27.48.10"

# how often to check
checkinterval=20

# how many failures to activate relay
activateafter=3

# where is the wrt_relay_mod
# serial=/tmp/test
serial=/dev/tts/1

# how long should we rest after switching
rest=120

# how many log/debug lines do we keep
keeplines=20
########### End Variables #################

#
pingfail=0
logfile=/tmp/wrm.log
debuglogfile=/tmp/wrm_debug.log
version=1
#

log() {
echo -n `date` >> $logfile
echo " : "${1} >> $logfile

# trim log file
head -n 8 $logfile > $logfile.tmp
tail -n $keeplines $logfile >> $logfile.tmp
mv $logfile.tmp $logfile
}

debug() {
echo -n `date` >> $debuglogfile
echo " : "${1} >> $debuglogfile

# trim debug file
tail -n $keeplines $debuglogfile > $debuglogfile.tmp
mv $debuglogfile.tmp $debuglogfile
}

check_loop() {
# we sleep $checkinterval seconds
sleep $checkinterval

if ping -qn -c 1 $checkhost > /dev/null ; then
# network is ok
pingfail=0
debug "/-\ => ping ok"
sleep $checkinterval
else
# network seems down
pingfail=`expr $pingfail + 1`
debug "/?\ => $pingfail ping failures"

if [ $pingfail -ge $activateafter ]; then
log “relay switched”
debug “/!\ => switching relay…”
echo ACTIVATE > $serial
debug “/-\ => resting for $rest seconds”
pingfail=0
sleep `expr $rest - $checkinterval`
fi
fi
}

# log few information at boot
log “######################################”
log “# wrm daemon version $version starting”
log “# checkhost=$checkhost”
log “# checkinterval=$checkinterval”
log “# activateafter=$activateafter”
log “# serial=$serial”
log “# rest=$rest”
log “######################################”

# initial rest
sleep $rest

# control loop
while true; do check_loop; done

Tune variables at your liking. You can see how the relay is software activated : it just writes ‘ACTIVATE’ to the device driving the second serial port. What you write is not important. ’saddam’ and ‘george’ work equally well for instance. You should also restrain yourself from logging too much. The idel situation for deployment is to disable debug and logging. Space is scarce on the WRT.

Here is the final thing assembler, with the driver modem (a Terayon TJ720). The system works fine but isAssembled setup quite static sensitive. So discharge yourself somewhere before touching the running circuit, or the relay might activate. Also, proper casing should be done. Putting the circuit inside the WRT is possible with latter models (WRT54GS and WRT54GL). This hasn’t been tester though, and might put some noise inside.

Bill of materials

Building this stuff shouldn’t take more than 2 hours and if you wish to buy parts, it will cost less than 4€ (3.0€ each by 20 at GoTronic in France).

Here is the list of components required :

Component Quantity
MINIATURE RELAY 6-12V/12V-2A 1
TWO WAY TERMINAL BLOCK 2
1K RESIST. CARBON 1/4-5% 2
47K RESIST. CARBON 1/4-5% 1
33K RESIST. CARBON 1/4-5% 1
TRANSISTOR NPN 50V-0.2A 1
CAPACITOR 10n 1
CAPACITOR 220u 1
CAPACITOR 100u 1
DIODE 1A 1N4007 or eq. 1
DIODE 1N4148 or eq. 1
NE555 TIMER 1
LED 5MM RED (not in schematics) 1
LEDS 5MM GREEN (not in schematics) 1
PROTO BOARD (approx 20 holes x 20 holes) or PCB to etch 1

Besides the board and may be the 555, the rest is easily scavengeable.

Category: electronics, projects  | Tags: ,  | Leave a Comment
Samedi, septembre 27th, 2008 | Author: admin

Here is the pinout for the standard Cisco serial console cable (DB9 - RJ45) like this one.

Note that DCD(1) and RI(9) are not wired.

This cable is quite handy when doing µcontroller stuff. Just put a RJ45 socket on your PCB our get a breakout board from Sparkfun and you can plug and unplug at will and securely.

DB 9 Serial pin Color RJ 45
8 CTS Black 1
6 DSR Brown 2
2 RX Red 3
5 GND Orange 4
5 GND Yellow 5
3 TX Green 6
4 DTR Blue 7
7 CTS Grey 8
Category: electronics  | Tags: , , ,  | Leave a Comment
Samedi, septembre 27th, 2008 | Author: admin

The Project

After chasing the idea of building a remote for my D50, I found this really interesting page with all you need (especially the IR timing) to get your remote up and running.

But using a AtTiny2313 for this leaves a lot of room to play with. So I made an enhanced version with a 7-segments display and a menu system. The new firmware let’s you choose among several shooting modes.

The remote is almost identical to the BigMike’s one except :

  • the firmware is, of course, modified
  • there is no On/Off button
  • there are two buttons for the menu (change/select)
  • there is a 7-segments display for the menu
Remote control

Remote control

The firmware sets the Tiny2313 in sleep mode after 5 seconds of inactivity.
In tis mode, the datasheet gives at most 2µA current usage. So, since a CR2032 yields 220 mAh, and if I didn’t mess up somehere, you should be up and running for 10 years.

Modes description

The remote offers 9 shot modes, which of course can be changed in the firmware.

Whatever the mode, the dp dot blinks everytime a “take shot” IR frame is sent.

  • Single shot mode (symbol : reversed lower ‘c’) : one button press makes a single shot
  • Double shot mode (symbol : two horizontal dashes ) : one button press makes two shots in a row
  • Triple shot mode (symbol : three horizontal dashes ) : one button press makes three shots in a row
  • Continuous shot (symbol : lower ‘c’) : one button press starts continuous shooting as fast as possible until the ‘menu’ button is pressed again or the battery is dead :)
  • Continuous shot every second (symbol : number 1) : one button press starts shooting 1 picture per second until the ‘menu’ button is pressed again or the battery is dead

Numbers 2, 5, 0 and 6 are also continuous shoot mode with 1 picture every 2, 5 10 and 60 seconds respectively.

Modes selection

Modes selection

Files

Wanna build yours ? You’ll need :

Circuit schematic

Circuit schematic

Circuit board layout

Circuit board layout

The core of the code (IR timing loop) is taken straight from BigMike’s ASM source.

Issues

There are some issues in my version. I am not sure if they are firmware/hardware/ir issues. The problem is the reliability of triggering : sometimes it just doesn’t work. This does make the remote of reduced usability for continuous shooting modes where timing is critical.

I wonder where this problem comes from : IR receptor low sensitivity ? inaccurate frequency generation ? AF mode induced triggering problems in some situations ?
Since I have relatively few hardware here (no friend with another D50, no oscilloscope, …) I didn’t dig it up for now.

And oh, BTW, the usual warnings apply : this remote can brick your MCU, destroy your Nikon, set your house on fire, etc… You’ve been warned !

Thanks

Big thanks to Bighignoli Michele, Jonas Diemer and Nate who pioneered the area.

EDIT : I finally managed to put my hands back on the firmware ! You can grab the ASM source or the hex file. Have fun !

Category: electronics, projects, video  | Tags: , , ,  | 5 Comments
Samedi, septembre 27th, 2008 | Author: admin

http://www.nearfuturelaboratory.com/2008/07/07/ds1803-digital-potentiometer/

Samedi, septembre 27th, 2008 | Author: admin

Product page

Category: chips, electronics  | Tags: ,  | Leave a Comment
Samedi, septembre 27th, 2008 | Author: admin

Useful file copy snippets collection for systems administration. scp is not here : syntax is trivial, and scp is really slow. The snippets below are supposed to be much faster, especially when dealing with many small files.

netcat style

  • On sender :

cd to the top dir to be copied recursively, and :
tar cv . | nc -vq 10 -l -p 1234

  • On receiver :

cd to the dir where the content has to be copied, and :
nc -v sender 1234 | tar xf -

ssh style

  • Data is remote, copy to where I am now :

ssh user@source "cd /source/dir; tar cv ." | tar x

  • Data is in current directory, copy to remote server :

tar cv . | ssh user@destination "cd /dest/dir; tar x"

rsync+ssh style

  • Data is in current directory, copy to remote server :

rsync -ve ssh -ar . user@destination:/dest/dir/

Note : add ‘z’ to tar options if link is slow

Category: sysadmin  | Tags: , , , , , ,  | Leave a Comment
Samedi, septembre 27th, 2008 | Author: admin

Battery internal resistance forms a divider with external load.
So to calculate internal resistance, take those steps :

  • measure the battery voltage without load (Vnoload)
  • measure again with a resistor of RloadΩ attached (the lower ohm value, the better, but watch outfor power ratings !), you have a difference with previous measurement (Vdrop)

The battery internal resistance is then :

Rbattery = Vdrop*Rload/(Vdrop+Vnoload)

Real world example on AA :

Vnoload = 1.421v
Rload = 460Ω
Vdrop = 0.002v

Thus : Rbattery = (0.002 x 460)/(0.002 + 1.421) = 0.65Ω
Since my metter has a milliVolts resolution, we just have a range between 0.001 and 0.003 for Vdrop.
So Rbattery can be anything between 0.33Ω and 1Ω.

Short-circuit current for this AA battery would be somewhere between 1.421/0.33 = 4.33A and 1.421/1 = 1.42A
Mesasurement made, it is around 4.2A. Watch out for your metter current rating if you do this. Some batteries have a much lower internal resistance.

Category: electronics  | Tags: ,  | Leave a Comment
Samedi, septembre 27th, 2008 | Author: admin

Few usefull video snippets.

Grabbing from DV cam, autosplitting scenes :

dvgrab -- autosplit -timestamp –format=dv2 video

Deinterlacing :

ffmpeg -i in-dv.avi -deinterlace -vcodec huffyuv -pix_fmt yuv422p -target pal-dvd out.avi

Flv encoding :

ffmpeg -i input.avi -ar 22050 -ab 64 -aspect 4:3 -b 768k -pass 1 -f flv -s 640x480 -acodec mp3 output.flv
then again with -pass 2.

Another solution :
mencoder out.avi -o out.flv -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames

Category: sysadmin, video  | Tags: , , ,  | Leave a Comment
Samedi, septembre 27th, 2008 | Author: admin

This chip is a 8-bits port expander driven by SPI (or I2C for MCP23008 version).

Microchip MCP23S08 datasheet

Samedi, septembre 27th, 2008 | Author: admin

This chip is a LED driver : this means you can connect up to 64 LEDs (matrix configuration), and drive them from a microcontroller via 3 lines. The chip has segments and digits lines. The digits sinks current, while the segments source. It also has built-in PWM to control the LED brigthness. See :