Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Modbus on Fipy returning not values but request

    Scheduled Pinned Locked Moved MicroPython
    4 Posts 2 Posters 30 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      Tautvydas Bujauskas
      last edited by

      Hi,

      I am trying to get readings form modbus device. but no matter what i tired i have same results.
      This is my code:

      from uModBus.serial import Serial
      import machine
      
      ######################### RTU SERIAL MODBUS #########################
      uart_id = 0x01
      modbus_obj = Serial(uart_id, pins=('P9', 'P10'))
      # if the serial modbus requires a ctrl pin, you can set it like this:
      # modbus_obj = Serial(uart_id, pins=('P9','P10'), ctrl_pin='P8')
      
      # baudrate=115200, data_bits=8, stop_bits=1, parity=None
      ###################### READ INPUT REGISTERS ##################
      slave_addr=0x01
      starting_address=0x06
      register_quantity=1
      signed=True
      
      register_value = modbus_obj.read_input_registers(slave_addr, starting_address, register_quantity, signed)
      print('Input register value: ' + ' '.join('{:d}'.format(x) for x in register_value))
      
      

      in serial module I added few print statements and get these results:

      Send to device:
       bytearray(b'\x01\x04\x00\x06\x00\x01\xd1\xcb')
      UART response:
       bytearray(b'\x01\x04\x00\x06\x00\x01\xd1\xcb')
      Input register value: 1536
      

      I know that response is the same like request, and value that is read is 06 00 (hex) is 1536 decimal

      sensor that shouldrespond with value is working and if I make a request to it i get:

      TX: 01 04 00 06 00 01 D1 CB
      RX: 01 04 02 01 96 38 CE
      

      value is 01 96(hex) wich is 406 and that is correct.

      Maybe somebode had the same problem?

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @Tautvydas Bujauskas
        last edited by

        @Tautvydas-Bujauskas have you tried using the same device to another host to see how it behaves there? Connecting it to your PC for instance.

        Also can you give more details about the device and how you connected it to the FiPy?

        Finally, can you tell us where you got the umodbus library from?

        1 Reply Last reply Reply Quote 0
        • T Offline
          Tautvydas Bujauskas
          last edited by

          @jcaron no I haven't tried to connect to another host Fipy device since in should be a master on modbus.

          I connected A and B of modbus pins to pytrack 2.0 external pins P9 and P10. And after more research i think this is a problem, since i need RS485 to UART converter to use... as most of the forums says...

          I downloaded library from pycom repo https://github.com/pycom/pycom-modbus bu it needs a little bit of adjusment since readall() function is deprecated and need to be changed do read().

          T 1 Reply Last reply Reply Quote 0
          • T Offline
            Tautvydas Bujauskas @Tautvydas Bujauskas
            last edited by

            So I was right, when i connected over UART to RS485 converter everything is working fine.

            This shloud be mentioned in docs, that you need to use RS485 converter and not to try connecting directly.

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom