Forum

Notifications
Clear all

Brewery Code

Page 1 / 3

(@pbruno3)
Reputable Member Admin
Joined: 4 years ago
Posts: 308
Topic starter  

Hi,

Here is my current script for my brewery. It is not commented, but it should generally make sense (maybe except the sparge loop!).

[setup]
new value MashVol
new value SpargeVol
new value StrikeTemp
new value MashStep1Temp
new time MashStep1Time
new value MashStep2Temp
new time MashStep2Time
new value MashStep3Temp
new time MashStep3Time
new value MinFlowRate
new value MaxFlowRate
new value PreBoilVolume
new string Status

MashVol = 18
SpargeVol = 17
StrikeTemp = 160
MashStep1Temp = 152
MashStep1Time = 01:00:00
MashStep2Temp = 152
MashStep2Time = 00:00:00
MashStep3Temp = 152
MashStep3Time = 00:00:00
MinFlowRate = 0.9
MaxFlowRate = 1.1
PreBoilVolume = 30

[prep]
Status = "Ready to Start"
"Step" Type = CountUp
restart "Step"
"Mash Temp" Enabled = true
"Mash Level" Enabled = true
"RIMS Temp" Enabled = true
"Flowmeter 1" Enabled = true
"Valve 1" Enabled = true
"Valve 2" Enabled = true
"Valve 3" Enabled = true
"Valve 4" Enabled = true
"Valve 5" Enabled = true
"Valve 6" Enabled = true
"Valve P1" Enabled = true
"RIMS Heat PID" Enabled = false
"RIMS Heat Duty" Enabled = false
"RIMS High Power" Enabled = true
"Pump 1" Enabled = true
"Pump 2" Enabled = true
"RIMS Heat PID" Enabled = false
"Water Input" Enabled = false
"Boil Temp" Enabled = false
"Boil Heat Duty" Enabled = false
"Boil Heat PID" Enabled = false
"Chill Temp" Enabled = false
"Chill Flush" Enabled = false
"Vent Fans" Enabled = false
"Panel Alarm" Enabled = true
"CONTINUE" State = false
wait "CONTINUE" State == true

[prep_fill]
Status = "Prep Fill"
restart "Step"
restart "Master"
"Valve 1" State = on
"Valve 2" State = off
"Valve 3" State = off
"Valve P1" Value = 60
"RIMS High Power" State = on
"Pump 1" State = off
"Valve 4" State = off
"Valve 5" State = off
"Valve 6" State = off
sleep 5000

[fill]
Status = "Fill"
restart "Step"
"Pump 1" State = on
wait "Mash Level" Value >= MashVol

[prep_strike]
Status = "Prep Strike"
restart "Step"
"Pump 1" State = off
"Valve 1" State = off
"Valve 2" State = on
sleep 10000
"Pump 1" State = on
sleep 10000
"RIMS Heat Duty" DutyCycle = 100
"RIMS Heat Duty" Enabled = true

[strike]
Status = "Heat Strike"
restart "Step"
new value PreStrikeTemp
new value StrikePIDTarget
PreStrikeTemp = StrikeTemp - 3
StrikePIDTarget = StrikeTemp + 1
wait "Mash Temp" Value > PreStrikeTemp
"RIMS Heat PID" Target = StrikePIDTarget
"RIMS Heat PID" Enabled = true
delete PreStrikeTemp
delete StrikePIDTarget

[strike_loop]
if "Mash Temp" Value >= StrikeTemp
	"Brew Alarm" Active = true
	"RIMS Heat PID" Target = StrikeTemp
	goto dough_in
endif
sleep 3000
goto strike_loop

[dough_in]
Status = "Strike Ready"
restart "Step"
"CONTINUE" State = false
wait "CONTINUE" State == true
"Brew Alarm" Active = false
"RIMS Heat PID" Enabled = false
"Pump 1" State = off
sleep 3000
"RIMS High Power" State = off
Status = "Dough In"
"CONTINUE" State = false
wait "CONTINUE" State == true

