Thursday, August 25, 2016

Arduino LCD Button Shield

The Sparkfun LCD shield works very well.  It has five buttons wired to a single analogue input, which is a neat pin saver. 

However, the example code is much too complex to my liking.  Granted, it can handle multiple simultaneous button clicks, but who on earth will ever do that?  So I made something simpler:

#include <LiquidCrystal.h>

// LCD uses D4 to D9 and A0 for buttons

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

void setup()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("C'mon click it!");
}

void loop()
{
  unsigned char key;
  unsigned int sensorValue;
 
  sensorValue = analogRead(A0);
 
  if(sensorValue < 1000)
  {
     sensorValue = analogRead(A0);
    
     lcd.setCursor(0, 1);
     lcd.print("                ");
    
     lcd.setCursor(0, 1);
     lcd.print(sensorValue);

     if ((sensorValue > 600) && (sensorValue < 620))
     {
       lcd.print(" Select");
     }

     if ((sensorValue > 840) && (sensorValue < 870))
     {
       lcd.print(" Left");
     }

     if ((sensorValue > 920) && (sensorValue < 940))
     {
       lcd.print(" Up");
     }

     if ((sensorValue > 890) && (sensorValue < 910))
     {
       lcd.print(" Down");
     }

     if ((sensorValue > 800) && (sensorValue < 830))
     {
       lcd.print(" Right");
     }

  }
}


Have fun!

Herman

Minimalist Arduino GPS Parser

The Sparkfun Redboard and other toys can be a lot of fun indeed.  What I like about the Arduinos, is that the board support packages are very good and it is very easy to intersperse regular C with the simple Sketch code.

Here is a minimalist on the fly parser for NMEA GPS data positioning that I've been playing with.  It receives and analyzes one byte at a time, so there is no delay.  You have the data the very moment it is available:

// Minimal GPS Parser
// Herman Oosthuysen, 2016

#include <string.h>
#include <SoftwareSerial.h>

// GPS serial: 9600N81
// Example GPS data capture
//$GPGSA,A,3,11,31,27,14,,,,,,,,,2.09,1.85,0.96*08
//$GPRMC,155741.000,A,2413.4311,N,05541.2983,E,1.19,45.34,240816,,,A*5D
//$GPVTG,45.34,T,,M,1.19,N,2.21,K,A*03
//$GPGGA,155742.000,2413.4313,N,05541.2985,E,1,4,1.85,263.9,M,-29.9,M,,*77

//Time, Lat, North, Long, East, Fix:
//$GPGGA,155743.000,2413.4317,N,05541.2986,E,1,

//Heading true, heading magnetic, speed knots, speed kph
//$GPVTG,45.34,T,,M,1.19,N,2.21,K

const int rxpin=8;
//const int txpin=9;
const int txpin=255; // Rx only, frees up a pin
SoftwareSerial serial_gps(rxpin, txpin);

char ch = 0;
int cnt = 0;
int csv = 0;
int fix = 0;
int res = 1;
char dat[16];
char tim[16];
char lat[16];
char lng[16];

void setup()
{
  Serial.begin(9600);
  serial_gps.begin(9600);
}

void loop()
{
  if(serial_gps.available())
  {
    ch=serial_gps.read();
    //Serial.print(ch);

    // simple parser, start with $
    if(ch == '$')
    {
      cnt = 0;
      csv = 0;
      fix = 0;
    }
    else
    {
      dat[cnt++] = ch;
     
      if(ch == ',')
      {
        dat[--cnt] = 0;
        cnt = 0;
        csv++;

        if(csv == 1)
        {
          res = strcmp(dat,"GPGGA");
          if(res == 0)
            fix = 1;
        }

        // Assume N, E
        if(fix == 1)
        {
          if(csv == 2)
            strcpy(tim, dat);
          else if(csv == 3)
            strcpy(lat, dat);
          else if(csv == 5)
            strcpy(lng, dat);
          else if(csv == 6)
          {
            Serial.print("Tim: ");
            Serial.println(tim);
            Serial.print("Lat: ");
            Serial.println(lat);
            Serial.print("Lon: ");
            Serial.println(lng);
            fix = 0;
          }
        }
      }
    }
  }
}


