Monday, December 20, 2010

YAPF - Yet Another Pricture Frame

with "viewer presents awareness" and geeky frame. 

Yup, yet another digital picture frame made from an old laptop. Added value: "viewer awareness intelligence". Say what? Ohh, nothing big. Simply a PIR (passive infrared sensor) to detect motion and turn on/off the back-light lamp. This prevents the lamp from burning out too quickly. To make things more interesting, a frame made out from discarded industrial printed circuit board. Perfect for the geek's house, ain't it?






Why ?


I have few of these long-obsolete, unwanted laptops in my garage and a desire to do something with them. They work...sort of. You can run Win95 on one, a Win3.1 on another and DOS on the oldest one. OK, some of them are too old. I have picked a ca.1997 Omnibook 800CT (Pentium MMX 166MHz/80MB RAM 800x600 10" TFT LCD). 


Now what?


Obviously this has been done for years. Short recipe here: 
  1. Get a CF card (>=128MB) and a laptop IDE-to-CF adapter (eBay)
  2. Using your USB card reader and your Linux Desktop (you have one, right?) install GRUB into it and a (preferably small) Linux distro.
  3. Install a picture viewer of choice and make it run at start.
  4. Copy pictures to a subdirectory.
  5. Remove the screen hinges and the skirts (front plates) from the laptop, then build a frame around it.
  6. Plug the CF & adapter in your laptop, reboot.
  7. Enjoy.

Add salt to taste.
Here are hints
CF card & adapter in IDE connector
  • Use GRUB  pre-2 version (I used 1.98). Newer may not work with old machines. There is plenty of help on-line.
  • I used TinyCore, a 10MB distro. On Omnibook 8xx series the Xvesa does not work so I had to install Xfbdev.
  • For picture viewer I used FEH, avaliable for TinyCore as add on package. The only downside of FEH is lack of transitions, but with weak CPU this may be actually be a benefit.
  • Add a script to start FEH after X started. The script that starts FEH goes into /home/tc/X.d/show.sh. It contains:
    • feh -rzFD60 --hide-pointer /mnt/hda1/Pictures &
    • as you see the pictures are in /mnt/hda1/Pictures (ie in the directory /Pictures in the top of the drive
    • the rest of options tell feh to do randomized slide show changing picture every 60s


Frame w/o laptop
Mechanical stuff

The frame is make of two identical PCBs one with elements the other blank. I have taken them from a pile of garbage. By size they are big. Old PC motherboards may be of use here. A dremel and angle grinder with cutting blade are your friends. All is held together by 6 stand-offs. The laptop slides in and is screwed into the front PCB.








PIR sensor aka "viewer presents awareness"


This was the most fun. It really had few parts: reading the PIR sensor, controlling the backlight, implementing the script to bind them all. 


To Port or not to Port


Laptop with PIR and PP connected
The CPU part is tackled under.
When this laptop was designed (ca.'95) there were no USB ports. But Parallel and Serial were in full swing. Both ports are easy to interface with and both have some lines that can be directly controlled (Serial has modem control likes, while Parallel is pretty much fully controllable). However, for the ease of software implementation I have chosen Parallel as it can be accessed from shell scripts through /dev/port. The down side of Serial is a harder control from scripts and its +/- 12V levels. So parallel it is.


However, my laptop (like many other) has and open-collector outputs that are internally pulled-up by 1kOhm resistors. Way too much for the Parallax PIR sensor I was planning to use (it ends up about 4mA drain). so I had to add a transistor "amplifier". Here is a good spill about the sensor and how to connect some load to its "Out" pin. The transistor output (collector) got connected to pint #15 of the port (which leads to bit #4 in STAT register).




Let there be...darkness


Modified inverter and PIR output amplifier.
All powered from +5V available on the inverter.
How to control backlight? There are more then a few ways. Normally, newer hardware would have ACPI which has backlight control. But my laptop has older APM which does not. So much for direct control. Another idea would be to decipher the keyboard and pretend a  "PWR" button press, which turns the display off (but let the CPU to continue). This proved hard to interface as the keyboard is connected through the thin "foil" connectors. So, in desperation I looked at the CCFL inverter and, the proverbial "bulb" went on in my brain. The inverter is build around LT1184CS chip, which has a "shutdown" pin. Bingo! Well, not quite. A little probing showed that the pin is shorted to +5V by some buried trace. So I got out my 6-pack of whoop-ass and lifted the pin. Added pull up 6kOhm resistor (probably not necessary as PP has pull-ups but I did not want the darkness when not in control). Then connected it to pin #14 (bit #1 in CONTROL register). 


Scribbling the scripts


I choose to implement the monitoring of the PIR in shell scrpt. There are 3 scripts: rdport, wrport and monitor. All placed in ~/.local/bin and invoked from .profile. Granted, I could simply hooked up the PIR to a timer such as NE555 and control the backlight directly. But writing script was more fun. As benefit, the scripts can log activity in my house (do not know why I'd need it though).


Again, few obstacles to be solved:
  1. how to read/write a port
    • access through '/dev/port'
    • must be root hence 'sudo'
    • use dd with seek/skip sudo dd bs=1 count=1 of=/dev/port seek=$1
    • convert a string '123' to actual byte :  echo -n $2 | awk '{printf("%c",$0)}'
    • convert byte to a sting: hexdump -e '/1 "%u"'
  2. how to interpret and generate binary values
    • motion=`dc $pir 8 xor 8 and p`

The script to read any ISA port 'rdport [addr]':
sudo dd bs=1 count=1 if=/dev/port skip=889 2>/dev/null | hexdump -e '/1 "%u"' 


The script to write any ISA port 'wrport [addr] [val]':

echo -n $2 | awk '{printf("%c",$0)}' | sudo dd bs=1 count=1 of=/dev/port seek=$1 2>/dev/null 
There is a small problem with this script as I cannot write 0. I think the busybox implementatino of awk's prints has problems printing 0 as this is a string terminator in C.


A script to monitor the PIR state and control the CCFL inverter "shutdown". This is the "brain". The addresses of PP CONTROL and STATUS registers are 889 and 890. The script only updates the 'shutdown' signal when its state actually changes.


The jest:
  • loop forever
    • check the sensor state
    • if motion detected update "last motion" time stamp
    • if "last motion" time stamp tool old (here 300 seconds) then turn off the backlight
    • otherwise turn on the backlight
#!/bin/sh
# monitor PIR sensor and control backlight


# handy function for time-stamping
now() { 
  echo -n `date +%s` 
}


# initialize start conditions
maxElapsed=300 # 300 SECONDS = 5 MIN
off=1
lastMotion=$(now)


# loop forever
while true; do


  # read and check PIR (bit #3 of ParPort hence mask is 2^3=8)
  pir=`rdport 889`
  motion=`dc $pir 8 xor 8 and p`
  if [ $motion -ne 0 ]; then
    lastMotion=$(now)
  fi
  # see if enough time elapsed since last registered motion
  elapsed=$(expr $(now) - $lastMotion)
  if [ $elapsed -gt $maxElapsed ]; then
    requestOff=1
  else
    requestOff=0
  fi


  #echo $pir $motion $lastMotion $elapsed $expired $off


  # if changes the state of backlight then apply it
  if [ $requestOff -ne $off ]; then
    off=$requestOff
    if [ $off == 1 ]; then
      echo -n 'OFF: ';date;
      wrport 890 2
    else
      echo -n 'ON : ';date;
      wrport 890 1
    fi
  fi


done



Todo


I'd like to have Forward/Backward buttons.
Have it WiFied to my picture archive (get a better laptop for this).

Make it serve beer.
Go on line and download some ...wait!



THE END

Monday, October 11, 2010

Kitesurfing: Replacing a strut bladder with U-Stick orange bladders

Here is a story of a bladder (replacement) on an inflatable kite.


Twice-Broken valve
Recently, I had a failure in my Flexifoil 9m Atom3 after I left it simmering in the sun for several hours (at Rio Vista, CA.) After having an "interesting" session with half-deflated kite I was faced with a repair. The heat caused delamination of the strut valve from the bladder. I have had local repair shop repair it. They glued the valve back but the repair looked terribly (with some part of bladder glued together, ripped apart and left hangin and bladder folds). I have reinstalled it anyway and tested it overnight. It held the air. I did not go out for several days (no, the kite was no longer on the sun).
Next time I have inflated it on the beach the kite quickly lost lots of air. I discovered that although the glue held, the valve become cracked and it had a serious leak. Apparently the repair damaged the valve base. The damage looked like it was heat induced. I bet it was overheated during the repair (the valve is usually completely unglued by "coocking" it). So much for "professional" repair.

Orange and original bladders.
So, a full bladder replacement was in order: U-Stick orange bladder and valve. The Airtime Kite people were awesome. They quickly advice me what I should use. The strut valves, both on main and strut bladder are called "option" as you can choose different stems. Flexifoil has a 11mm valves with straight stems. There is also a "replacement" option valve which does not have "options" as it comes only with straight stem. Also, Airtime has nice on-line bladder selection tools. My kite needed 50cm bladder. The valves fit the opening in the kite and did not need rings. Ordering and shipment was a snap, thanks Airtime!

I followed instructions attached to the bladder and valve. However, there were few small surprises.

The 50cm bladder is visibly much bigger then the original Flexifoil one. Too big is OK as the kite will restrict the expansion, too small would be bad (too much stretch). The original bladder was also 50cm (just much smaller). 


The material is more brittle sounding (it sounds more like a "shopping bag" while Flexifoil's is more like "sex-rubber", if you know what I mean.) Just observing the visual difference which has nothing to do with other physical properties like strength. I just said "oh well it must work fine."


REALLY be careful when cutting the hole in the bladder for the valve. The bladder is completely air tight when shipped so pulling it apart is hard. Never thought that vacuum can be so hard :-)
Bladder prepared for surgery


When sticking the valve there were more surprises.

The bottom of the valve protrudes from the base so it is perhaps better to use soft surface to glue on, like a towel.
Bottom of stem protrudes beyond the base
It is hard to align it with the hole before the valve sides will start catching the bladder and when they do, it is over; perhaps a helper could stretch the bladder flat when you align the valve and stick it, mine cough bit early and got slightly misaligned with the cutout.

The valve glued to the bladder.
The diameter of the opening in the end of strut is so small that I had to bend the base of the valve to fit it in. Then I had to push it in through with some force. Needed to get a bit medieval with it, but it worked. The rest of the way was traveled with a "string attached."

Size matters?

The bladder is so much longer than the original even though I followed the instructions and folded top and bottom inside to match original length. I have folded it more so it flashed with the pocket.

Too long?

The valve is a bit shallower then the original so the pipe between main the strut seems too short and bends the new valve. I wonder how it's going to work long term?.

Too short stem?

So far so good, the kite flies and makes his owner smile. The replacement was $35, a mare $15 more then the "professional" repair that failed.


References: