Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
/**
* General Config Options
*/
#define CO2_PURGE_PERIOD 2000
#define CO2_PRE_PURGE_PERIOD 2000
#define MOVE_BEER_BELT_PERIOD 5000
#define FILLER_TUBE_MOVEMENT_DELAY 2000
#define CO2_PURGE_RETRACTION_DELAY 1000
#define CO2_PURGE_RETRACTION_PERIOD 500
#define CO2_POST_PURGE_DELAY 1000
#define CO2_POST_PURGE_PERIOD 500
#define FILL_SENSORS_TIMER_FREQUENCY 100000 // 100ms This value needs to be defined in microseconds.
#define FILL_SENSORS_TRIGGER 400 // Int between 0 and 1023 used to trigger the fill sensor: operating voltage(5v or 3.3v) / 1024
#define FILL_SENSOR_TRIGGER 400 // Ints between 0 and 1023 used to trigger the fill sensor: operating voltage(5v or 3.3v) / 1024

/**
* Feature flags
*/
//#define CONINUOUS_FILLING // Uncomment this to have the filling process repeat for new batch after the current batch has completed it filling.
//#define CONTINUOUS_FILLING // Uncomment this to have the filling process repeat for new batch after the current batch has completed it filling.
17 changes: 10 additions & 7 deletions InputConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
/**
* Pin definitions
*/
#define START_BUTTON 8
#define BEER_INLET_SOL_1 5
#define BEER_INLET_SOL_2 6
#define BEER_INLET_SOL_3 7
#define START_BUTTON 10
#define BEER_INLET_SOL_1 7
#define BEER_INLET_SOL_2 8
#define BEER_INLET_SOL_3 9
#define BEER_FILL_SENSOR_1 A0
#define BEER_FILL_SENSOR_2 A1
#define BEER_FILL_SENSOR_3 A2
#define CO2_PURGE_SOL 4
#define FILL_RAIL_SOL 3
#define BEER_BELT_SOL 2
#define CO2_PURGE_SOL 6
#define FILL_RAIL_SOL 5
#define BEER_BELT_SOL 4
#define ROT_ENC_A 2
#define ROT_ENC_B 3
#define ROT_ENC_BUTTON 12
91 changes: 58 additions & 33 deletions OpenBeerFiller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
// Project specific includes.
#include "Config.h";
#include "InputConfig.h";
#include "ReprapLCD.h"
#include "Settings.h"

