I am trying to use Arduino as Modbus- RTU slave and Raspberry Pi as a Modbus master I have interfaced Max485 (RS485 to TTL converter) with Arduino and Rs485 to USB converter in Raspberry Pi, Initially, I was able to send data from Arduino to Raspberry Pi, but the data seems to inconsistent and fails to read most times

I am using https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino for Arduino Minimal Modbus for raspberry pi

Connections: DI(max485)- TX ( Arduino), DE(max485) -D4 ( Arduino), RE(max485) - D4( Arduino), Ro(max485) - RX( Arduino), Vcc(max485) -5v( Arduino), Gnd (max485)- GND( Arduino)

code for Arduino

#include <ModbusRtu.h>
uint16_t au16data[6] = {};
Modbus slave(5,0,4); 
void setup() {
  slave.begin(19200,SERIAL_8N1 ); 
void loop() {
  slave.poll( au16data, 6 );

python code

import minimalmodbus
from datetime import datetime
import time

instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 5)
instrument.serial.baudrate = 19200
instrument.serial.bytesize = 8
instrument.serial.parity = minimalmodbus.serial.PARITY_NONE
instrument.serial.stopbits = 1
instrument.serial.timeout =5
instrument.mode = minimalmodbus.MODE_RTU

        val = instrument.read_registers(0,6)
        # Registernumber, number of decimals
        print val
    except IOError:
        error_msg = "Failed to read from device"
        error_time = datetime.now()
        print "IO Error Time",error_time.isoformat(),error_msg 

    except ValueError:
        error_msg = "Failed to read CRC"
        error_time = datetime.now()
        print "Value Error Time",error_time.isoformat(),error_msg

migrated from electronics.stackexchange.com Dec 25 '18 at 4:07

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Sounds like a hardware problem. Show the schematic, and an oscilloscope trace. – CL. Dec 20 '18 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.