The result is:
Tim: 154417.000
Lat: 2413.4364
Lon: 05541.2907


Cool, now you all know exactly where I live.

In days gone by, there were phone directories, now, there is GPS.

There are Arduino GPS libraries available, but they are too complex for my liking.  For a toy, one can make some assumptions to simplify things, which saves processing cycles and memory.  I don't see the need to verify the checksum, or check whether the position is north and east - I'm not going to drive my toy car to the other side of the globe.

The Arduino software and Redboard works pretty good on my Mac, but if I unplug it from the USB port, then I have to reboot the Mac to get the USB serial port to work again when I plug it back in.  There should be a way to force the Mac to reload the driver, but I haven't gotten round to diving into the OSX weeds to figure it out yet.

Have fun!

Herman

Wednesday, August 10, 2016

Audio VU Meter

I have a bunch of Magic Eye tubes and was wondering what to do with them.  An audio VU meter with a microphone pickup could make a nice magical flickering display as I originally described here: An Angel Dancing On a Pin Head.


The example Rusky circuit works, but it needs much more gain to work with a microphone and it needs a power supply of sorts.  So, I dusted the old circuit off, hooked up a little triode as an amplifier to drive the display tube and my prototype works nicely.   Moving the resultant rat's nest from the breadboard into a proper display case is another matter though.

For a little toy like this, a pair of huge transformers will increase the cost and their bulk will detract from the whole idea, so I made a simple direct mains powered supply - shocking, eh...

A magic eye tube is a tiny cathode ray tube as in old TV sets and requires a very high operating voltage.  So I used a voltage doubler on the 220 V mains.  That ensures that the electrons have sufficient kinetic energy to penetrate surface pollutants and stimulate the ancient zinc oxide fluorescent display properly.  High voltage capacitors are costly and one 630V electrolytic could cost as much as a transformer.  Put two identical(!) 315 V caps in series - much cheaper.

The miniature triode needs a much lower voltage, so I made a simple half wave rectifier for that.  So far - fairly standard.  The triode output is envelope detected to create a negative voltage to drive the display tube gate - any small signal diode will work - a 1N4148 is cheap.  You can put a trimmer on the display tube cathode to adjust the DC bias and together with the input volume control, get the shadow to flicker properly.

The heaters require about 300 mA at 6.3 V.  So for that, I made a simple triac light dimmer circuit (test it with a light bulb and set it to minimum) with the two heaters in series (I used a quadrac - one less part).  To get the right current, install a 1 Ohm resistor in series with the tubes, measure the RMS voltage over it and tweak the trimmer - then maybe put a spot of glue/wax on it.

The fuse and chokes provide some protection and spike/triac noise filtering.   You can wind your own chokes - a few turns on a ferrite toroid or ferrite cable clamp (easier to wind, since you can wind it while it is open) is all that's needed.

As with any thermionic valve circuit, this one is dangerously 'hot' and noisy.  So when this toy is running, don't poke your fingers in the works - you will be sorry...

La voila!

Herman

Saturday, August 6, 2016

FM Crystal Varicap Tuner

I like to keep things simple, but I also like to make things that are a little unusual.

To go with my Valve Amplifier, I wanted to make a simple radio tuner.  Where I live, there is a powerful FM transmitter almost in my back yard.  It is very strong and overpowers all other transmissions, so the only FM station that I can receive is Abu Dhabi Classic.  That gets rather trying after a while, but why not turn it into an advantage?

Since the radio transmission is very strong, it can be detected with a simple tuned circuit and a non-linear element - there is no need for a complex discriminator or PLL.

For an intuitive explanation of how it is possible to demodulate FM with an AM detector: If you tune an AM receiver adjacent to an FM signal, then when the FM signal is closer, the AM signal will be stronger and when it dithers further away, the AM signal will be weaker - that way, a simple envelope detector can detect a FM signal.  Some call this a slope detector.