/**
* ***************************************************************************
Expand All @@ -39,8 +41,10 @@ volatile bool fillSensor1Triggered = false;
volatile bool fillSensor2Triggered = false;
volatile bool fillSensor3Triggered = false;
bool idleMessageDisplayed = false;
enum ProgramState {UNDEF,IDLE,START,FILLING,STOP};
enum ProgramState {UNDEF, IDLE, START, PRE_PURGE, FILLING, POST_PURGE, STOP};
char ProgramStateText[][8] = {"UNDEF", "Idle", "Feeding", "Purging", "Filling", "Purging", "Stop"};
ProgramState currentState = UNDEF;
int cansFilled = 0;

/**
* ***************************************************************************
Expand Down Expand Up @@ -83,13 +87,13 @@ void setupFillSensorsTimer() {
* Check if the fill sensors have been triggered.
*/
void checkFillSensors() {
if (FILL_SENSORS_TRIGGER < analogRead(BEER_FILL_SENSOR_1)) {
if (EEPROM16_Read(EEPROM_FILL_SENSOR_TRIGGER) < analogRead(BEER_FILL_SENSOR_1)) {
triggerFullFillSensor1();
}
if (FILL_SENSORS_TRIGGER < analogRead(BEER_FILL_SENSOR_2)) {
if (EEPROM16_Read(EEPROM_FILL_SENSOR_TRIGGER) < analogRead(BEER_FILL_SENSOR_2)) {
triggerFullFillSensor2();
}
if (FILL_SENSORS_TRIGGER < analogRead(BEER_FILL_SENSOR_3)) {
if (EEPROM16_Read(EEPROM_FILL_SENSOR_TRIGGER) < analogRead(BEER_FILL_SENSOR_3)) {
triggerFullFillSensor3();
}
}
Expand Down Expand Up @@ -172,27 +176,13 @@ void closeAllBeerFillerTubes() {
digitalWrite(BEER_INLET_SOL_3, LOW);
}

/**
* Open the CO2 purge solenoid, wait a while and then close it again.
*/
void purgeCO2( bool retract = false ) {
Serial.println("Purging CO2");
digitalWrite(CO2_PURGE_SOL, HIGH);
if(!retract) {
delay(CO2_PURGE_PERIOD);
} else {
delay(CO2_PURGE_RETRACTION_PERIOD);
}
digitalWrite(CO2_PURGE_SOL, LOW);
}

/**
* Raise the fillter tubes out of the bottles.
*/
void raiseFillerTubes() {
Serial.println("Raising filler tubes");
digitalWrite(FILL_RAIL_SOL, HIGH);
delay(CO2_PURGE_RETRACTION_DELAY); // We use CO2_PURGE_RETRACTION_DELAY here as we want to start purging with CO2 as the fill rail raises.
delay(EEPROM16_Read(EEPROM_CO2_POST_PURGE_DELAY)); // We use CO2_POST_PURGE_DELAY here as we want to start purging with CO2 as the fill rail raises.
}

/**
Expand All @@ -201,7 +191,7 @@ void raiseFillerTubes() {
void lowerFillerTubes() {
Serial.println("Lowering filler tubes");
digitalWrite(FILL_RAIL_SOL, LOW);
delay(FILLER_TUBE_MOVEMENT_DELAY);
delay(EEPROM16_Read(EEPROM_FILLER_TUBE_MOVEMENT_DELAY));
}

/**
Expand All @@ -210,7 +200,7 @@ void lowerFillerTubes() {
void moveBeerBelt() {
Serial.println( "Moving beer belt" );
digitalWrite(BEER_BELT_SOL, HIGH);
delay(MOVE_BEER_BELT_PERIOD);
delay(EEPROM16_Read(EEPROM_MOVE_BEER_BELT_PERIOD));
digitalWrite(BEER_BELT_SOL, LOW);
}

Expand All @@ -231,7 +221,17 @@ void idleState() {
void startState() {
moveBeerBelt();
lowerFillerTubes();
purgeCO2();
changeProgramState(PRE_PURGE);
}

/**
* Code to run when we are in the PRE_PURGE ProgramState.
*/
void prePurgeState() {
Serial.println("Purging CO2");
digitalWrite(CO2_PURGE_SOL, HIGH);
delay(EEPROM_CO2_PRE_PURGE_PERIOD);
digitalWrite(CO2_PURGE_SOL, LOW);
openAllBeerFillerTubes();
changeProgramState(FILLING);
}
Expand All @@ -242,16 +242,31 @@ void startState() {
void fillingState() {
// Check if we are done filling.
if(allFillSensorsTriggered()){
cansFilled++;
raiseFillerTubes();
purgeCO2(true);
resetFillSensorTriggers();
// If done filling, check if we want to do continuous filling or go back to the UNDEF state.
#if defined(CONINUOUS_FILLING)
changeProgramState(START);
#else
changeProgramState(IDLE);
#endif;
changeProgramState(POST_PURGE);
}
}

/**
* Code to run when we are in the POST_PURGE ProgramState.
*/
void postPurgeState() {
if(CO2_POST_PURGE_PERIOD) {
Serial.println("Purging CO2");
digitalWrite(CO2_PURGE_SOL, HIGH);
delay(EEPROM16_Read(EEPROM_CO2_POST_PURGE_PERIOD));
digitalWrite(CO2_PURGE_SOL, LOW);
}

resetFillSensorTriggers();

// If done filling, check if we want to do continuous filling or go back to the UNDEF state.
#if defined(CONTINUOUS_FILLING)
changeProgramState(START);
#else
changeProgramState(IDLE);
#endif;
}

/**
Expand All @@ -268,7 +283,7 @@ void stopState() {
*/
void readStartButton() {
if(
HIGH==digitalRead(START_BUTTON)
LOW==digitalRead(START_BUTTON)
&& hasProgramState(IDLE)
) {
Serial.println("Start Button Pressed");
Expand All @@ -281,7 +296,7 @@ void readStartButton() {
*/
void readStopButton() {
if(
HIGH==digitalRead(START_BUTTON)
LOW==digitalRead(START_BUTTON)
&& !hasProgramState(IDLE)
&& !hasProgramState(START)
) {
Expand Down Expand Up @@ -313,7 +328,7 @@ void changeProgramState(ProgramState state) {
}
currentState = state;
Serial.print("Program state changed: ");
Serial.println(currentState);
Serial.println(ProgramStateText[currentState]);
}

/**
Expand All @@ -331,6 +346,8 @@ bool hasProgramState(ProgramState state) {
*/
void alwaysRun() {
readStopButton();
rotEncRead();
showDisplay(ProgramStateText[currentState], cansFilled);
}

/**
Expand All @@ -344,6 +361,8 @@ void alwaysRun() {
*/
void setup() {
Serial.begin(115200);//Serial.begin(9600);
firstRunSettings();
setupLCD();
setupPins();
setupFillSensorsTimer();
resetUnit();
Expand All @@ -360,9 +379,15 @@ void loop() {
case START:
startState();
break;
case PRE_PURGE:
prePurgeState();
break;
case FILLING:
fillingState();
break;
case POST_PURGE:
postPurgeState();
break;
case STOP:
stopState();
break;
Expand Down
Loading