A Better Gas Pycnometer

Three years ago I built my first gas pycnometer to measure the volume of coffee beans using changes in air pressure. Since then, I’ve built many more of these, each trying to solve some issue I discovered in the previous design. These improvements include:

  • Improved pressure sensor accuracy
  • Improved volume accuracy
  • Reduced leakage
  • Rigidity of chambers and plumbing
  • Automation

Rather than walk through each iteration of the design, I think it will be better to look at the gas pycnometer I’m using today, and talk about how each of these improvements is reflected in the new design.

As usual, 3D files, ESP32 firmware, and client software have been uploaded to GitHub. Please let me know if anything is missing.

Overview

In the previous post, I mentioned that there are two main types of gas pycnometer:

  • A gas expansion pycnometer uses two chambers, with gas expanding from one chamber into the other.
  • A variable volume pycnometer uses a single chamber whose volume can be varied using a mechanical piston.

The original design was a variable volume pycnometer. I ran into a couple of specific issues with this style of pycnometer:

  • First, it was difficult to control the change in volume and to prevent leakage around the piston.
  • Second, having the sample in the syringe meant that the syringe walls were constantly getting dirty, which made the piston stick (affecting the accuracy of volume changes) and leak.

The use of a gas expansion pycnometer helps solve both these problems. A gas expansion pycnometer arranges things a little differently:

In this style of pycnometer, the sample is placed in one of the chambers and the other chamber is left empty. A positive pressure, often of helium gas, is applied to one of the chambers. The pressure is measured, a valve between the two chambers is opened, and then pressure is measured again. Based on the resulting change in pressure, it is possible to determine the volume of the sample.

The new gas pycnometer uses a method very similar to this, except that a vacuum is used instead of a positive pressure. The use of vacuum makes it easier to avoid leakage, since components containing vacuum tend to pull themselves together, tightening the interfaces, whereas components containing positive pressure tend to push themselves apart, creating leaks.

Hardware

The new gas pycnometer uses a slightly different layout than the one shown in the diagram above. The reason for this is that I wanted to minimize the number of valves connected to each chamber, in order to reduce the potential for leakage. Here’s the diagram for my design:

The three solenoid valves and vacuum pump are controlled by four MOSFET drivers, which are connected to an ESP32 development board.

The pycnometer uses two Honeywell HSCDANN015PA2A3 pressure sensors. These have a full scale output (FSS) of 15 PSI (103.42 kPa), an output resolution of about 0.03% FSS, and an accuracy of about 0.25% FSS. These are mounted inside each chamber, with the short barbed port cut off to maximize thermal contact with the air inside the chamber.

The reference and sample chambers are 4 oz mason jars. A 3D printed support makes the lid more rigid and provides a 1/8″ NPT thread to connect to the rest of the system. The mason jars have a couple of really nice properties.

First, the “gasket” inside the lid of a mason jar is quite thin, and relatively rigid at room temperature. Looking at the deviation plot below, if there is any “creep” over time due to compression of this gasket, it is quite small.

Second, the closing mechanism of a mason jar keeps the two mating surfaces stationary relative to each other, with a separate screw mechanism pulling the two together. This gives a consistent closing force and no stick-slip that can make a typical screw lid close at a different position each time.

Where consistent volume is important, the new gas pycnometer uses 1/8″ NPT brass fittings for plumbing.

Software

The ESP32 development board controls the solenoid valves and vacuum pump. A single measurement cycle consists of the following steps:

  • With the pump off, open all valves for 5 seconds
  • Close valves 2 and 3, and turn the pump on for 10 seconds
  • Close all valves and turn the pump off, then hold for 40 seconds
  • Open valve 2, then hold for 40 seconds
  • Open all valves

A set of 3 measurements is initiated by pushing a button on the gas pycnometer. A small OLED screen indicates the progress of these measurements.

At the same time, the ESP32 development board streams pressure and temperature measurements from both sensors over a TCP socket at a rate of 10 samples per second. Client software on a laptop collects this data and looks for the sudden change in pressure that signals the opening of the valve connecting the two chambers. When this happens, the software records the collected data in a 30 second window on either side of the valve opening. The collected data looks like this:

A script fits separate lines to the segments before and after the valve opening, and uses these to estimate the instantaneous change in pressure when the valve is opened. Collecting the raw trial data like this means we can improve analysis methods later on, and even come up with new ones. For example, I think it may be be possible to use the slope after the valve is opened to quantify CO2 off-gassing.

Volume calculation

To calculate the volume of a sample, we start with the ideal gas law:

    \[PV = nRT\]