Crystal sets are normally associated with shortwave radio, which require enormous coils, air capacitors and high impedance headphones.  In the 100 MHz FM band (88 to 108MHz), everything is much smaller, but a high impedance headphone may still be a problem to find.  Piezo electric speakers are commonly used in laptop computers and can be obtained from Digikey or Mouser, so you can use one of those, but do put a resistor in parallel, since it won't pass DC.  Mike's actually has everything you may need.

Variable capacitors are somewhat hard to get and air capacitors are still manufactured by at least one US company, but are expensive.  Using varicap diodes to tune a circuit is also expensive, but LEDs and zeners are cheap and make fairly decent DIY varicaps.

This circuit looks like a FM crystal radio with a 9V battery.

The battery is needed to charge the tuning capacitor, which is made from two red LEDs, used as varicap diodes.  Red LEDS provide about 10 to 30 pF capacitance with  9V bias (You have to take a handful of LEDS and try them - some patience required).  Other options are large rectifier or zener diodes, but a couple of 5mm LEDS look nicer.  Of course a real varactor will be better and more linear, but who has a varactor in his junk box?



If you want something a bit more predictable than a LED, then you could use 1N4001 rectifier diodes. The 1N4001..7 all exhibit the same curve, as shown in the data sheet here on page 2.  However, you would have to double them up to get sufficient capacitance.   To make a 100MHz RF circuit work, it is important to keep all wires short (just a few millimeters) and the parts very close together, otherwise stray capacitance and inductance will detune it and it won't work as intended.

The result is a FM crystal radio that can be tuned with a potentiometer.

In my eventual circuit, I used two LEDs and tune the tank with a 22k potentiometer.  Some more playing with a coil design tool settled on 5 turns, 10 mm diameter and 12 mm length for 150 nH and a Q of 600.  That improved the selectivity much.  I wind coils around a drill bit to get a precise diameter and the biggest bit I got is 10 mm, so...

BTW, a 1/4 wave antenna needs to be 75 cm in length and a 1/20 wave antenna needs to be 15 cm. On a receiver, a bad antenna affects both the signal and the noise, so the S/N ratio stays the same, but a longer antenna will certainly catch more signal.  If you solder the antenna on the top end of the coil, then it will load the coil and you won't be able to tune to the high end of the band, so solder it to the first turn from the bottom.

So, how weird is that?

Herman.

Friday, July 29, 2016

Twin Otter

If you ever visit British Columbia in Canada, then do yourself a favour and take a sight seeing trip with Harbour Air.

They operate a large fleet of old and new De Havilland seaplanes flying out of lakes and harbours all over BC - providing a delightful experience.

In this older plane, an original De Havilland, circa 1970, the upgraded turbine engine has about 50% more power, which provides seemingly effortless take-off and landings, while the cockpit is a museum piece with some essential updates.  Note the fuel flow indicator hose at the top of the panel - the ultimate in low tech!

The planes are simple and reliable aluminium sheet metal constructions, supported by Viking Air, which is continuing the De Havilland mission.  Since 2010, Viking Air builds completely new Twin Otters.

Yours truly, in the co-pilot seat.
A view of Victoria, with the snowy peaks at Vancouver in the distance.

You can literally fly from downtown Victoria, to downtown Vancouver, have a meeting and fly back again, in less time than a one way trip with BC Ferries and it won't cost you much more either.

Have fun!

Herman




Tuesday, July 12, 2016

Why Globalization Doesn't Work

One doesn't need to be a wizard to realize that when you take a large amount of wealth and divide it amongst four billion people, nobody has anything.

Globalization is a form of Communism.  It didn't work in the USSR or China and it won't work for the whole world.

Recently, the Limeys voted to exit the EU - which confirms that although common sense isn't common, it usually prevails in the end.

. -.-. .-. .- ... . --..   .-.. .   .. -. ..-. .- -- .

Herman


Tuesday, June 14, 2016

Slackware Linux

One of the first Linux distributions I ever tried was Slackware, some time before the dinosaurs, circa 1995 - it was quite an adventure, since in those days, nothing worked the first time.  Yesterday, I gave the latest Slack a spin and it felt like donning an old frumpy jersey - for that comfy, warm, lived in feeling and nowadays, everything 'Just Works', TM.


