Extending the capabilities of Samovar with the additional I2CStepper board with a stepper motor and four relays.
The module can be used as a standalone device. It can be controlled on its own with the menu on a 16x2 LCD screen and an encoder, or while connected to Samovar.
The expander is connected to Samovar over the I2C bus with four wires (like the LCD screen). Samovar detects that the expander is connected and can control it.
Samovar 7.00: the firmware works with the boards using protocol version 3. Up to ten boards with I2C addresses from 1 to 10 can be on the bus: boards with an odd address (1, 3, 5…) are stirrers, boards with an even address (2, 4, 6…) are pumps (continuous pumping or filling a set volume). Each board tells Samovar what it can do: stirrer, pumping, filling, relays, external sensor. The boards are searched for when Samovar starts and are then polled in the background; if at least one is found, an "I2CStepper" button appears on the main page of every mode and opens the board control page. A board that has once responded on the bus stays in the list until Samovar is rebooted; if communication with it is lost, it is marked as unavailable.
During operation (rectification program, Lua, Beer and Cheese modes) Samovar uses one working stirrer and one working pump — the boards with the lowest address among those found. They are fixed when the process starts and do not change until it ends, even if a board with a lower address appears during the run.
In Beer mode the first relay is used to switch the wort transfer pump on and off (for example, to circulate the wort in the brew kettle). The firmware does not use the other relays — you decide what they do, and you can switch them from Lua. The relays are served by the working stirrer if it has declared relay support, otherwise by the working pump.
The board settings themselves (mode, speed, stirrer run time and pause, pump flow, fill volume and rate, steps per milliliter) are stored in the Nano memory and edited on the Settings → I2CStepper tab («Настройки → I2CStepper»), see below. The "I2CStepper" page is used only for manual start and stop.
The "I2CStepper" page
The "I2CStepper" page: the pump board with address 2 is selected
 Device («Устройство»)
The list of boards found on the bus; shown if there are two or more boards. Stirrers have an odd address, pumps an even one.
|
 Board state
"Running" («Работает») or "Stopped" («Остановлен»); below it are the current pump speed and the remaining volume.
|
 Speed and volume
Pump speed in liters per hour and volume in milliliters for the "Run" («Запустить») button. "Stop" («Стоп») stops the pump.
|
 Relay 1
Shown if the board supports relays; switches the first relay of the board.
|
 External pump calibration