Here, P is the pressure of the gas, V is its volume, T is its temperature, n is the number of molecules of gas, and R is the ideal gas constant. Before the valve is opened, we know that the two separate chambers must obey the ideal gas law:

    \[P_r V_{r,0} = n_r R T,\,\,\,\,P_s V_s = n_s R T\]

After the valve is opened, we know the combined volume must obey the ideal gas law:

    \[P_f (V_{r,0} + V_s) = (n_r + n_s) R T\]

This gives us:

    \[\begin{gathered}P_r V_{r,0} + P_s V_s = P_f (V_{r,0} + V_s) \\\Rightarrow (P_s - P_f) V_s = (P_f - P_r) V_{r,0} \\\Rightarrow \frac{V_s}{V_{r,0}} = \frac{P_f - P_r}{P_s - P_f}\end{gathered}\]

Here, V_s/V_{r,0} is the ratio of the gas volume in the sample chamber to the gas volume in the empty reference chamber. Note that this value depends only on two differences in pressure: P_f - P_r and P_s - P_f. Each of these can be measured using a single one of our sensors, which means the measurement doesn’t require absolute accuracy—only relative accuracy across the 60 second measurement window.

We can then calculate the volume of the sample as follows:

    \[V_m = V_{s,0} - \frac{V_s}{V_{r,0}} V_{r,0}\]

Here, V_{s,0} is the volume of the empty sample chamber and V_{r,0} is the volume of the empty reference chamber. We don’t know either of these measurements, but we can determine their value by measuring the volume ratio of the empty sample chamber and of the sample chamber containing a sample with known volume. The best fit line to these calibration points gives us the values of V_{s,0} and V_{r,0}.

For calibration, I use the empty sample chamber and a set of 75 3/8″ steel balls with a volume of 34.05 ml, measured using water displacement. Calibration gives:

    \[\begin{aligned}V_{s,0} = 129.3\,\text{ml} \\V_{r,0} = 129.7\,\text{ml}\end{aligned}\]

Automation

I had initially built a non-automated version of the gas expansion pycnometer:

The primary limitation of the non-automated design is that it requires the user’s sustained attention for the full duration of the measurement, leaving little opportunity to multitask. With the automated version, a single button press starts the measurement, and then the user’s attention can be turned elsewhere for a couple of minutes.

Error Analysis

Stability of calibration measurements

Over the course of six months, we see about ±0.50% variation in the volume ratio measurement (relative to the reference chamber) for both the empty chamber and the reference balls:

Some of this variation seems to be correlated with seasonal changes like ambient temperature. It’s unlikely this results from changes in the volume of the mason jars or the steel reference balls. The volumetric coefficients of expansion for these two materials at 20 °C are:

  • Glass: about 26 × 10−6 K−1
  • Steel: about 36 × 10−6 K−1

This means a change of even 10 °C would cause only 3 ppm change in the volume of glass and 4 ppm in steel—much smaller than the change we’re seeing here. However, it may be that the pressure sensor is not compensating completely for changes in temperature.

Roughly ±0.25% of the variation seen above appears to be random. This could come from random variation in the orientation of the glass jar containing the sample when it’s screwed into place. With a diameter of 60 mm, a change of ±0.1 mm in the lid position would give the observed ±0.25% change in volume ratio. This may be reduced by marking the lid and glass jar to ensure they are aligned consistently.

Stability of repeated measurements

Each push of the button on the gas pycnometer initiates a set of 3 identical trials as described above. Ideally, these should give the same result. The plot below shows the distribution of differences between each repetition and the mean value of all three.

The variation between the 3 trials is about ±0.1%. This is the “best case scenario” with the current hardware—taking repeated measurements with no change to the equipment configuration. Together with the variation in calibration measurements, this could suggest the following approximate contributions to uncertainty in volume ratio measurements:

  • ±0.1% due to limitations in the pressure sensor itself
  • ±0.25% due to limitations in the repeatability of system volume
  • ±0.25% due to changes in the environment, e.g., temperature

Conclusion

The accuracy of the new gas pycnometer is quite good, but the variation in calibration measurements makes me think there is room for improvement. Others have achieved much better repeatability with similar designs. For example, Sereno et al. were able to achieve 0.05% accuracy in volume measurements of a non-porous metallic cylinder, which may be indicative of what could be achieved with our calibration sample.

However, even with its current accuracy, the new gas pycnometer has allowed me to make measurements of whole bean volume and ground particle volume for most of the espressos I’ve made in the past several months. In upcoming posts, we’ll look at some of the results coming out of this data.

Leave a comment

Your email address will not be published. Required fields are marked *