Write to the Input Registers.


node1.writeInputRegister(address, value)
node2.writeInputRegister(address, size, buffer)


  • node1/node2: ModbusSlaveNode object.
  • address: The address of the Input Registers to write to.
  • value: The value of the single Input Registers that you want to write to.
  • size: The number of plural Input Registers you want to write to.
  • buffer: Copy the data of the array in the array space pointed to by the buffer to the Input Registers.


int: If it succeeds, send back MODBUS_SUCCESS, and vice versa send back EXCEPTION_CODE.


#include <Modbus86.h>
ModbusSlave bus;
ModbusSlaveNode node;
uint8_t read_input_registers(   uint8_t function,
                                uint16_t address,
                                uint16_t length)
    int sensorPin = A2;
    if (address <= 2 && address + length > 2)
        node.writeInputRegister(2, analogRead(sensorPin));
    return MODBUS_SUCCESS;
void setup()
    /* Modbus RTU Mode via RS485. */
    bus.begin(MODBUS_RTU, Serial485);
    /* Slave node with ID 11. */
    node.attach(11, bus);
    /* Set the callback function of Read Input Registers (0x04). */
                            = read_input_registers;
void loop()

Libraries Reference Home

The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top