Download PDF
        SAMOVAR 
×
Menu

I2CStepper

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
1

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.
 
2

Board state

"Running" («Работает») or "Stopped" («Остановлен»); below it are the current pump speed and the remaining volume.
 
3

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.
 
4

Relays 1–4

Four buttons switch relays 1–4 of the selected board on and off; shown if the board supports relays.
 
5

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:
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:
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.
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.