💣 In this week's development log, we introduce how we are controlling the stirring in the Pioreactor. We recently got the final piece working, and spent this week tying it all together.
The role of stirring in the Pioreactor is important for a few reasons: i) it allows for modest gas exchange between the media and the air, ii) more importantly: it creates a homogenous environment for microbes and nutrients alike. This last point also means that our optical signals won't vary spatially - something that would make the whole system much more complicated.
Stirring in the Pioreactor is accomplished by having a magnetic stir bar at the bottom of the vial. A rotating magnetic field below the stir bars causes it to spin. The rotating magnetic field is caused by two magnets rotating on a motor at the base of the Pioreactor. See Figure 1.
The speed of the rotating motor is controlled by the amount of voltage we apply to it. This is accomplished using a PWM signal of a 5V signal. So 0% PWM is 0V, 50% PWM is 2.5V, and 100% PWM is 5V. However, we can't rely on a constant PWM signal to provide reliable stirring. Why not?
- Even with the same motor part and manufacturer, variations exist in the motors. So a 30% PWM signal in one motor might produce 100 RPM, in another motor the same PWM signal might produce 200 RPM. These differences are enough to change the growth of the microbes, and ruin the interchangeable status of the Pioreactor. This can be "corrected" with calibration, but I think calibration is an anti-pattern and should be automated away.
- As the culture multiplies in the media, the cells themselves, along with metabolites, cause the liquid to become more viscous. So over time, with a constant PWM, the stirring will slow down unpredictably.
Our simple solution to the above problems is to introduce a feedback loop between a measured RPM and the applied PWM signal. Controlling the PWM is done in software, but how do we measure the RPM? The solution we came up with was the put a Hall effect sensor inside the magnetic field, see Figure 2. These sensors will respond to a changing magnetic field, and are commonly used in industry and home: to determine if doors are open/shut, proximity of two pieces, etc.
The Hall effect sensor sends a digital signal back to a GPIO pin on the Raspberry Pi. From this signal, it's easy to average the duration between pulses (aka the frequency), and determine the RPM from there.
In the stirring job, we calculate the RPM every N seconds (currently N=10), and adjust the PWM signal using a PID controller. The response time and accuracy is pretty good, even after a few hours of tinkering, see Figure 3.
We explored other options for measuring RPM. Some motors have a built in RPM sensor, but these are very expensive compared to a "dumb" motor. We also explored creating a circuit that can detect a voltage drop caused by the alternating commutator in the brushed motor, but we abandoned this since it wasn't reliable enough. The Hall sensor design we chose is both cheap and reliable.