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

    [Solved :]UART read

    Scheduled Pinned Locked Moved MicroPython
    uartuart printlopy
    6 Posts 3 Posters 2.0k 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.
    • D Offline
      DDA
      last edited by DDA

      Original Post:
      I have a serial device that I would like to integrate with my LoPy via UART ( P3 and P4 pins). Currently, if I connect the serial device's Tx and Rx with my computer via 9 pin DB9 connector ( COM 1 port: pin 2 and 3 ) and TeraTerm or similar with 9600/8/none/stop serial configuration..... on sending two ~~ or "escape" key sequence the serial device wakes up and then if I type "R it gives output. Or instead of ~~R I could also use CTRL+E

      So I tried to replicate that in code but I don't seem to get ANY response except "None" using ~~R or CTRL-E, what am I missing here. Also, I tried swapping the Tx and Rx line as well just in case:

      from machine import UART # Tx and Rx (``P3`` and ``P4``)
      import struct
      import time
      import pycom
      pycom.heartbeat(False)
      uart1 = UART(1, baudrate=9600)
      uart1.init(9600,bits=8,parity=None, stop=1)
      uart1.write(b'0x1B')  # LETS TRY THE ESCAPE ESCAPE R which should be 27 27 82 in ASCII or 1B 1B 82 in Hex 
      uart1.write(b'0x1B')
      uart1.write(b'0x82')
      # Or try CTRL-E which is Decimal 05 or hex 05
      #uart1.write(b'0x05')
      recv=uart1.read(15) # read up to 5 bytes
      print(recv)
      

      Thanks a lot.

      robert-hhR 1 Reply Last reply Reply Quote 0
      • T Offline
        timh
        last edited by

        Might be a stupid question but is the computer serial port a TTL UART (0-3V) or an RS232 serial port.
        Many serial ports (DB9) on a PC are RS232 (very different voltage) and not a TTL UART which is on the PyCOM.

        D 1 Reply Last reply Reply Quote 1
        • D Offline
          DDA @timh
          last edited by

          @timh
          Its a 9 pin RS232, so I see the problem now.....the voltage and logic is way different for both. So, I guess the way around might be to use a RS232 to TTL-UART converter, unless there is another work around to it.

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

            @dda Yep that will be it. Some sort of RS232 -TTL will be required, unless the device has a TTL connection buried inside. They usually do then use a TTL -> RS232 or RS485 to present the external serial interface.

            D 1 Reply Last reply Reply Quote 1
            • robert-hhR Offline
              robert-hh @DDA
              last edited by

              @dda The ASCII code of R is 0x52 or decimal 82, not 0x82

              1 Reply Last reply Reply Quote 1
              • D Offline
                DDA @timh
                last edited by

                Per comments from @robert-hh & @timh , I used a MAX3232, RS232 to TTL converter chip to resolve the issue.

                1 Reply Last reply Reply Quote 1

                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