June 2016 Archives

Mon Jun 20 15:30:29 PDT 2016

Joule Thief in Obligatory Tic Tac Box with Flickering LEDs

The 'Big Clive' Joule Thief runs to low voltages - as is well known - so if you want to extract energy from an old AA battery and have something possibly useful with that energy happen - a Joule Thief is a perfect vehicle to that end.

There is lots of experimentation documented on the web with different approaches and circuit variations. Some circuits yield improved efficiency and others provide enhancements like current or voltage control.

Here is a Joule Thief variant I put together at the weekend, as one does. It uses two flickering light emitting diodes (LEDs) taken from Dollar Store 'tea light' plastic candles (2 for one dollar). These Dollar Store candles are in themselves wonderful devices. They use 3 volt 2032 lithium cells - so perhaps their only limitation is that they run for a decidedly finite 5 days (according to the packet). The Joule Thief circuit allows you to use AA batteries that are no longer able to energize modern electronic equipement - the inductor based Joule Thief circuit extracts energy from the cell all the way down to about 0.4 volts (and lower if you are prepared to seek out special transistors).

 
Flickering LED Joule Thief Circuit
(Flickering LED Joule Thief Circuit)

The circuit used is shown in the image near this text (click on the image for a larger view). This is an extension of the Joule Thief circuit, adjusted to provide a specific output voltage. In the original Talking Electronics version (from here), the target voltage was 5 volts. The place of the solar cell in the original circuit has been taken by a 1.5 (in principle) AA battery. For the flickering LEDs, a voltage of about 3 volts was required, so I changed the resistor network of the original circut a little so that the control of the oscillating transistor cuts in at 3 volts. This means that the output is a steady 3 volts. I also added a series resistor for the LEDs - I did this to mimic the behavior of the original flickering LEDs in the Dollar Store tea lights - super bright is not particularly candle like.

As a finishing touch, American style Tic Tac boxes are the perfect enclosure for a small circuit - providing an aesthetically satisfying blend of transparency, amateurishness, and thriftiness. Once installed in the Tic Tac box the flickering LEDs can be conveniently covered with the plastic tube fake flame cover of the original lights, yielding a quasi-nixie tube flickering display - both fetching and enchanting.

The flickering LEDs contain a chip which handles the random fluctuations, as discussed here. So although this is a two transistor Joule Thief, it contains two substantial integrated circuits as well.

From a chemical perspective, what happens in an alkaline battery is that zinc is oxidized to form zinc oxide, and manganense in the form of MnO2 is reduced. (The name 'alkaline' refers to the fact that their are hydroxide ions added to the water in the battery in the form of potassium hydroxide). The basic chemical reaction of an alkaline battery is:

Zn(s) + 2MnO2(s) = ZnO(s) + Mn2O3(s)

This reaction liberates a fair amount of energy as the zinc is effectively burned, and that energy is released in the form of electrons flowing between the zinc and the MnO2. That is the energy that powers the Joule Thief and flickers the LEDs.

As an alkaline battery ages, its internal resistance increases, reducing the voltage that is available to drive electronic devices. The Joule Thief, because it boosts voltage using a transformer, is able to keep going with lower voltages than many pieces of equipment. Hence the Joule Thief is the perfect device for squeezing the last few drops of zinc oxidation from old batteries prior to handing them over to the recycler.

The Joule Thief on the video above has been running for about 24 hours. I may exert myself and measure how long it takes to run down sufficiently to be unable to light the LEDs - I am expecting several weeks of run time. I will report back on my observations.


Posted by ZFS | Permanent link | File under: chemistry, electronics

Wed Jun 15 19:27:39 PDT 2016

Making a Book from HTML Pages

I spent a little time recently in figuring out how to compile various pages into a pdf book. The key to doing this, I found, is to use 'htmldoc' - which can be downloaded for various platforms easily.

Here is a summary of the scripts that I used.

make_pdf.sh controls the overall processing, it uses a list of files stored in 'chapters.txt' to determine the files to process.

#!/bin/sh

rm -f missing_files
rm -f image_files 

i=0
while read CHAPTER
do
  i=`expr $i + 1`
  TMP=`echo $i | awk '{printf "tmp%04d.html", $1}'`
  echo $TMP 
  ./txttohtml.sh $CHAPTER | sed -f greek.sed > $TMP
  if [ $i -eq "500" ]
  then
    break
  fi
done < chapters.txt

htmldoc --book --linkstyle plain --toctitle "The Molecular Universe"  -f output.pdf --no-title --headfootfont times --headfootsize 10 --charset iso-8859-7 --embedfonts --size letter tmp*.html --titlefile title.html

./make_index.sh output.pdf 12

# make a report on the current status to append to the book
WORDS=`wc output.txt | awk '{print $2}'`
MISSING=`wc missing_files | awk '{print $1}'`
IMAGES=`wc image_files | awk '{print $1}'`
echo "<pre>" > status.html
echo "PDF file created:" >> status.html
date >> status.html
echo "" >> status.html
echo "Current word total: " $WORDS >> status.html
echo "" >> status.html
echo "Number of image files that should be enlarged: " $MISSING >> status.html
echo "" >> status.html
echo "Missing file names follow: " >> status.html
cat missing_files >> status.html
echo "" >> status.html
echo "Current image file count: " $IMAGES >> status.html
echo "All image file names follow: " >> status.html
cat image_files >> status.html
echo "</pre>" >> status.html