Only for pump boards: opens the "Steps/mL" («Шагов/мл») calibration page for the selected board.
|
If two or more boards are found, a "Device" («Устройство») list appears at the top — use it to choose the board you work with: "Stirrer, address N" («Мешалка, адрес N») or "Pump, address N" («Насос, адрес N»). With a single board the list is hidden. If the selected board is unavailable, the message "The selected I2CStepper is unavailable" («Выбранный I2CStepper недоступен») is shown instead of the panel — another board is not substituted automatically, you have to choose it in the list.
For the selected board the page shows its type and address, its state ("Running" («Работает») or "Stopped" («Остановлен»)), the current speed in steps per second and how many steps are left before it stops. The data is refreshed every two seconds.
Control. "Speed" («Скорость») is the motor speed in steps per second (from 1 to 18000), "Target, steps" («Цель, шагов») is how many steps to make. The "Run" («Запустить») button sends these two values to the board and starts the motor in the mode stored in the Nano memory: for a stirrer it is rotation, for a pump it is filling with the given number of steps. For a pump it is easier to calculate the number of steps from the volume: multiply the required milliliters by "Steps/mL" («Шагов/мл») from the Nano settings. "Stop" («Стоп») stops the motor. The start is impossible if the pump is not calibrated ("Steps/mL" is zero) or Samovar is switching its mode at that moment — an error message is shown then.
Relays. If the board has declared relay support, a "Turn relay 1 on" («Включить реле 1») / "Turn relay 1 off" («Выключить реле 1») button is shown — it switches the first relay of the board (in Beer mode this is the wort pump). Relays 2–4 cannot be switched from this page, only from Lua.
External pump calibration. The button is available only for pump boards that support filling. It opens the calibration page for the selected board: prepare a measuring container, set the motor speed and press "Start calibration" («Начать калибровку») — the pump starts pumping. When exactly 100 mL has been collected, press "Set 100 mL" («Зафиксировать 100 мл»): Samovar calculates "Steps/mL" and writes the value to the Nano memory. Repeat the calibration after changing the driver microsteps, the motor, the pump head or the tubing.
Samovar settings
Settings → I2CStepper. The "Nano I2CStepper settings" («Настройки Nano I2CStepper») tab shows the settings stored in the memory of the board itself. The "Rescan I2C devices" («Пересканировать I2C-устройства») button searches the bus for boards again (for example, after connecting a new one). If there are several boards, choose the one you need in the "Device" list. Fields:
"New address" («Новый адрес») — the board address on the bus, from 1 to 10. An odd address makes the board a stirrer, an even one makes it a pump; an address that is already taken cannot be chosen. The new address takes effect after the Nano is rebooted.
"Mode" («Режим») — "Stirrer" («Мешалка», odd address only), "Pump" («Насос») or "Fill" («Наполнение», even address only). The board works in this mode when you press "Run" and on commands from Lua and the apps.
"Steps/mL" — the pump calibration coefficient: it is used to convert milliliters and liters per hour into motor steps. It is filled in by calibration (see above) or manually. While it is zero, the pump cannot be started.
"Stirrer speed" («Обороты мешалки»), "Stirrer run time, s" («Работа мешалки, с»), "Stirrer pause, s" («Пауза мешалки, с») — the stirrer parameters for standalone operation of the board; with a pause of 0 the stirrer runs continuously.
"Pump flow, mL/h" («Подача насоса, мл/ч») and "Pump pause, s" («Пауза насоса, с») — for the "Pump" mode (continuous pumping); "Fill volume, mL" («Объём наполнения, мл») and "Fill rate, mL/h" («Скорость наполнения, мл/ч») — for the "Fill" mode.
The "Save to Nano" («Сохранить в Nano») button writes the fields to the non-volatile memory of the board; they survive a restart of both Samovar and the board.
Settings → Pump («Настройки → Насос»). If an I2C pump is found, two fields for rectification appear on the tab:
"Use I2C pump above the pasteurization section" («Использовать I2C-насос над ЦП») — the pump takes part in rectification if it was detected when Samovar started: during heads take-off it becomes the main pump, during hearts and pre-flooding it works together with the local pump.
"Take-off rate above the pasteurization section" («Скорость отбора над ЦП») — the constant speed of the I2C pump on hearts lines B and pre-flooding lines C. On heads line H the speed of the program line itself is used.
The speed in liters per hour for this pump is converted into steps using "Steps/mL" from the Nano memory; the separate "I2C pump steps count" («Количество шагов I2C насоса») field no longer exists in the Samovar settings.
Mobile apps and website
The Samovar apps and the Samovar control page on the samovar-tool.ru website receive the list of boards and their state (availability, mode, speed, remaining amount, relay mask) every five seconds and let you start and stop a board and switch the relays. The Nano settings and calibration are not available through the apps — only through the Samovar web interface. If a command is rejected, the reason arrives in the Samovar messages in the form "Blynk V37 a=N: code" («Blynk V37 a=N: код»).
Diagram and wiring
Wiring diagram
Pinout for connecting peripherals:
// Pins for I2C Master - connecting the screen and potentially other devices
// SDA_PIN 0 //A0
// SCL_PIN 2 //D2
// Pins for I2C Slave - communication with Samovar
// SDA_PIN A4
// SCL_PIN A5
// Pins for the stepper motor
#define STEPPER_STEP 3
#define STEPPER_DIR 4
#define STEPPER_EN 5
//Pins for the relays
#define MIXER_PUMP_PIN 13 // RELE_PIN1
#define RELE_PIN2 10 // RELE_PIN2
#define RELE_PIN3 11 // RELE_PIN3
#define RELE_PIN4 12 // RELE_PIN4
// Pins for the encoder
#define ENC_CLK 7 //S2
#define ENC_DT 8 //S1
#define ENC_SW 9 //KEY
Tip.
If you plan to use the expander as a separate device in its own enclosure, it makes sense to connect it to Samovar with a USB A-B cable (computer - printer). The module power (+/- 5 volts) and the two I2C bus signals are taken directly from the Samovar display. A USB-B connector is mounted on the Samovar enclosure.
A USB-A connector is mounted on the expander enclosure.
This way, when connected to Samovar, the Arduino Nano gets both power and the I2C bus at the same time. When used as a standalone device, a separate power supply is used instead of Samovar, for example a phone charger.
When a built-in power supply is used, a USB-B connector is fitted to the power supply output, and the same USB A-B cable is used to deliver power, which rules out accidentally feeding +5 volts into Samovar.
Peripherals.
The relay block is used at 5 volts, preferably with optocoupler control. You can also use 12-volt relays, wired the same way as in Samovar.
Any pump can be used: a DC motor or an AC single-phase or three-phase one. The pump motor is started and stopped through a relay and then through any power switch: a contactor or a solid-state relay. For small volumes, consider the 15RM magnetic-drive pump. Stainless steel, quiet, with good flow.
For the stirrer or the NBK, any bipolar stepper motor can be used, provided it has enough power and torque. A Nema 23 with a matching driver is recommended.
The current sketch for the Arduino Nano that controls the stepper motor and the four relays can be downloaded from this link . You need the version with protocol v3; when moving from protocol v2 the board memory is initialized anew — check the address, the mode and "Steps/mL" again. Its main purpose is to be used together with Samovar as an expansion module. You must use the libraries supplied with Samovar.
Control from Lua
The functions are available when the firmware is built with Lua (see
About the Lua scripting language). The stirrer functions work with the working stirrer, the pump functions with the working pump (the boards with the lowest address, see above). All start functions return 1 if the command was accepted by the board and 0 if not — including when the required board is not on the bus.
set_stepper_by_time(spd, direction, time) – start the stirrer: spd – speed in steps per second, direction – direction 0 or 1, time – run time in seconds. With time = 0 the stirrer rotates continuously until a stop command, spd = 0 stops the stirrer.
set_stepper_target(spd, direction, target) – start the pump in fill mode: spd – speed in steps per second (up to 18000), direction – direction 0 or 1, target – number of steps. With spd = 0 or target = 0 the pump stops. The function does not control the standard Samovar stepper motor.
get_stepper_status() – how many steps the pump still has to make (0 – it is stopped or there is no board).
i2cpump_start(rate, volume) – pump volume mL at rate L/h, converted to steps using "Steps/mL" from the Nano memory. Returns 0 if the pump board is not connected, not calibrated or the arguments are invalid.
i2cpump_stop() – stop the pump.
i2cpump_get_speed() – current pump speed in steps per second.
i2cpump_get_target_ml() – the volume set by the last i2cpump_start command, mL.
i2cpump_get_remaining_ml() – how much is left to pump, mL.
i2cpump_get_running() – 1 if the pump is running, otherwise 0.
set_mixer_pump_target(Val) – switch the first relay – the wort pump – on (1) or off (0).
get_mixer_pump_status() – state of the first relay: 0 or 1; 255 if there is no board with relays.
set_i2c_rele_state(Num, Val) – switch relay Num (1–4) on (1) or off (0). Returns 1 if the command was executed.
get_i2c_rele_state(Num) – state of relay Num (1–4): 0 or 1; 255 if there is no board with relays.
check_I2C_device(Addr) – check whether the device with address Addr responds on the I2C bus; returns the address if the device is found.
Attention. The relays are served by the working stirrer if it has declared relay support; otherwise by the working pump. Functions that change the state are not executed in Lua simulation mode and while Samovar is switching its mode.
Example: set_stepper_by_time(800, 0, 0) – rotate the stirrer continuously at 800 steps per second; set_stepper_by_time(0, 0, 0) – stop it. i2cpump_start(6, 250) – pump 250 mL at 6 L/h; while i2cpump_get_running() == 1, the pump is running.