Finding the characteristic impedance of an antenna cable

May 24, 2020

I recently stumbled on a cool video that showed how to compute the impedance of an antenna cable. Unfortunately it’s almost five minutes long, so I thought I’d summarize:

  1. Measure the capacitance of the cable when it’s open (C) in farads (F).
  2. Short one end.
  3. Measure the inductance of the cable from the non-shorted end (L) in henrys (H).
  4. Impedance (Z) = √(L/C) in ohms (Ω).

It works for both coaxial cables and ladder line. Neat trick!


Fixing a busy CP210x serial device on Ubuntu

April 5, 2020

I had the opportunity to reorganize my local machines. As part of that, I wanted to plug my firewall’s serial port into USB serial and pop that into my server. I have a CP2104 serial device that I bought with my PC Engines apu2 which I use for a firewall.

The USB serial device worked fine when plugged into my Windows 8 laptop, but I want my server to be able to connect to my firewall even when the network is down. Because the apu2 is headless, it’s nice to have something that’s plugged into a monitor when I need to fix things.

I plugged the USB serial port in, and tried to connect to my firewall with minicom. I got this instead:

$ minicom 
minicom: cannot open /dev/ttyUSB0: Device or resource busy

So, time to look at who has /dev/ttyUSB0 open:

$ sudo lsof | grep ttyUSB0
gpsd 416 root 3u CHR 188,0 0t0 176 /dev/ttyUSB0

Ok, why is gpsd holding /dev/ttyUSB0 open? It’s true I have a GPS attached to my server, but that runs as /dev/ttyACM0 and has nothing to do with /dev/ttyUSB0. Hmm… time to search and find this in the gpsd FAQ: Why does GPSD open non-GPS USB devices?

That made me suspicious. See, gpsd is trying to be too friendly – and to do that, it opens a whole bunch of possibly GPS devices even if they’re not GPS devices! Could that be my problem?

$ lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 003: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 040: ID 1546:01a7 U-Blox AG 
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Hmm… let’s take a peek in /lib/udev/rules.d/60-gpsd.rules:

... blah blah blah...
# Cygnal Integrated Products, Inc. CP210x Composite Device (Used by Holux m241 and Wintec grays2 wbt-201) [linux module: cp210x]
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="gps%n", TAG+="systemd", ENV{SYSTEMD_WANTS}="gpsdctl@%k.service"
... more blah...

So in an effort to detect the Holux m241 and Wintec grays2 wbt-201, it’s matching the vendor and product ID of my CP2104 serial device as well! Luckily, I don’t have any of those GPS devices, so a quick snip:

# Cygnal Integrated Products, Inc. CP210x Composite Device (Used by Holux m241 and Wintec grays2 wbt-201) [linux module: cp210x]
# commented out because it interferes with Andrew's PC Engines 2104 USB serial cable
#ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="gps%n", TAG+="systemd", ENV{SYSTEMD_WANTS}="gpsdctl@%k.service"

was all it took. Now my USB serial device shows up as a serial device, and is not held open by a GPS daemon.

I have to disagree with the GPSD FAQ’s statement, “It’s not a problem we can solve with clever programming, the devices simply don’t yield enough information about themselves to avoid conflicts.” Err, no… clever programming would have the user run through an install procedure which involved plugging the device in, and detecting the device. Then they could update the udev rules so that only the device that a user owned was stolen by gpsd, and not all serial devices on the planet that happened to match a vendor/product ID that they knew about.


Translation of Evangeline Acadian Queen

December 3, 2016

Angèle Arsenault wrote this back in 1977, and I haven’t been able to find a translation that I really liked. So I had to do it myself. It’s from her album Libre (SPPS Disques, PS-19903) and was my first introduction to Acadia.

I’m going to talk to you of someone that you know
Yes but don’t deceive yourself, she did not come from the States
Even if a certain fellow who was called Longfellow
Popularized her two hundred years ago
She was called Évangéline, she was very very fine
She loved Gabriel on earth as if in heaven
They lived in Acadia, they were damned rich1
But one day the English were no longer satisfied
So they deported them, Gabriel disappeared
Discouraged2 Évangéline searched for him as long as she could
She searched for him in Acadia in Quebec in Ontario
Then in the United States in Florida in Idaho
Arriving in Louisiana with her cousin Diane
She said I have lost my time3
She was 75 years old4
Working a the hospital, she cared for the sick
Then she saw her Gabriel who was leaving for heaven
She jumped on his neck
And said thank you very much
At the hour that you’re interred I will be able to return
I’m going to invest in the companies of the future
So that the name of Évangéline will be bloody well known5