[mash_step1]
Status = "Mash Step 1"
restart "Step"
"Valve P1" Value = 45
sleep 5000
"Pump 1" State = on
sleep 3000
"RIMS Heat PID" Target = MashStep1Temp + 2
"RIMS Heat PID" Enabled = true
wait "Step" Value >= MashStep1Time

[mash_step2]
Status = "Mash Step 2"
restart "Step"
"RIMS Heat PID" Target = MashStep2Temp + 1
wait "Step" Value >= MashStep2Time

[mash_step3]
Status = "Mash Step 3"
restart "Step"
"RIMS Heat PID" Target = MashStep3Temp + 1
wait "Step" Value >= MashStep3Time

[mashout]
Status = "Mashout"
restart "Step"
"RIMS Heat PID" Enabled = false
"Valve P1" Value = 60
sleep 3000
"RIMS High Power" State = on
sleep 3000
"RIMS Heat PID" Target = 172
"RIMS Heat PID" Enabled = true
wait "Mash Temp" Value > 168

[prep_sparge]
new value MashTopLevel
new value MashBotLevel
Status = "Prep Sparge"
restart "Step"
"RIMS Heat PID" Enabled = false
sleep 5000
"Pump 1" State = off
sleep 5000
MashBotLevel = "Mash Level" Value
MashTopLevel = MashBotLevel + 1
"Valve P1" Value = 30
"Valve 2" State = off
"Valve 3" State = on
"Valve 1" State = on
"Valve 4" State = off
"Valve 5" State = off
"Valve 6" State = on
"Pump 2" State = off
"Boil Temp" Enabled = true
"Flowmeter 1" Enabled = false
"Boil Level" Enabled = true
sleep 5000
"Flowmeter 1" Enabled = true
"Pump 1" State = on
"Pump 2" State = on
sleep 5000
"RIMS Heat Duty" DutyCycle = 60
"RIMS Heat Duty" Enabled = true

[sparge]
Status = "Sparge"
restart "Step"
new value SpargeLoop
new bool FlowOK
SpargeLoop = 0
[sparge_loop]
if "Flowmeter 1" Value >= SpargeVol
	goto drain
endif
if "Mash Level" Value > MashTopLevel
	"Valve 6" State = on
	sleep 3000
	"Valve 6" State = off
	sleep 3000
	SpargeLoop += 5
endif
if SpargeLoop >= 10
	FlowOK = true
	if "Flowmeter 1" Rate > MaxFlowRate
		"Valve P1" Value -= 1
		FlowOK = false
	endif
	if "Flowmeter 1" Rate < MinFlowRate 
		"Valve P1" Value += 1
		FlowOK = false
	endif
	if FlowOK == true
		if "RIMS Temp" Value > 175
			"RIMS Heat Duty" DutyCycle -= 1
		endif
		if "RIMS Temp" Value < 165
			"RIMS Heat Duty" DutyCycle += 1
		endif
	endif
	SpargeLoop = 0
endif
sleep 1000
SpargeLoop += 1
goto sparge_loop

[drain]
delete MashTopLevel
delete MashBotLevel
delete SpargeLoop
delete FlowOK
Status = "Drain Mash"
restart "Step"
"Valve 6" State = off
"RIMS Heat Duty" Enabled = false
"Valve 1" State = off
"Valve P1" Value = 0
"Pump 1" State = off
sleep 5000
"RIMS High Power" State = off
"CONTINUE" State = false
[drain_loop]
"Valve 6" State = on
sleep 3000
"Valve 6" State = off
sleep 10000
if "CONTINUE" State == true
	"CONTINUE" State = false
	goto boil
endif
if "Boil Level" Value >= PreBoilVolume
	goto boil
endif
goto drain_loop

[boil]
Status = "Boil Ramp"
restart "Step"
"Pump 2" State = off
"Valve 3" State = off
"Valve 6" State = on
"Boil Heat Duty" DutyCycle = 100
"Boil Heat Duty" Enabled = true
"Vent Fans" Enabled = true
"Vent Fans" State = on
"Mash Temp" Enabled = false
"Mash Level" Enabled = false
"Flowmeter 1" Enabled = false
"RIMS Temp" Enabled = false

