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.
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. Boards are searched for once when Samovar starts; only discovered boards are then polled in the background. After connecting a new board or changing its address, press "Rescan I2C devices" («Пересканировать I2C-устройства») in the settings. If at least one board is available, an "I2CStepper" button appears on the main page of every mode. A previously discovered board stays in the list until Samovar reboots; if communication 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, relay 1 switches the wort transfer pump on and off (for example, to circulate wort in the kettle). The firmware does not occupy the other relays; you choose their purpose and can switch them from the I2CStepper page and Lua. Relay functions use the working stirrer if it supports relays, otherwise the working pump.
The board settings (mode, speed, stirrer run time and pause, pump flow, fill volume and rate, steps per milliliter) are stored in Nano memory and edited on the Settings → I2CStepper tab («Настройки → I2CStepper»), see below. The "I2CStepper" page lets you start and stop the motor, change its speed and direction, switch relays and open pump calibration.
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 l/h, direction and volume in ml. "Apply speed" («Применить скорость») changes the speed of a running pump; "Stop" («Стоп») stops it.
|
 Relays 1–4
Four buttons switch relays 1–4 of the selected board on and off; shown if the board supports relays.
|
 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, reopen the page from the main page to select an available board, or use the "Device" («Устройство») list.
The selected board shows its type and address, state ("Running" («Работает») or "Stopped" («Остановлен»)), direction and current speed: rpm for a stirrer, l/h for a pump. The pump also shows the remaining volume in ml. Data is refreshed every two seconds.
Control. For a stirrer, enter "Speed, rpm" («Скорость, об/мин»); for a pump, enter "Speed, l/h" («Скорость, л/ч») and, for a metered dose, "Volume, ml" («Объём, мл»). Leave the volume empty for continuous pumping; for a running pump, enter the remaining volume. Select "Direction" («Направление») and press "Run" («Запустить») or "Apply speed" («Применить скорость»). If the drive belongs to a process, the program sets the volume, while the new speed and direction replace the program values. During an NBK session, change the working pump speed on the NBK page. "Stop" («Стоп») stops the drive; for a stirrer stopped manually during a process, "Return control to the program" («Вернуть управление программе») restores schedule control. A pump with zero steps per milliliter cannot start.
Relays. If the board supports relays, the page has four "Turn relay N on" («Включить реле N») / "Turn relay N off" («Выключить реле N») buttons (N is 1–4). In Beer mode, relay 1 of the working board serves the wort transfer pump. All four relays are also accessible 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:
"Address on the I2C bus" («Адрес на шине I2C») is 1–10. An odd address makes the board a stirrer, an even one a pump; an occupied address cannot be selected. After saving a new address, reboot the Nano and press "Rescan I2C devices" («Пересканировать I2C-устройства») once: the settings will select the board at its new address.
"What the pump does" («Что делает насос») offers "Continuous feed" («Постоянная подача») or "Fill a volume" («Наполнение объёма»); the field appears only for an even address. An odd address automatically selects stirrer mode. These settings define standalone Nano operation; Samovar commands may specify their own mode and parameters.
"Motor steps per 1 ml" («Шагов мотора на 1 мл») is the pump calibration factor used to convert milliliters and liters per hour into motor steps. Fill it by calibration (see above) or manually. A zero value prevents pump start.
"Speed, rpm" («Скорость, об/мин»), "Run, s" («Работа, с») and "Pause, s" («Пауза, с») are the stirrer settings for standalone board operation. A run time of 0 means continuous rotation. With a nonzero run time and a pause of 0, it runs one cycle and stops; a nonzero pause repeats the cycles.
"Feed rate, ml/h" («Скорость подачи, мл/ч») sets continuous feed; "Volume, ml" («Объём, мл») and "Rate, ml/h" («Скорость, мл/ч») set filling of a specified volume. "Smooth acceleration and braking" («Плавный разгон и торможение») enables gradual speed changes at start and stop.
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.
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 . Protocol v3 is required. After flashing the Nano, check the address, mode and "Motor steps per 1 ml" («Шагов мотора на 1 мл»). Its main purpose is use with Samovar as an expansion module. 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(rpm, direction, time) – start the stirrer: rpm – speed in revolutions per minute (the Nano checks the allowed speed), direction – direction 0 or 1, time – run time in seconds. With time = 0 the stirrer rotates continuously until a stop command, rpm = 0 stops the stirrer. If the stirrer speed or direction is set manually on the "I2CStepper" page, it overrides the values passed from the script.
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(60, 0, 0) – rotate the stirrer continuously at 60 rpm; 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.