What hooked me, was that the ethernet port is named eth0, so all my old scripts work.  The boot loader is LILO.  The boot code is in the MBR.  The initialization system is in /etc/rc.d and rc.local works right off the bat.  SELinux is nowhere in sight.  The log files are plain text and I can watch my system with 'tail -f /var/log/messages'.  Systemd?  What is systemd??? Never heard of it, sorry...

In short, everything works totally Olde Skool, the way the Fates intended and Slack is Fast.

Slackware is the ultimate Long Term Support Linux, since for the better part of the past quarter century, it has been the same.

I haven't realized how much the other bloated and slow Linux systems were annoying me all the time and I think that from now, on, I'll be a Slacker again.

If you have no idea what you are doing, then maybe Slack isn't for you yet.  Rather go and experiment with PCLinuxOS, Fedora or Suse Linux for a bit, then come back later.  Slack doesn't have training wheels.

Where To Get Slackware

The Slackware installer is not unfriendly.  It simply assumes that you know what you are doing and basically just gets on with it.  Installing Slack takes only a few minutes (or a few weeks/months/years, if you are new).

The first problem is downloading an ISO file to install:
http://bear.alienbase.nl/mirrors/slackware/slackware-current-iso/slackware-current-install-dvd.iso

See the mirror information page here: http://mirrors.slackware.com/

Virtualbox

I then made a Virtualbox VM with name Slackware and OS type Linux 2.6 / 3.x (64 bit) with 1 GB RAM and VDI disk size 20 GB.

Under Storage, Controller: IDE CDROM, I selected the downloaded ISO file and started her up.

Once booted up and logged in as root, you will get a nice, friendly, self explanatory prompt:
#

An interesting observation is that Slackware is much faster than other Linux versions.  Slack with KDE runs fine in a virtual machine, while with most any other distro, one should stick to XFCE to get non-frustrating speed in a VM.  Pat's keep it simple and don't fix it if it ain't broke principles, really pay a dividend.

Partitioning the Disk

Slackware uses LILO which writes to the MBR, so you need to configure the disk as DOS with MBR and then create at least two partitions for swap (type 82) and linux system (type 83) and set the bootable flag on it, just like in the good old, bad old days.

So run fdisk /dev/sda, type o to create a MBR DOS partition, type n to make a new partition for +18 GB and again, for 2 GB, type t to change the 2 GB partition to 82 (Linux Swap), type a to make the 2nd partition bootable and type w to write it to disk.  Easy as borscht!

Deviate from the above, and LILO won't install.  You may be able to get it going in Expert mode, but good luck with that.

Setup

Now run setup and accept all the defaults, the way Pat intended, so that you have a full system with compiler and source code, about 9 GB.  Eventually, set the hostname and domainnameThe setup program is so simple, that there isn't any point in trying to describe it.

Reboot.

Log in as root and create a user account:
# useradd -m username
# chpasswd username

Log out and log in as the new user, then run startx to get your graphical desktop. 



I chose XFCE, but KDE works fine in a VM too - you can change with xwmconfig.  It will be a bit sluggish until you install Guest Additions below.

Guest Additions

Select Mount Guest Additions CD Image from the Virtualbox Devices menu, open it with a file manager and note the path. Open a terminal, su - to root, cd to /run/media/username/VBOX... and run the VboxLinuxAdditions.run file.

The system will build itself and install the faster Virtualbox aware mouse and video handlers.

Log out and log back in.


That is all there is to it.  You are now an official Slacker.

A Few Slack Links

Slackware is community driven like no other Linux distribution.  Patrick Volkerding manages the essential system.  Others provide the niceties.  You don't need to be a genius to use Slackware, being a subgenius is sufficient...

The default system works and does most anything, but after a few days, you may start to look around for a missing tool or two.  Slackbuilds is the answer and sbopkg is the aspirin for the resultant head-ache.

Package build scripts:

Slackware Forum:

The forum is hilarious.  There can be multiple years between questions and answers, since Slackware changes so slowly.

Documentation:

Everything about Slack in a few brief chapters:
http://slackbook.org/beta/

. -.-. .-. .- ... . --..  .-.. .  .. -. ..-. .- -- .

Herman