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

    UART - send and receive data

    Scheduled Pinned Locked Moved FiPy
    6 Posts 3 Posters 289 Views 3 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.
    • F Offline
      fellowes22
      last edited by

      Hello together

      I have a question regarding UART at FiPy. In the future the FiPy will be integrated into a gateway. The data comes via UART (P3 / P4) from the Gateway. To test this with the Expansion Board, I wrote the following code:

          uart = UART(0, baudrate=115200, timeout_chars=1200) // PIN P3 & P4
          uart.init(115200, bits=8, parity=None, stop=1)
          writtenstr = uart.write('HELLO')
          print('\nWRITTEN: ' + str(writtenstr))
          s = uart.read(5)
          print('\nREAD: ' + str(s))
      

      This is the output:

      HELLO
      WRITTEN: 5
      READ: None
      

      The gateway sends for example "Hello" to the Fipy. Why is uart.readany() null and why do I get None as result of uart.read()?

      robert-hhR J 2 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @fellowes22
        last edited by

        @fellowes22 try UART(1, ..)
        UART0 is connected to P0 and P1 and used for REPL.

        1 Reply Last reply Reply Quote 0
        • F Offline
          fellowes22
          last edited by

          I also tried this. This is the result:

          WRITTEN: 5
          READ: None
          uart.any --> 0
          
          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @fellowes22
            last edited by

            @fellowes22 try to swap rx and tx

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

              @fellowes22 To test the code independently of the connection with your gateway, just connect RX to TX to see if you receive back what you send.

              Note that here, you would receive something only if the gateway sends any data within one tenth of a second of the script being started (you set the timeout to 1200 chars, which at 115200 bits/s is about 0.1 s). If this is not the case, there are 0 characters available in the buffer (any will return 0) and readwill timeout and return None.

              You probably want to add a loop after you open the connection to wait for data to come in.

              Other possible issues may include:

              • swapped RX/TX as suggested by @robert-hh
              • levels (3.3V / 5V)
              • flow-control mismatch
              • speed/bits/parity settings mismatch
              • the gateway may wait for a specific command before it sends back anything
              F 1 Reply Last reply Reply Quote 1
              • F Offline
                fellowes22 @jcaron
                last edited by

                @jcaron @robert-hh Thank you guys. It works right now. The problem was RX and TX. I swap them, it works right now.

                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