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 library on LoPy : no data received from slave

    Scheduled Pinned Locked Moved LoPy
    lopymodbus
    13 Posts 5 Posters 3.2k Views 5 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
      timh @SameerChouksey
      last edited by

      @sameerchouksey

      Hi this might be a silly question, but most MODBUS RTU devices are serial RS323 or RS485. I personally haven't seen any industrial modbus devices that use TTL.

      I am pretty sure the serial UART on the ESP32 is TTL so it won't work with any RS232/RS485 devices with out something like a MAX3232

      Cheers

      Tim

      L 1 Reply Last reply Reply Quote 2
      • L Offline
        livius @timh
        last edited by

        @timh
        Yes, it is TTL only.

        @SameerChouksey
        you must use converter e.g. SN65HVD230 - direct connection can brake your device as it is 3V3 levels device only.

        think about people first, then computers

        1 Reply Last reply Reply Quote 0
        • S Offline
          SameerChouksey
          last edited by

          Hello,

          Thanks for your prompt response. Yes, the device supports RS485 and I am using a Rs485 to TTL converter between PyCom board and the ModBus slave. Still getting same error.

          Regards,
          Sameer

          T 1 Reply Last reply Reply Quote 0
          • T Offline
            timh @SameerChouksey
            last edited by

            @sameerchouksey have you tried using TTL and a different library on something like a raspberry pi ?

            One of things we have had issues with various serial modbus adaptors is the timeout for the read is too short, which typically gives you OSError: no data received from slave. For instance an ATLAS COPCO engine controller I couldn't get to work using modbus_tk, but could with PyModbus due to the way modbus_tk was handling serial timeouts (and I didn't then want to spend time debugging modbus_tk ;-)

            The other obvious things are checking comms details and slave address which will also generally give you the same error.
            You code example isn't showing baud etc...

            T

            1 Reply Last reply Reply Quote 0
            • Charly86C Offline
              Charly86
              last edited by

              You can use something like that

              0_1521332539702_Capture.JPG

              Search for "XY-017 RS485" in google you'll find it everywhere starting less than $2 (on ebay for example)

              1 Reply Last reply Reply Quote 0
              • S Offline
                SameerChouksey
                last edited by SameerChouksey

                Thanks for the support. I am able to read it with a potential divider circuit.

                One query, how many registers can I read in one single call?? I am setting up register_quantity=10, but still I am able to read only one register at a time.

                Regards
                Sameer

                T 1 Reply Last reply Reply Quote 0
                • T Offline
                  timh @SameerChouksey
                  last edited by

                  @sameerchouksey

                  Oh I didn't know you could read a single register. That information missing from you post above.

                  Have you checked that the contiguous register range is valid (ie no holes).

                  We talk to a number of devices that have large holes in the register range . We can read multiple registers if we avoid the holes. ie registers 50 to 100 (decimal) might have two unused registers at 68 & 69. So we can't read from address 50 for a length of 50. We have read start register 50, length of 27, then from 70 with a length of 30.

                  Can you read 2 adjacent registers or are you limited to a single register?

                  Tim

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    SameerChouksey @timh
                    last edited by

                    @timh I tried reading 2 adjacent registers. But getting only one value.

                    There is no hole between two registers. You can see in the screenshot that I first reading register address 0x110 with register count as 2. And then I am reading register address 0x111. In the second call I can read the second register.

                    Please check the screenshot.

                    0_1521445988223_520b1af9-a056-4682-b7f5-0a4a48bf2d54-image.png

                    T 1 Reply Last reply Reply Quote 0
                    • T Offline
                      timh @SameerChouksey
                      last edited by

                      @sameerchouksey have you confirmed you can read multiple registers from this device using some other software/hardware other than pycom ?

                      T

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        SameerChouksey @timh
                        last edited by

                        @timh Yes. I have used Modbus Poll simulator and I can read 10 registers there.

                        Regards
                        Sameer

                        T 1 Reply Last reply Reply Quote 0
                        • T Offline
                          timh @SameerChouksey
                          last edited by

                          @sameerchouksey this might be a long shot, but I would try using the original micropython modbus code.
                          The pycom modbus code is different and adds the signed option. (which I find strange because endianess is not a given in modbus (ie not defined) so can vary from platform to platform) which would be required to correctly interpret signed values. The original doesn't include this extra code.

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            jant
                            last edited by

                            Hello,
                            I'm working on a modbus project using the pycom controller to read a few input registers. But there I get the same error as you Sameer and I'm not able to make the code run correctly.
                            What did you do that the code work?

                            Regards,
                            Jan

                            current code:
                            ######################### RTU SERIAL MODBUS #########################
                            uart_id = 0x01
                            modbus_obj = Serial(uart_id, pins=('P3', 'P4'))

                            ###################### READ INPUT REGISTERS ##################
                            slave_addr=0x01
                            starting_address=0x04
                            register_quantity=2
                            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))

                            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