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 Reading Problem

    Scheduled Pinned Locked Moved FiPy
    12 Posts 4 Posters 203 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.
    • J Offline
      jcaron @Christian Storm
      last edited by

      @Christian-Storm what kind of data is it? ASCII text? UTF-8 text? Binary?

      I’m not sure I understand what you are doing with decode and str (and of course rstrip)…

      C 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Christian Storm
        last edited by

        @Christian-Storm readline reads data up to a newline or up to a timeout, whatever occurs first. Try to increase the timeout.

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          Christian Storm @jcaron
          last edited by

          Hey @jcaron, data is ASCII, but uart read return bytes. Thats why I use decode.

          1 Reply Last reply Reply Quote 0
          • C Offline
            Christian Storm @robert-hh
            last edited by

            Hey @robert-hh, I did try increase timeout_chars up to 255. But than I miss more bytes. Even if I use uart.readline or uart.read

            1 Reply Last reply Reply Quote 0
            • C Offline
              Christian Storm
              last edited by

              For me it looks like, that these posts:
              https://forum.pycom.io/topic/2595/uart-rx-buffer-issue-after-buffer-overflow
              https://forum.pycom.io/topic/6228/uart-readline-not-working-reliably-for-long-strings
              are still unsolved. Well, in the meantime I found an other solution

              robert-hhR S 2 Replies Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @Christian Storm
                last edited by

                @Christian-Storm That's true. There seem to be no interest at Pycom to fix bugs, even if the fix is trivial. For a while I supplied PRs for bug fixes, and that worked to some extend. But no one seems to care about that since a while. It is also not clear what the actual 'master' branch of their firmware is, and whether the published one is the recent firmware. People at Pycom seem to change frequently, so there is no continuous building up and keeping of knowledge about the existing code base.

                C 1 Reply Last reply Reply Quote 4
                • S Offline
                  SciWax @Christian Storm
                  last edited by SciWax

                  @Christian-Storm

                  Hi Christian,
                  welcome to the forum. You linked a thread where I've asked a question about UART and how to parse certain strings. I actually made it work and it works for nearly 2 years now thanks to the help of @robert-hh, who helped me getting on the right track.

                  Actually I was sure, that I edited my first post in the thread with a solution, but doesn't seem like it.

                  Tomorrow, I will have access to my PC with a working solution. I will try posting a minimal example for you!

                  C 1 Reply Last reply Reply Quote 0
                  • C Offline
                    Christian Storm @robert-hh
                    last edited by

                    Hi @robert-hh, that sounds not very good. Since I'm almost done with my project, about 95% achieved. The last meters are so important. I do need a reliable uart communication on few Bytes and many Bytes. I solved it with a kind of file buffer. So I save the "normal" data from my external UART device (btw without any option of flowcontrol) which have about 45bytes. And if I am requesting the whole data, so I get it from file buffer. Thanxx for your help and time

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      Christian Storm @SciWax
                      last edited by

                      Hi @SciWax, would be great to hear from you and your solution!

                      S 1 Reply Last reply Reply Quote 0
                      • S Offline
                        SciWax @Christian Storm
                        last edited by

                        @Christian-Storm

                        Hi, sorry for the late reply. My week was really turbulent.

                        In my case, I basically designed the format of the strings myself the Pycom board receives. I had more freedom, therefore I've created a start marker and end marker, which nicely surround my strings.

                        I've created json formatted strings, which begin with { as a start marker and end with } as an end marker. My reference is a tutorial in the official Arduino Forum

                        So basically I read my input strings like this embedded in a while loop:

                                dataRec = serialrecv(uart1) # collect single bytes
                                if dataRec is not None:
                                    if dataRec.startswith('{') and dataRec.endswith('}\r\n'):
                                        print(dataRec)
                        

                        where dataRec is the string received and parsed by

                        # Configure UART on pins P3(TX1) and P4(RX1)
                        uart1 = UART(1, baudrate=9600, timeout_chars=10000) 
                        
                        def serialrecv(uartport):
                          #read the data, letter by letter until we reach EOL
                          dataString = ""
                          char = uart1.read(1)
                          if char is not None:
                              print("")
                              print("Reading string from Serial:")
                              while char is not None:
                                  dataString += char.decode("utf-8")
                                  char = uart1.read(1) 
                          return dataString
                        
                        C 1 Reply Last reply Reply Quote 0
                        • C Offline
                          Christian Storm @SciWax
                          last edited by

                          Hi @SciWax, thanks for your reply. I rely on the communication protocoll of the external device, which have only an end marker "\r\n". The normal dataflow, about 45 bytes are ok with readline and even with read by byte (uart.read(1)). The Problem occurs one data larger than the overflow. If I try to read more than 2000 Bytes at once, it makes no sence. In between the "received" data block there are missing data, and thats the mess.

                          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