Évangéline Fried Clams
Évangéline Salon Bar
Évangéline Sexy Ladies Wear
Évangéline Comfortable Running Shoes
Évangéline Automobile Springs
Évangéline Regional High School
Évangéline Savings Mortgage and Loans
Évangéline The only French Newspaper in New Brunswick
Évangéline Acadian Queen

  1. This is “riches en maudit” in the original.
  2. This is “déconfortée”in the original.
  3. This proves that Angèle didn’t come from Clare, since she wrote “soixante et quinze” instead of “septante-cinq.”
  4. This is “A dit là j’perdrai pu mon temps.” It seems to indicate both past and future.
  5. This was the hardest to translate, “soit connu en câline.” Literally, “will be known in cuddly” but câline is a milder form of the sacre (expletive) câlisse or chalice.

Setting up Raspian Jessie on a Pi

March 15, 2016

There are a few changes to setting up Raspian Jessie on a Pi. Here’s what I do:

Burn the image

  1. Get the Raspbian image from the Raspberry Pi downloads page. I’ve been using Jessie Lite, since I don’t need the full package.
  2. Unzip it on a Linux box (mine saw the SD card as /dev/sdb, use your SD card device and don’t wipe your hard drive)
  3. Pop the card out of the Linux box and into the Pi

The command to write that I used:

sudo dd if=2015-01-31-raspbian.img of=/dev/sdb bs=4M

Configure the Pi

When the Pi boots into raspi-config, do the following:

  1. Expand Filesystem
  2. Change User Password
  3. Internationalisation Options / Change Locale, pick en_US UTF-8
  4. Internationalisation Options / Change timezones, pick yours
  5. Internationalisation Options / Change Keyboard Layout, pick US PC 104, accept defaults

Set up the network

I have my Pi configured with a static IP. The first time I boot I attach a network cable.

  1. Edit /etc/dhcpcd.conf (not /etc/network/interfaces) so the wired interface is static
  2. My /etc/resolv.conf was configured automatically by dhcp and was mostly right (missing domain and search, but I guess I can live with that)
  3. Now would be a good time to edit /etc/hostname as well
  4. Edit /etc/hosts to use the new hostname and hostname.domainname

(Thanks to https://pi-hole.net/faq/how-do-i-set-a-static-ip-address-in-raspbian-jessie-using-etcdhcpcd-conf/ for the revised instructions for a static IP.)

I added the following to the end of my /etc/dhcpcd.conf:

# Configure eth0 to be static
interface eth0
static ip_address=192.168.17.5
static routers=192.168.17.1
static domain_name_servers=192.168.17.1
static domain_name=mydomain.foo

Install an editor

I can do a few things like adding users while updates are happening. So:

sudo aptitude update
sudo aptitude install zile

Update the OS

This takes a while, but you can continue on while this is happening.

sudo apt-get install rpi-update
sudo aptitude dist-upgrade

Add my user

I don’t like to use the default user, so I add my own.

  1. sudo addgroup –gid 3009 myshare
  2. sudo adduser –uid 3000 myuser
  3. sudo usermod -a –groups adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio,myshare myuser
    log out, log in – make sure I can sudo with the new user
  4. prevent login as pi

To prevent the pi login, I do:

sudo vipw -s

and replace the password for pi with *.

Update everything else

Once the dist-upgrade has completed and it’s time to reboot:

sudo /sbin/shutdown -r now

Now you can log in again and upgrade the firmware:

sudo rpi-update
sudo /sbin/shutdown -r now

Get things I know I’ll need

I like to have an emacs clone:

zile ~/.bash_aliases
alias emacs='zile'

I also like tightvncserver on non-Lite images:

sudo aptitude install tightvncserver
tightvncserver
(set password)

Finally, make emacs the default editor by appending this to ~/.bashrc:

export EDITOR=/usr/bin/zile

Mounting a CIFS drive

I don’t like to do more writing than I have to, so:

sudo mkdir /etc/samba/credentials
sudo chmod 700 /etc/samba/credentials
sudo chown root.root /etc/samba/credentials
sudo mkdir /shared
sudo zile /etc/fstab
sudo zile /etc/samba/credentials/myserver

In /etc/fstab, I add:

//myserver/shared /shared cifs credentials=/etc/samba/credentials/myserver 0 0

While in /etc/fstab, I change the following to reduce wear on the SD card:

/dev/mmcblk0p1  /boot           vfat    noatime 0 0
/dev/mmcblk0p2  /               ext4    defaults,noatime 0 2

{Edit} I used to have ro,noatime on /boot but the Pi gets really unhappy when you try to upgrade the OS if /boot isn’t writable. So out it came.

In /etc/samba/credentials/myserver, I add:

username=myuser
password=mypass

That’s about it.