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 write human-readable ASCII text

    Scheduled Pinned Locked Moved LoPy
    9 Posts 5 Posters 96 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.
    • M Offline
      Mao
      last edited by

      Hi,

      I'm working on Lopy4 interfacing with Nextion serial display (http://nextion.tech/instruction-set/#s6).

      To send the data to the monitor for displaying, I have to follow their rules (see below Arduino code for instance).
      12bf8b0f-562a-466d-8964-b2d108625987-image.png
      Sample code from https://www.youtube.com/watch?v=akpF9TbvNss&t=542s

      I had tried to migrate the Arduino code to Lopy4, but never make it works. After investigating, my understanding is that uart.write() can not accomplish the work that Serial.print()in Arduino does. Because the former write a series of bytes to the serial port, while the latter one prints human-readable ASCII text to the serial port.

      So my question is can Lopy4 UART port write human-readable ASCII text? Please give some instructions. Thank you!

      robert-hhR 1 Reply Last reply Reply Quote 0
      • M Offline
        Mao
        last edited by

        In short, can Lopy4 UART port performs the same function as Serial.print() does in Arduino?

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

          Try:
          uart.write("Hello World!".encode())

          Not 100% sure, but thinks that should do the trick.

          Johan

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

            @Mao There are two options:
            a) use the str() function or an string formatting methods to convert a non-ascii object into it's ascii representation, which you then can send with uart.write(). Like uart.write(str(100.3))
            b) use the file = stream option of print, like:

            from machine import UART
            uart = UART(1)
            print("The answer is", 42, ", but what is the question?", file=uart)
            

            Obviously you can combine both methods for a pretty formatted output, a little bit easier than you could do with Arduino.

            P.S.: Thanks to Dave Hylands pointing me at the file=xxx option again.

            1 Reply Last reply Reply Quote 0
            • M Offline
              Mao
              last edited by

              Thank you for all the instruction and explanation! My problem finally got fixed!

              mogplus8M 1 Reply Last reply Reply Quote 0
              • mogplus8M Offline
                mogplus8 @Mao
                last edited by

                @Mao could you please post a copy of your program? I have not been able to find a way to send the 0xFFFFFF Nextion terminator to the Nextion screen as part of the uart.write command. It always complains that it can't convert the object to a string. If I try to convert it to a string it is converted to the string of characters that I used to define the object, like b'\xff\xff\xff' or 765. How did you do it?
                Thanks,

                mogplus8M 1 Reply Last reply Reply Quote 0
                • mogplus8M Offline
                  mogplus8 @mogplus8
                  last edited by

                  @mao
                  Well I think I've solved this one. It seems the original method now works, although I will swear on a stack of Bibles that it didn't the first time I tried it. I set a variable to '\xff\xff\xff' and then use that as the command terminator and it now at least runs whereas I was getting an error message before.
                  Now I have a different problem...

                  1 Reply Last reply Reply Quote 0
                  • O Offline
                    oliverthom707
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • O Offline
                      oliverthom707 @Mao
                      last edited by

                      @Mao Thanks man issue is finally resolved.

                      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