I have been working really hard towards this day and I am proud to announce that as of today BrewPi is fully open source! Sorry to have kept you waiting for so long, but it just takes so much more time when you are building something that anyone should be able to use compared to hacking something together for yourself.
BrewPi is an open source fermentation controller that runs on an Arduino (for now) and a Raspberry Pi. It can control your beer temperature with 0.1 degree precision, log temperature data in nice graphs and is fully configurable from a web interface.
If you are not into brewing, but do like to thinker with electronics, give the article a read. I had to invent many little things that could be very helpful for other projects too. I can think of a lot of cool things you could that involve controlling an Arduino from a web browser.
To give you an idea of the features, here’s a slide show:
Initially this project was called UberFridge. It ran on a router instead of a Raspberry Pi. There is a write-up on UberFridge on my personal website. I got so much positive responses the UberFridge, that I decided to continue it as an open source project.
First of all: thanks to every brewer that took the time to fill in my interest check survey. It was very valuable in writing a business plan and confirmed that there was a huge demand for a Raspberry Pi based brewing controller like BrewPi (357 full responses and 431 partial responses!).
I have registered BrewPi as a business, because I eventually want to sell complete kits to convert a fridge into a BrewPi fermentation controller. You should be able to buy every component you need in one convenient package, instead of searching the Internet for every part. I am also looking into creating a PCB that already has all connectors for the sensors and the actuators, thermocouple amplifiers, a display connector, JTAG header, etc. This would make it really plug and play. I have the tools for small production runs, but have not found the time yet.
I feel like I have kept you waiting long enough, so I released the software for BrewPi today. Setting up a shop and supplier relations would delay the release too much. There is a perf board friendly layout for a BrewPi Arduino shield further down in this post for the brewers that want to start building today.
My main goal now is to get as many people involved as possible and to provide the tools for smooth collaboration. So everything is open: anybody can edit the Wiki, report bugs in Mantis, clone and fork the GitHub repositories and join the discussion on the forum.
So at the moment I am not selling anything, but you can start building today. If you want to support BrewPi, you can buy me a beer 🙂
What’s new since UberFridge?
Many things have changed and improved in converting UberFridge to BrewPi. It has almost been rewritten from the ground up, so I’ll just mention the major changes here. These changes are partly the result from my experience with UberFridge and partly from moving to the Raspberry Pi as a platform. But mainly these changes have been made to make BrewPi very configurable, usable in many situations and manageable as an open source project. I really want this to be something we will build together, instead of a one man project.
Atmel Studio, C++ classes, JTAG
When I look at the UberFridge Arduino code now, I think it’s a mess. It definitely was not a good starting point for an open source project, so I completely rewrote it. The new code is nicely packed into an Atmel Studio project, which has the fantastic Visual Studio 2010 shell. Try it and you will never go back to the Arduino environment.
If you have a debugger like the AVR Dragon and you buy an Arduino Leonardo, you can debug with JTAG: you can set breakpoints and view all your variables and registers on the target.
The new code is also written fully in C++ and makes extensive use of classes. This makes to code much easier to read and debug.
I didn’t want to go the complicated way of compiling the Arduino libraries and adding a makefile like many other guides on the web. Just download the example project, change two directory settings and you are good to go with AVR studio. There are a few compiler settings that reduce the code size, but make debugging a bit harder. If you want to use Atmel studio for a different project, take a look at this guide.
DS18B20 digital 12 bit temperature sensors
I replaced the analog LM35 temperature sensors with digital DS18B20 sensors from Maxim. They have a 0.0625 °C resolution and are very stable. With some fixed point filters, see next paragraph, the resolution increased even more.
In my UberFridge project, I used 3.5mm jack plugs to connect the sensors. Bad idea, very unreliable! They are now replaced by sturdy 3 pin DIN connectors. Each sensor has it’s own Arduino pin, because they are easier to identify that way.
Each sensor is wrapped in a class that has a fast filter, a slow filter and a filter for the slope of the temperature.
Fixed point variables and filtering
BrewPi, contrary to UberFridge, uses no floats at all. All temperatures and control variables are stored as fixed point integers, with 7 integer bits and 9 fraction bits. (From 64 to 64 degrees Celsius, 512 steps per degree).
If you want to create very slow filter, floats are a bad idea. A very slow low pass filter requires adding a tiny fraction of each new value to the old values. With floating point, you will lose data. The new fixed point filtering class uses 32 bit precision internally, so 16 additional fraction bits, and is configurable to have a step response of 25, 50, 100, 200, 400 or 800 samples. The filter coefficients are configured for the fastest step response without overshoot.
The control algorithm internally uses Celsius, like any good scientist would. But, because for most brewers Celsius doesn’t make sense, temperatures can be converted at the boundary. There are functions to convert from the fixed point format to strings for both Celsius and Fahrenheit. Just flip the switch in the web interface.
The PiLink class
Something I really miss in the Arduino environment is the printf function. It’s a bit expensive in code size, but it’s so nice to have. So I wrapped all the serial communication with the Raspberry Pi in the PiLink class. It has easy to use print functions for debug messages, data logging and annotations. It can also send and receive all variables and settings as JSON strings. This makes it much easier to make everything configurable from the web interface, which brings me to my next point…
There is a tab in the maintenance panel now, that lets you configure all the constants for the control algorithm. All settings are stored in EEPROM and will be remembered between restarts. You don’t have to reprogram the Arduino to tweak your controller.
To make it easier to find the right settings, there is a page that displays the control calculations in a clear overview.
For your other projects that require storing settings in EEPROM, take a look at how it’s implemented here. It’s really easy when you wrap your settings in a struct.
A nicer display menu with a rotary encoder
To reassure you that your beer is doing fine every time you pass your UberFridge, I really like the very clear and bright 4×20 character OLED display I have been using. You can build your BrewPi without one. Or you can even use BrewPi without a rasp, data logging and the web interface, just the OLED display. I like to have both. The new OLED class has better initialization and is more stable than the old one.
I previously used 3 buttons for the menu on the fridge. That has been replaced now with a rotary encoder which can be rotated and pushed. Just one knob to easily adjust your temperature settings. See how the rotary class is implemented here.
Solid state relays
I used normal mechanical relays for UberFridge, but I have switched to solid state relays for BrewPi. They can be controlled directly with an Arduino pin and are safer to use than there mechanical relatives.
Safer users and permissions
In UberFridge, everything ran as root. Easy to set up, but not very secure. With the new release, the BrewPi Python script runs under the brewpi user. The web interface runs as the www-data user. There are instructions on the Wiki on how to set up user permissions to make it work smoothly and safely.
Programming the Arduino from Python
In the old UberFridge, the Arduino was programmed by invoking avrdude from PHP with a shell_exec. But giving PHP such privileges isn’t exactly safe. So now PHP uploads a file and asks the Python script to upload it to the Arduino. The Python script parses the Arduino boards.txt file to load the correct parameters, resets the Arduino, uploads the Hex file and restarts the BrewPi script to just continue running.
Keeping brewpi alive with CRON
There is a shell script included that checks that the script is running and to restarts it if not. If it cannot find the serial port it will restart the pi. With this script added to the brewpi user’s crontab, the www-data user doesn’t have to have permissions to start Python, which is a lot safer.
I hope that this is just to beginning and that BrewPi will become an active platform with many users and contributors, instead of a one-man-show. With a wiki, a bug tracker and a forum, I hope I have provided the right tools for collaboration. If you are missing anything, just tell me and I’ll see if I can add it.
A few points came already came up in e-mails and forum posts, which I would like to address here as well.
Why not use just the Raspberri Pi without an Arduino?
There have been examples of brewing controllers that use the Pi’s GPIO pins intead of having and Arduino slave, but having a slave is a deliberate choice for me. The main reason for this is that the Pi is not very stable. I have had it crash on me multiple times. So what happens to the GPIO pins when it crashes? Will it just keep cooling your beer to 4°C and stop your fermentation?
The Arduino slave simply will not crash. Even if the Pi crashes, the temperature control keeps running. Your beer is safe. The worst thing that will happen is that it will not get a new temperature from the temperature profile and no data will be logged.
A microcontroller is better suited to interface low level hardware. The Pi is better suited to log data and provide an interface. I think it’s a better design this way.
Is Arduino the right platform?
The Arduino works fine for now, but I think we will need to move on to something like an ARM Cortex M4 in the future. My Arduino Leonardo only has a few bytes of program space left with the current program. The code space is so large, because almost al variables are 16 or even 32 bit. That takes up a lot of instructions on an 8-bit platform.
The Arduino is fast enough and powerful enough, because it just needs to update its controller once every second. Avr-gcc has absolutely no problem with up to 64 bit variables, but it will cost you in code size. Program size is the main problem.
I have pre-ordered a TI Stellaris Launchpad,but it has not arrived yet. If you manufacture board that you think would be great for BrewPi, feel free to contact me or send me a sample.
Another option would be to make our own board, instead of a shield to plug onto an off-the-shelve board. Let’s discuss that on the forum.
A proper web framework
Eventually I would like to move to a framework that allows plugins, skins, etc. But I am not the right guy for the job. So if you feel like you could contribute on this part, start a discussion on the forum.
A digital specific gravity sensor
In my interest check survey, I had some questions about a digital specific gravity sensor. I think I have succeeded in building one and now that BrewPi is finally ready I can start testing it with a real fermenting beer instead of water.
My method involves accurately weighing a weight that is hanging in the beer from a cord. The resulting force gives the buoyancy force, from which the gravity can be calculated.
I don’t want to go into detail about my exact method now. A couple of months after after I have published my method in the interest check, the BeerBug has left its original design that measured capacitance and started using the same method. I want to withhold some details until I have properly tested my design and am ready to get you guys involved.
How to get started TODAY
Go to the Wiki for step-by-step instructions to get BrewPi on your Raspberry Pi.
Download the Arduino shield layout in a PDF document (schematic, top view, bottom view), or as Eagle files. This layout uses 0.1 inch pitch so you can translate it directly to a perf board layout. If you don’t have a JTAG debugger, you can leave out the JTAG connector. You can also leave out the 10k resistors if you use the internal pull-up resistors (there is a #define in the code for this).
You might have noticed that BrewPi doesn’t have a logo yet. Got great design skills? We need you over here!
If you want to stay up to date, you can…
- Follow BrewPi on twitter
- Subscribe to the mailing list
- Follow this blog though RSS
- Subscribe to the blog (side bar on blog)
That’s about it for this update. Cheers!