modbus rtu arduino raspberry over usb

Hey,

I am trying to learn Modbus, so I have one arduino and raspberry Pi and they are connected via usb (yes without converters). For rpi I’m using pymodbus and for arduino this Google Code Archive - Long-term storage for Google Code Project Hosting.

So I have communication between these two devices, but it seems that data read from raspberry pi is wrong. So for example in the register 10000 arduino writes 100 and RPI reads 1 for example.

Simple code for Arduino,

#include <modbus.h>
#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>

/*
This example code shows a quick and dirty way to get an
arduino to talk to a modbus master device with a
device ID of 1 at 9600 baud.
*/

//Setup the brewtrollers register bank
//All of the data accumulated will be stored here
modbusDevice regBank;
//Create the modbus slave protocol handler
modbusSlave slave;

void setup()
{   

//Assign the modbus device ID.  
 regBank.setId(1);

/*
modbus registers follow the following format
00001-09999  Digital Outputs, A master device can read and write to these registers
10001-19999  Digital Inputs, A master device can only read the values from these registers
30001-39999  Analog Inputs, A master device can only read the values from these registers
40001-49999  Analog Outputs, A master device can read and write to these registers 

Analog values are 16 bit unsigned words stored with a range of 0-32767
Digital values are stored as bytes, a zero value is OFF and any nonzer value is ON

It is best to configure registers of like type into contiguous blocks.  this
allows for more efficient register lookup and and reduces the number of messages
required by the master to retrieve the data
*/

//Add Digital Output registers 00001-00016 to the register bank


//Add Digital Input registers 10001-10008 to the register bank
 regBank.add(10001);  
/*
Assign the modbus device object to the protocol handler
This is where the protocol handler will look to read and write
register data.  Currently, a modbus slave protocol handler may
only have one device assigned to it.
*/
 slave._device = &regBank;  

// Initialize the serial port for coms at 9600 baud  
 slave.setBaud(9600);   
}

void loop()
{
 regBank.set(10001, 100);
while(1)
 {
    slave.run();  
 }
}
and for raspberry;
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.client.async.serial import AsyncModbusSerialClient
from pymodbus.client.async import schedulers
from pymodbus.register_read_message import ReadInputRegistersResponse

client = ModbusClient(method='rtu',port='/dev/ttyACM0',stopbits=1,bytesize=8,parity='N',baudrate=9600,timeout=0.3)
connection = client.connect()
value = client.read_input_registers(10000,1,unit=1)
print(value.registers)
client.close()

So for example in the register 10000 arduino writes 100 and RPI reads 1 for example.

In your code the Arduino doesn't have a register 10000. If you use different register numbers on the two devices I'm not surprised it doesn't work.