htmldoc --webpage -f status.pdf --no-title --size letter status.html

pdftk A=output.pdf B=output.index.pdf C=status.pdf output output.pdf

rm -f output.pdf output.txt output.index.pdf output.data.txt status.html status.pdf

if [ -f missing_files ]
then
  echo "THERE ARE " `wc missing_files | awk '{print $1}'` " MISSING FILES"
  cat missing_files
fi

txttohtml.sh is a very crude script that converts the raw nanoblogger txt file into a crude html file which can be used as the input to the htmldoc processor.

#!/bin/sh

awk '{
  if(match($0,"TITLE:")){
    title=substr($0,7)
    print "<h1> " title " </h1>"
  }
  if(match($0,"<blockquote>")){
    print "<table border=\"1\" cellpadding=\"10\"><tr><td>"
    getline
    sub("Note:","<b>Note:</b>");
    print $0
    next
  }
  if(match($0,"</blockquote>")){
    print "</td></tr></table>"
    next
  }
  if(match($0,"BODY:")){
    intext=1
    next
  }
  if(!intext)next
  if(match($0,"END-----")){
    intext=0
    exit
  }
  if(match($0,"<table class=\"image")){
    imagetable=1 
  }
  if(match($0,"\"left\"") && imagetable){
    sub("\"left\"","\"center\"");
  }
  if(match($0,"\"right\"") && imagetable){
    sub("\"right\"","\"center\"");
  }
  if(match($0,"<img src=")){
    record=$0
    sub("^.*<img src=","",record);
    sub(" .*$","",record);
    sub("^.*/","",record);
    sub("\"","",record);
    sub("_scale","",record);
    largefile=record
    largefile="../../../images/" largefile
    located=0
    # look for file with original extension
    line=""
    getline line < largefile
    close largefile
    if(length(line)>0){
      largefile="\""largefile"\""
      sub("\".*\"",largefile)
      located=1
    }
    # look for file with .png extension
    line=""
    sub(".gif",".png",largefile)
    getline line < largefile
    close largefile
    if(length(line)>0){
      largefile="\""largefile"\""
      sub("\".*\"",largefile)
      located=1
    }
    if(!located){
      print "COULD NOT LOCATE " record > "/dev/tty"
      print record >> "missing_files"
    }
    print largefile >> "image_files"
  }
  if(match($0,"</table") && imagetable){
    imagetable=0
    print $0
    print "<table width=\"100%\" summary=\"\"><tr><td> </td></tr></table>"
    next
  }
  print $0
}' $1

make_index.sh comes from pdftk and uses two tools from the pdftk site to create a crude book-like index for the the book. I modified the make_index.sh script a little - so I am including it here.

#!/bin/sh
# make_index.sh, version 1.0
# usage: make_index.sh <PDF filename> <page window>
# requires: pdftk, kw_catcher, page_refs,
#           pdftotext, enscript, ps2pdf
#
# by Ross Presser, Imtek.com
# adapted by Sid Steward
# http://www.pdfhacks.com/kw_index/

# modified somewhat from the original distributed version to correct
# problems encountered in initial testing

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
LANG=C

fname=`basename $1 .pdf`
pdftk ${fname}.pdf dump_data output ${fname}.data.txt && \
sed 's/LowercaseRomanNumerals/DecimalArabicNumerals/' ${fname}.data.txt > j && \
mv j ${fname}.data.txt && \
pdftotext ${fname}.pdf ${fname}.txt && \
  page_refs ${fname}.txt index-terms.dat ${fname}.data.txt \
| sed 's/PageLabelNumStyle://g' \
| enscript --columns 2 --font 'Times-Roman@10' \
  --header '|Index' --header-font 'ArialBold@20' \
  --margins 54:54:36:54 --word-wrap --output - \
| ps2pdf - ${fname}.index.pdf


Posted by ZFS | Permanent link | File under: bash, blogging

Sat Jun 4 21:31:49 PDT 2016

Fentanyl: Molecule that Actually Killed Prince

The official autopsy report has revealed that fentanyl killed Prince. (Originally it was thought that oxycodone was the culprit).

The structure of a fentanyl molecule is shown above. Like oxycodone, fentanyl is an opioid drug, and like oxycodone it operates on the receptors that transmit pain.

Although fentanyl is medically employed for pain relief it delivers a 'high' to people who take the drug.

Fentanyl is a flexible drug molecule (unlike oxycodone). It has more than five torsions or dihedral angles by which its conformation can be altered.

Hence, in some respects it resembles the peptide endorphins that are thought to be the natural equivalents of opioids.

Despite its flexibility, fentanyl is a powerful drug. It is approximately 100 times more active than morphine, for example. Given its activity, fentanyl is a dangerous drug - overdoses are unfortunately common because a small quantity of fentanyl can cause substantial respiratory depression and death.


Posted by ZFS | Permanent link | File under: chemistry