wait "Boil Temp" Value >= 210
Status = "Boil"
"Step" Type = CountDown
"Step" Value = 01:00:00
"Boil Heat Duty" DutyCycle = 65
wait "Step" Value <= 00:05:00
"Valve 4" State = on
"Valve 5" State = on
"Valve 6" State = on
"Chill Temp" Enabled = true
sleep 10000
"Pump 2" State = on
"Boil Heat Duty" DutyCycle = 100
sleep 15000
wait "Boil Temp" Value >= 210
"Boil Heat Duty" DutyCycle = 65
wait "Step" Value <= 00:00:00
"Boil Heat Duty" Enabled = false

[chillboil]
Status = "Chill Boil Kettle"
"Chill Flush" Enabled = true
"Vent Fans" State = off
[chillboil_loop]
"Chill Flush" State = on
sleep 30000
"Chill Flush" State = off
sleep 15000
if "Boil Temp" Value <= 175
	goto whirlpool
endif
goto chillboil_loop

[whirlpool]
Status = "Whirlpool Fast"
"Step" Type = CountUp
restart "Step"
"Boil Heat PID" Target = 170
"Boil Heat PID" Enabled = true
"Valve 5" State = off
wait "Step" Value >= 00:10:00
Status = "Whirlpool Slow"
"Valve 5" State = on
wait "Step" Value >= 00:15:00

[transfer_prep]
Status = "Transfer Ready"
restart "Step"
"Brew Alarm" Active = true
"CONTINUE" State = false
wait "CONTINUE" State == true

[transfer]
Status = "Transferring"
"Brew Alarm" Active = false
"Boil Heat PID" Enabled = false
"Chill Flush" State = on
"Valve 6" State = off
"CONTINUE" State = false
wait "CONTINUE" State == true

[shutdown]
start "Brew Shutdown"
stop "Brew"

 


Quote
(@thesleepydog)
Active Member
Joined: 4 years ago
Posts: 9
 

Are you willing to share what flow meter you have used and how you set that up in the brucontrol interface?

I am also wanting to know how many outputs / inputs the Arduino Mega can control without the use of a serial to parallel multiplexer. Can you use a serial to parallel multiplexer with brucontrol?

 


ReplyQuote
(@thesleepydog)
Active Member
Joined: 4 years ago
Posts: 9
 

And can you share how you coded or setup the proportional electric valve? is this a 4/5 wire or 3 wire valve you are using for this?


ReplyQuote
(@pbruno3)
Reputable Member Admin
Joined: 4 years ago
Posts: 308
Topic starter  

Absolutely! The flowmeter I have been using is an inexpensive unit which I originally purchased just to do testing with, but it worked so well I put it into service, and it has worked flawlessly for over 18 months. The model is here  https://www.adafruit.com/product/828 but you can find the same model on both Amazon and eBay. 

To wire it, you connect the Ground to the control system ground, +5V to the 5V power supply or the interface's 5V output if it has one and it is not overloaded (for example, the MEGA has a 5V regulator output you can draw up to 200mA off.). The output goes to an PIN of the micro which is capable of high-speed counting. The Interface Wiring Maps have these PINs (ports) marked with a 'C'.

To set it up in BC, you create a Counter Input device element. Select the port/PIN the flowmeter is wired to, then it will report pulses and its pulse rate. Add calibrations for both the Total and the Rate values. For this flow meter, I found 355 pulses per quart to be right at the slow rate I need it to be most accurate. Therefore, for Total (in quarts), I added a 0.0028169 linear multiplier calibration, which is 1/355. For the Rate (in quarts/min), its 60/355, so the multiplier is 0.1690141. Let me know if you would like me to explain these calibrations in more detail or with the units.

