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]Send Serial ASCII string to Web Server

    Scheduled Pinned Locked Moved Discussion
    lopyuart1
    12 Posts 3 Posters 2.6k 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.
    • J Offline
      jimpower
      last edited by livius

      I have a lopy with expansion board I have connected pin 4 of the lopy to pin 3 (tx) of a serial cable aswell as ground to ground. I am using cmd echo hello > COM9 from windows shell, but I get as a hex string as an output.

      b'\x00\x80\x80\x80\x00\x00\x80\x00\x80\x80\x80\x00\x80\x80\x80\x00\x00\x80\x00'

      import machine

      uart1 = machine.UART(1, baudrate=9600, bits=8, parity=None, stop=1)

      while True:
      print(uart1.readall())
      time.sleep(1)

      Is this expected output? My goal is my family has a weigh station and want to have the weight displayed in their office which is 10m away from weigh machine. The weigh station out puts ASCII string via RS-232 connection as follows
      <STX> <SIGN> <WEIGHT(7)> <STATUS> <EXT>
      STX: Start of transmission character (ASCII 02)
      ETX: End of transmission character (ASCII 03)
      SIGN: The sign of the weight reading (space for positive, dash (-) for negative)
      WEIGHT(7): A seven character string containing the current weight including decimal point, then first character isa space. Leading zero blanking applies.
      STATUS: Provides information on the weight reading. The characters G?N?U?O?M?E represent Gross/ Net/ Underload/ Overload/ Motion/ Error.

      If the output is in HEX how can I represent this to POST in usable data? Can I use ubinascii conversion?

      Any help would be great.

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @jimpower
        last edited by livius

        @jimpower said in Send Serial ASCII string to Web Server:

        \x00\x80\x80\x80\x00\x00\x80\x00\x80\x80\x80\x00\x80\x80\x80\x00\x00\x80\x00'

        this is not hello sentence
        first look if you have same port configuration on PC

        type mode into command line and look like is your port really configured
        it can be different than showing in device manager ;-)

        to see how to configure port, type

        mode /?
        

        e.g.

        mode COM1 BAUD=9600 PARITY=n DATA=8 STOP=1 rts=off cts=off
        

        and to send data from command without line break and spaces use

        set /p x="hello world" <nul >\\.\COM1
        

        but better use any com port software like putty, comport monitor from Arduino IDE ...

        think about people first, then computers

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jimpower @livius
          last edited by

          @livius

          Thanks for your reply,

          I used putty and got this output from

          set /p x="hello world" <nul >\.\COM9

          b'fr3rfr\x193r\x19rfr3r\x19r3rfrfr3rfr3rgr3rfrgrfr3r3rfrg\x00\xa9::\n*\x00yFrgrgrggr3rfrfrgrfrfrf3r3rfr\x19r\trMr\x12r\x12rHrKr\trcr\x0cr\x06r\x06r\x08rgr3rgr3rfr\x19r'

          Does this look accurate?

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @jimpower
            last edited by livius

            @jimpower
            no this looks like garbage
            what is your putty com settings?
            alt text

            UPDATE

            can you clarify this

            I used putty and got this output from
            set /p x="hello world" <nul >.\COM9

            above command can be run from windows CMD after setting com settings by mode command
            you can not run it from putty it send this as text

            think about people first, then computers

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jimpower @livius
              last edited by

              @livius

              0_1518079325810_dab21adb-f18d-44b2-9363-418c668b2037-image.png

              I sent plain text hello with same garbage response

              L 1 Reply Last reply Reply Quote 0
              • L Offline
                livius @jimpower
                last edited by

                @jimpower
                Then only some wiring problem must be.
                You have connected P4 which is default RX for UART1 with TX of your serial converter
                For test connect also RX from converter to TX (P3). And look if all is ok.
                And if possible test Lopy without expansion board.

                think about people first, then computers

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jimpower @livius
                  last edited by

                  @livius Yes my tx is on pin4 and rx on p3. I will try without expansion board thanks.

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

                    Isn’t there an issue with levels? I.e. +/- 5V for regular serial port compared to 0/3V for the LoPy or something similar?

                    L J 2 Replies Last reply Reply Quote 1
                    • L Offline
                      livius @jcaron
                      last edited by livius

                      @jcaron
                      I ommit that he say about RS232!

                      @jimpower
                      RS232 is not an UART. And 5V levels can kill your lopy board it is 3V3 device.
                      If you need to connect it to your PC use TTL converter e.g. USB->UART.
                      You then can have virtual COM on your PC.

                      think about people first, then computers

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

                        @jcaron damn that makes sense, so I would need some kind of step down can this be done by an ardiuno I have one lying around.

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          jimpower @livius
                          last edited by

                          @livius thanks I have a bunch of these lying around will give that a try thanks everyone

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

                            @livius @jcaron <SOLVED>

                            I managed to get this to work thanks to your help, used a sparkfun MAX3232 to step down the RS232 to UART and ASCII strings appear as expected and was able to upload them to a web server.

                            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