The Software

A project log for Seismometer

An inexpensive Lacoste pendulum seismometer

Bud BennettBud Bennett 02/18/2019 at 13:180 Comments

I will make all of these programs available to download from the files section of this project or link to the webpage for download. I need to do a bit of cleanup and improve the documentation on my stuff first.


The capacitance to digital converter is not listed among the supported data converters for the popular seismic software packages -- Earthworm, et al. I had to write a custom program to extract the data from the cap2dig converter and massage it into a form that the standard seismic server programs would understand. Here's the flow:

The cap2dig converter uses I2C to interface to the Raspberry Pi computer. It runs in continuous mode -- sampling at 16.2Hz -- and interrupts the Pi on GPIO4 when each conversion is done. The data is collected by a Python program, The program creates two arrays: the resultArray for the realtime web server, and the seedArray for the seismic data stream server.

When the seedArray reaches 512 samples it is packed into an ascii file and fed to a program called ascii2mseed, which creates another file containing the miniseed data packet.

Lastly, a daemon program called ringserver watches the directory containing the miniseed files and adds the data packets to the data stream that it serves on port 18000. At this point the data stream is available to any computer running standard seismic software -- Earthworm, Quake, ObsPy, etc. 

I use ObsPy running on a desktop iMac to view the data in several formats. ObsPy is a collection of Python programs specific to seismic data manipulation.

The heart of this program is a function called getData(). It is called when the cap2dig converter signals that a sample is ready by a falling edge on GPIO4. There is also a Class called AD7745 which contains all of the methods to configure and extract data from the cap2dig converter. The AD7745 requires sequential reads of the I2C port that the standard python smbus libraries don't support very well, so I'm using the Quick2Wire libraries instead. The Quick2Wire stuff is very old, but still works fine in Python3.

A timestamp is added to the data and it is appended to both the resultArray and the seedArray.

When the length of the seedArray is 512 samples the data is packed into a simple text file with this format (explained in the next section), and ascii2mseed is called in the background:

TIMESERIES EI_AEGI__BHZ, 512 samples, 16.2 sps, 2019-02-18T13:47:12.273422, SLIST, INTEGER, Counts
  -1272258    -1272447    -1272290    -1272276    -1272222    -1272194  
  -1272313    -1272208    -1272297    -1272342    -1272303    -1272273  
  -1272373    -1272268    -1272423    -1272324    -1272484    -1272189 

The samples are integers representing the the conversion Counts of the cap2dig converter. The integers range from -2^23 to +2^23, or ±8,388,608.

 I added a webserver to allow the raw or filtered data to be viewed real-time. I was familiar with Bottle to create and manage a webpage so that is what is used. Bottle can be obtained here.

This is a screenshot of the webpage:

I'm using Flot to plot the data. The data sent to the webpage is decimated 8:1 to reduce loading times. Every 10 seconds or so the data is updated and scrolls. Usually, there is about 1 hour of data to view.


This program is available from IRIS. Simply download it and install on the Raspberry Pi using make. The ascii data file must include a header with the following information:

"TIMESERIES SourceName, # samples, # sps, Time, Format, Type, Units, Headers"

followed by the data in tabbed format. It is pretty well documented in the GitHub repository.

The miniseed file is uniquely named with a timestamp and deposited into a directory on external thumb drive attached to the Raspberry Pi.


This program runs as a daemon under systemd. It performs a seedlink streaming service. I believe it is part of the Earthworm seismic software package (which I could not get to work on my Raspberry Pi.) It is also available from IRIS. Simply download it and install on the Raspberry Pi using make. 

In order to run ringserver as a daemon at boot, there must be a ringserver.service file located in /lib/systemd/system/. This is what my ringserver.service looks like:

# This service installs a python script that communicates with the UPS hardware.
# It also provides logging to a file
# the ringserver.service is located in /lib/systemd/system/
# To test, use sudo systemctl start|stop|status ringserver
# To install during the boot process, use: sudo systemctl enable ringserver
# If this file gets changed, use: sudo systemctl daemon-reload
# If the Python script is changed, use : sudo systemctl restart ringserver
Description=Powerfail Service
ExecStart=/usr/local/bin/ringserver /home/pi/ringserver/ring.conf
# The number of times the service is restarted within a time period can be set
# If that condition is met, the RPi can be rebooted
# Only use these options with a working system!
# actions can be none|reboot|reboot-force|reboot-immidiate
# The following are defined the /etc/systemd/system.conf file and are
# global for all services
# They can also be set on a per process here:
# if they are not defined here, they fall back to the system.conf values

The ringserver is configured by a file called ring.conf. I did not make many changes to the ringserver configuration, but I did configure it to watch the directory containing the miniseed files and add them to the data stream. The ring.conf can be downloaded from the files section of this project. You will have to change some paths to get it working in your system.

I created a directory for the ring server: /home/pi/ringserver. In the directory you need to make another directory called "ring". I also put a symbolic link to the location of the miniseed files:

ln -s /media/pi/BPLUSTHUMB/mseed .

The ringserver program will add scan.state into /home/pi/ringserver, and use the /home/pi/ringserver/ring directory for its data files.

The mseed directory is located on a thumb drive. The thumb drive must be formatted to ext4, otherwise the number of files will eventually overload a FAT32 allocation table. To keep the number of files to a reasonable value the seismo2mseed program erases all files more than 2 days old.