The MEGA can natively control about 45+ digital inputs or outputs, 14PWM/Analog outputs, 16 analog inputs, 4 counter inputs, and more (see User Manual page 14 for specifics.). We have not addressed any I/O extenders as of yet, but honestly don't see the need, because BruControl's architecture permits multiple distributed interfaces (Advanced version). So if more I/O were needed, it would be easier/cheaper/more reliable just to duplicate the interface (like multiple MEGA's).

Regarding the proportional valve, I selected a 24VDC, 0-5V control. So it receives full time 24V power for the logic, then monitors the 0-5V input for it's 0-90 degree valve control. I built a R-C network from a 300 ohm series resistor and a 220 uF parallel capacitor to convert the PWM output of the MEGA to a stable analog voltage. It works exceptionally well!

To control the valve, you would set up a PWM Output device element. I added a 2.55 multiplier to convert the 0-255 output value to 0-100%.

Let me know if these answer your questions or if you have any additional - happy to help!

 


ReplyQuote
(@dps1331)
Active Member
Joined: 3 years ago
Posts: 7
 

Rather than a proportional valve could a dc pump be modulated through the software to control flow?  


ReplyQuote
(@pbruno3)
Reputable Member Admin
Joined: 4 years ago
Posts: 308
Topic starter  

Yes. It may not have the exact same level of control, but it can be done that way. You can run it open loop or use the FM for feedback.


ReplyQuote
(@dps1331)
Active Member
Joined: 3 years ago
Posts: 7
 

So the desired flow through the flow meter would be set and a program would modulate the pump to meet the set flow?  Or would I just ramp up or down based on visually observing the flow reading on the screen?


ReplyQuote
(@hemicharger99)
Active Member
Joined: 3 years ago
Posts: 10
 

BrunDog,

Do you have the workspace config file for this? If you are willing to share that.

 

I'm working on a HERMS build and I am trying to make sure I have everything covered before plugging in all the components.


ReplyQuote
(@pbruno3)
Reputable Member Admin
Joined: 4 years ago
Posts: 308
Topic starter  

Hi Hemicharger99,

 

I can send you the config file (note it contains all Workspaces). Unfortunately you would not be able to use it unless your wiring matches mine, since port numbers are not editable in device elements. 

I am happy to share it if you want, though I suspect you would be better with copies of the script above as examples. You can cut/paste these into your scripts and edit from there. Please confirm. I have your email so once you respond will send what you want.


ReplyQuote
(@hemicharger99)
Active Member
Joined: 3 years ago
Posts: 10
 

BrunDog,

 

If you could email them, that would be great. I wouldn't use them for my setup. But just yo give me more of a visual and reference to the configuration itself. Thanks! 


ReplyQuote
(@canmorebrewguy)
Active Member
Joined: 4 years ago
Posts: 15
 

Hello Pete,

I have a few questions on scripting:

  1. Under [setup] you have new values and times, are these variables and how to I write these and connect them to the input boxes on the work space? I have been watching Bryan's you tube videos and I really like how he has it set up to add in volume and times and temps I am not sure on how to get there though.
  2. Will the work spaces communicate with each other of do I have to set that up, the example I will use id Bryan's videos again how he has the brewery display on one work space but all of the data entry on another.

Sorry if these are basic questions but I am very excited to start down the path of automation.

Cheers,

Todd


ReplyQuote
(@pbruno3)
Reputable Member Admin
Joined: 4 years ago
Posts: 308
Topic starter  

Hi Todd,

My first comment is [setup] is not a formal name that is required... it is just a section heading if you want it for whatever reason. It could be called [myfavoritesection]. I use it here for organization. Now 'new value xxx" declares a local number variable to be used in the script. Now to inspect that variable on your workspace, you create a new variable element, and link it to that variable by naming it's script name and variable name in the element's properties.

The workspaces do not "communicate" with each other, but data can be displayed on any workspace. For example, I can have variable elements on two different workspaces that reference variables in the same script. Or device elements on two different workspaces that reference devices on the same interface.

Hope that makes sense!


ReplyQuote
(@diebeerery)
Eminent Member
Joined: 3 years ago
Posts: 25
 

https://www.youtube.com/watch?v=xtqCmhUFApE


ReplyQuote
(@pbruno3)
Reputable Member Admin
Joined: 4 years ago
Posts: 308
Topic starter  

Cool! Well done!


ReplyQuote
(@canmorebrewguy)
Active Member
Joined: 4 years ago
Posts: 15
 

Bryan,

Thank you so much! That really cleared up the process for me, I owe you a beer!

Cheers,

Todd


ReplyQuote
Page 1 / 3
Share: