A Raspberry PI Espresso Machine
by pivalse in Circuits > Raspberry Pi
12 Views, 0 Favorites, 0 Comments
A Raspberry PI Espresso Machine
When I moved from the US to Germany, one of the first thing I bought was an espresso machine. Since I did not have a lot of money, I looked for something cheap on Kleinanzeigen and got this very old VBM Junior from a couple that did not know how to set it up and use it. They were so desperate to get rid of it that they added a coffee grinder for free and all the coffee they had. I threw the coffee away.
Considering my living situation at that time, being able to make coffee was a considerable upgrade. After buying some better coffee and setting up the grinder properly, I realized that some setting was needed and set out to discover what I could set up in it. So, I opened it and it looked like what is visible in the picture below.
The VBM Junior is a very simple machine with one single pressure vessel and no electronics. The temperature of the water is controlled by two staged thermostats. The one that controls the temperature to make espresso is the big black box visible on the top in the picture. It has a regulation screw on top and a thermometer sonde that fits in a cylinder that reaches the middle of the vessel. While measuring the temperature at the center of the vessel may be very precise, the control is still electro-mechanical, with the thermostat switching the heater 100% on when it is below a minimum temperature and switching it off when it is above a maximum temperature. The regulation screw moves these two temperatures up and down but obviously there is no way of knowing these two activation temperatures. The optimal brew temperature is set by making coffee every eighth of a turn.
In addition to the feeble temperature control, the small size of the vessel makes the water temperature change rapidly when the pump is activated. When brewing, cold water from the water tank at ambient temperature enters and cools down the rest.
The second thermostat is a much smaller unit placed on the top of the vessel and serves for the second setting, the one for making steam. Three switches are present in the front of the machine. One is to turn the machine on and one is to switch from espresso to steam. The third one is still a mystery to me. In the picture above is a sketch of the very simple, yet incomplete, electrical wiring. Everything runs on 220V-AC.
When I first opened the machine, I could see water leakages at several points and damages to plastic parts due to heat. While the machine may have been operated for a few years without de-scaling or basic cleaning, I noticed that some wires had been moved and, in my opinion, misplaced. Still, the machine worked.
Of course, I first took it completely apart as a way of inspecting it for further damages and for a deep cleaning and descaling. The picture on the first page was taken after I put it back the first time.
Before embarking on the journey that I am describing in these pages, which lasted a few years between different life events, I shall point out that the VMB Junior is a perfectly functional machine that makes a good coffee. In other words, there was absolutely no need to do anything to it beside my curiosity and the pleasure that tinkering gives me.
Downloads
Supplies
What you need for this project
- Obviously, you need an old espresso machine that is mechanically sound. I chose a VBM Junior. VBM is a small Italian company out of Milan that makes excellent machines. I found this one used for about €200
- A Raspberry PI Mini, preferably with a WIFI
- Two MAX31855 boards and two thermocouples
- An expansion board
- A Display HAT Mini
- Two Steady-State Relays (SSR) rated at 20-40A
- Four buttons for low voltage
- One 220VAC – 5VDC converter
- A 3D Printer
Downloads
Measuring the Temperature With Arduino
While some control of the temperature was achievable, the temperature of the water when I made coffee could vary considerably depending on whether the thermostat had just reached the lowest point (and turned on the heater) or the highest point (turned it off) or any position in between. Before thinking of any possible way of improving it, I decided that I first needed to know how far the temperature of the water would oscillate between the two activation temperatures of the thermostat. So I decided to add a thermometer, which I made using an Arduino.
For that, I just needed an Arduino, a thermocouple with its electronic reader, a display and, obviously the power supply. Since I was already doing that, I decided on three temperature measurements: one at the bottom of the tank for the water temperature, one at the top of the tank for the case of steam, and one at the brew unit to measure the temperature of the water right at poured, as shown in the pictures above. I used K-thermocouples and connected them to MAX31855 and MAX6675 chips, which cost about €5 each. It turns out that they have to be insulated electrically from the metal of the machine, so I had to re-do it a few times. The connection to the Arduino is straightforward and the coding is readily available on the internet.
Next, I connected the smallest display I could find. I started using a 128x32 color screen that I bought for a previous project. After fidgeting with it for a week, I realized that it was broken from the beginning or that I fried it. It turns out that the new one is monochrome and is 128x32 instead of the 128x64 that was indicated when I ordered it. Still plenty of real estate for showing one, two, or even three numbers.
I made an enclosure out of a plastic sheet just to provide a minimal protection, as I installed it inside the espresso machine and added cheap 220VAC – 5VDC converter to run the Arduino mini, as visible in the figure below.
Not wanting to mess with the chromed front of the espresso machine, I designed a support for the display and glued it to the front. There was a cable running from the back to the side, but it was not visible unless one looks closely. At the end, this was meant as a first measure to understanding how good the machine was at maintaining a temperature for one espresso. The total cost was less than €30.
The ability to see the temperature at all time was a neat upgrade which allowed me to know when to pour a coffee based on the temperature. It also gave me an insight on how much the temperature swung due to the thermal inertia and the temperature controls. I used the VBM Junior for a couple of years until I bought a second (broken) larger one and repaired it to be my primary espresso machine. At that point, the VBM became a larger project…
Downloads
The Raspberry-controlled Coffee Machine
From Arduino to Raspberry PI
The VBM Junior with the temperature measurement worked perfectly for me until, about two years later, I bought a larger espresso machine or, to be precise, another project. I paid a couple of hundred euros for a Bezzera instead of over a thousand, just because the tank had a fracture and the electronics stopped working. Once I repaired it and made it my daily source of cappuccinos, I could take the VBM completely apart and rebuild it to have a few more features. I wanted a PID/controlled temperature and a WiFI connection, just in case I want to interface it with my computer or my smartphone.
That meant taking it completely apart to heavily modify the frame, as it had to host a display and all the electronics and controls. It also meant adding a separate control circuit at 3.3 / 5 V-DC .
The frame
I took the occasion to reshape the entire frame. The original frame is made of two parts: the front simply holds the water tray under the E60 brew-group and the back us an L-shaped metal plate that holds the basic electronics on the floor and the plumbing on the vertical plate. A chromed front plate is placed over the front and has all the necessary signs for lights and switches.
I perforated the bottom plates on the front and on the back, not just to reduce the weight but also to prevent water from collecting inside the frame in case of a leak, or just due to humidity. I added four large feet to make the machine a bit taller and give it a bit more design character.
Since the new configuration has more electronics and some additional metal structures to act as electromagnetic shield, additional holes were also drilled on the frame to fasten the additional pieces.
The more evident modifications were on the vertical plates. Going from the original 220VAC switches and 220VAC lights to 3.3VDC buttons with one LCD screen, a few holes became unnecessary and a new holes were needed. I had to ditch the chromed plate and substituted it with a brushed aluminum plate that I also painted with a transparent coat.
Beside the holes for the E61, the pour switch, the manometer, and the steam pipe, I opened a square hole for the LCD screen and added four buttons. Having a large screen, I decided not avoid additional lights.
It took me several iterations and rebuilds to reach the final shape. The hole for the LCS screen, for example, took a few successive enlargements and adjustments to fit the screws, to design a proper cover, and to avoid unexpected short-circuits with the sensitive electronics of the LCD screen.
The power circuit on the bottom
The 220VAC power originally came through a cord locked in place at the bottom. I substituted it with a socket to plug the power cord from below. This way, the power cord can be detached. I added a more shielded distribution plate for the three main power users: the AC/DC transformer to run the Raspberry PI and the 5VDC circuit, the water pump through a relay, and the heater through another relay.
In the picture on the left, the first realization of the left power circuit, with the main plug, the distributor, and a first transformer. I spent months fighting what I thought were electromagnetic interferences between the buttons and the relays, just to realize that the transformer was just too weak and would make the Raspberry freak out when the relays kicked in. So, I replaced the transformer with something a bit more professional and steady, as shown in the picture on the right.
The machine has two elements that require 220 VAC power (the heater and the water pump). Moving from the original wiring to an electronic control means that they must be steered through relays. I mounted the two relays on the floor in the back, the only place with enough space. This is visible in the figure below. I built a metal shield to separate these power circuits from the transformer and, above from the low voltage electronics circuit. While the relay for the heater is a very oversized solid-state relay (SSR), my first choice for the pump was a cheaper relay that turned out not to be a solid-state relay. When I rep laced the transformer, I took the occasion to replace that relay with a real SSR. The combination of the new transformer and the new SSR made the interference problem disappear. In the figure below, the first configuration is shown on the left, and the final configuration with the two SSR is shown on the right. For the heater, I chose a solid-state relay (SSR) with a rating of 40A, which safely exceeds the rating of the heating coil (1100W, or about 5A x 220V). At about €20, it is the most expensive element in this project. In order to run the pump, I chose a second, smaller SSR.
The original lights were removed since there is now a display and of the original switches I kept the one activated by the pour lever and the one that detects the water tank being full. They are now on the control circuit. Additionally, I installed four buttons.
The electronics circuit
I spend way too much time fiddling with the issue of interference between the relays and the electronics. In my first iteration, in 2023, I abandoned the project for months out of despair. I rebuild the entire frame to have metal shields and physical separation in 2024, and seriously restarted it in 2025. The iterations were useful, though, to arrive at a mechanical setup that looks professional. The metal shield and the physical separation of the electronics circuit is shown in the figure on the right.
For the CPU, I chose a Raspberry PI Mini because of the reduced footprint. It still offers plenty of computational power to manage a couple of switches, a display, and two relays. I fried the first Raspberry PI by touching it when it was all connected. I bought a second one without the WiFi and therefore, the third one was the version with WiFi, which makes it infinitely easier to program and setup up through my laptop.
The electronics are mounted on a 3D-printed frame that attaches on the back vertical panel in the location of the LCD screen. The screen is mounted on the front and two long screws fasten the screen cover, the screen, and the frame.
The frame hosts the Raspberry PI in the middle. On the top, a board to distribute the GPIO connections in two directions. The LCD screen requires an entire 40-pin connector, even though it uses much less. The other channels are connected through individual wires, as shown in the picture below.
Below the raspberry PI on the 3D-printed frame is a small board where I wired the pull-up resistors for the buttons and the switches. Switches cannot be simply connected between the 5V power and the GPIO port. Beside the fact that the 3.3V is recommended, the port must be connected through a large resistor to the ground and another resistor helps stabilize the signal.
There are four buttons I added as a way to provide intuitive inputs to the computer: a main button that substitutes the functions of the main switch, and three additional buttons placed under the LCD screen to interact with the screen. In addition, the original switch behind the pour lever has been retrofitted to work with the electronics (at 3.3VDC instead of 230VAC), and the same was done for the switch under the tank that signals whether there is enough water. These six button/switches are wired with the appropriate resistors on a small board under the Raspberry PI.
Two K-type thermocouples measure the temperature at two different positions on the tank, and are connected through MAX 31855 boards. The two boards share the power connection (3.3VDC and ground) and the input signals (CLK and CS). The output from the boards go back to the Raspberry PI. One of the MAX31855 boards is mounted on the small board of the switches while the second one is installed directly on the metal shield, due to the lack of space.
Finally, two outputs from the Raspberry PI go directly to the two Solid-State Relays to steer the pump and the water heater.
For the display, I chose a 4” 480x200 RGB HAT mini (PIM589), which fits perfectly on the upper right corner of the front of the machine. This LCD display has four buttons on the front, which are however, ignored in this project and are closed by the front panel cover.
The complete wiring of the electronics is shown in the figure below, where the GPIO ports from the Raspberry PI are in the middle. The electronics circuit is marked by normal black lines and the power circuit is marked by bolder black lines.
It must be noted that the machine does not have a proper main switch to turn it on. Once connected to the power, the machine remains in stand-by modus where only the Raspberry PI is powered. The “main” button is used to signal to the Raspberry PI to go from stand-by to other operation modes. At first, however, only one operation mode (“espresso”) is available.
Of the other three buttons, only two are currently assigned functions (increase/decrease brightness, increase/decrease temperature target). The third button, as of now, does not have a function.
Coding and testing
The development of the code and the mechanical build grew together in a sequence of re-builds. At each re-build, I followed the same sequence of tests and re-coding. I started with the functions associated with the buttons, then added the display, then the switching of the pump and the reading of the tank switch status. Then the reading from the thermocouples, and finally the PID to control the tank temperature.
The buttons
It took a very long time to get the wiring right, together with the correct coding. I chose RPi.GPIO as the Python module to interact with the GPIO. It offers a neat solution for triggering functions upon “events” such as switch going from off to on (rising) or from on to off (falling). Phantom triggers are still occurring, although rarely, but I need the code to be sufficient robust to understand what is real and what is not. This is particularly important for the pour switch, as now the pump is operated from a line of code and not from an actual switch. Should the code crash when the pump is on, the pump will remain on. Fail-safe concept must be built in the code.
The “main” button is only meant to switch between machine states such as the stand-by and the espresso state. Further “states” will be built within this concept.
The function of the other two buttons depend on the machine state. In stand-by, they only increase and decrease the brightness of the display. In the espresso state, they increase and decrease the target temperature for the tank.
The pour switch, if the machine is in the espresso state and if the tank switch is not off, causes the pump to run.
The state of the tank switch is reported on the display for all states. If the tank switch is off (not enough water in the tank), the pump will not activate and the PID will not send signals to the relay for the heater.
The display
At present, only two states are available: stand-by and espresso. Stand-by has a dark background and only shows the time in the middle. The state of the tank is shown and the function of two buttons (more or less brightness) is also indicated.
The espresso state is where the machine actually works. It has two different background colors: one for the case of no water in the tank (to indicate that nothing will work until water is added), and one for operation. Next to the indication “espresso”, is the time. In the middle is the current tank temperature and the indication of the target temperature. The state of the water tank is also indicated.
The Solid-State Relays
The SSR connected to the pump is not modulated and is simply programmed with an On/Off signal from the GPIO.
The heater, on the other hand, uses a modulated signal to the SSR which better operates the function of the PID. For this case, I used a PWR port from the Raspberry PI and the PWR function with a frequency of 1000Hz.
The control of the temperature in the tank
Using a PID to control the water temperature was the original scope of the project, which escalated into all this. Once all this electronics is in place, however, the actual PID consists of three lines of code, as a PID module in Python takes care of all the complex calculations to determine the signal modulation to the SSR.
The calibration of the PID is the most complex work here, as the right combination of Ki, Kp, and Kd prevents overshoots or oscillations, and quickly reaches the desired temperature.
The persistence
The Raspberry PI runs a Debian Linux version and, in principle, it reaches a graphic GUI state where the user interact through a display and a keyboard/mouse combination. In the stand-alone configuration of the machine, the I/O (the display and the buttons) is connected with the GPIO and is managed through a Python script. The Python script must be automatically started once the machine is switched on and it must run continuously. Should the Python script for any reason stop, it must be restarted automatically.
This is achieved by setting up a system service that calls a batch script. The batch script verifies every 10 seconds that the python script is running and, if not, it starts it again.
Turning off the machine
One button has been reserved to ensure an orderly shutdown of the Debian Linux. The Python code controls that button. When it is pressed twice, the Python script calls for a power down process. In order to restart the machine, the power plug must be unplugged and plugged in again.