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 Serial Stream - Escape Sequences

    Scheduled Pinned Locked Moved Discussion
    uartescape sequencserial escape
    18 Posts 4 Posters 4.5k Views 4 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.
    • robert-hhR Offline
      robert-hh @spookyrufus
      last edited by

      @spookyrufus Independent from the more, for the UART mode the esp32 expects the starting state is high voltage, and each character transmission starts with a low voltage period of 1/baud_rate s, in case of 9600 baud the would be about 104 µs. If at that device the start state is low, the esp32 would not see the begin of a character transmission until eventually there a 1 0 bit sequence of the data is transmitted, which then would be interpreted as the start bit of a byte.
      Interestingly, if i take sequences from your output like 'gdy+' or hex 6664792b, invert that and shift it 7 bits to the right, I get something which ends in 33370D, which is ASCII "37\r". So this can be fixed by inserting an inverter in between, like a 74HC04, or a single transistor circuit.

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        spookyrufus @robert-hh
        last edited by

        @robert-hh Thank you Robert, I think I understand better now. I checked the datasheet for 74HC04 and it seems to me that that is a kind of 6 bits NOT port? Wouldn't there be a way to solve this via software, since the issue seems to involve only flipping and shifting bits?

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

          @spookyrufus No, you cannot do that by software, at least not using the UART, since the uart already decodes the bit stream wrong. You could try to do the decoding using the getpulses() method to get the raw data and decoding the bit stream yourself. In a single message mode, that would start with a rising edge, and then you would have to do some bit fiddling. In grey history, I did that once, but now I would prefer to insert an inverter.
          of the 74hc06, you just need one inverter. You could also use a 2n7000 transistor and an resistor.

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            spookyrufus @robert-hh
            last edited by

            @robert-hh OK, thank you. So by putting a 74HC04 in between the sensor and the LoPy, would I still need to shift 7 bits to the right via software, or is the 74HC04 sufficient to correct the issue?

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

              @spookyrufus The inverter is sufficient. I just see I have a different module. It just looks similar.

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

                @robert-hh Since in UART mode the input has a Pull-Up resistor, a single Transistor like the 2N7000 or the like should do it. The transistor has three legs, called D (Drain), S (Source) and G (Gate). Connect S to GND, D to the UART input (P4) and G to the sensor output. I verified that with a Pulse generator, and the waveform is in spec.
                0_1507220818541_2N7000.jpg

                S 1 Reply Last reply Reply Quote 1
                • S Offline
                  spookyrufus @robert-hh
                  last edited by

                  @robert-hh Thank you Robert. I appreciate very much you taking the time to explain me. I would have never figured out the issue myself, and still can't quite wrap my head around why they would decide to invert the serial signal on the sensor.

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tmz
                    last edited by

                    Hi, @spookyrufus i have the same issue reading MaxSonar sensor on LoPy with Expansion board. The solution is using RS232 converter IC https://www.sparkfun.com/products/11189

                    S robert-hhR 2 Replies Last reply Reply Quote 0
                    • S Offline
                      spookyrufus @tmz
                      last edited by

                      @tmz Hi thanks for the reply. Does this mean that you are powering your sensor with 5V then?

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

                        @tmz I would strongly object to use that solution, for a few reasons:
                        a) If by bad luck you connect the RS232 out to the LoPy/WiPy in, you might damage the LoPy, because RS232 out levels are +/-5V .. +/-12V, which is definitely outside the permittet range of -0.3 .. 3.6 V for inputs.
                        b) the logic levels of the converter on the RS232 input side do not match the 0..5V range. It may works, but could not be relaible.
                        c) price. A 74HC04 cost < 50 cent, a single transistor 10..20 cent, and available at almost every electronic shop. The board you show is 6$ + shipping. The single transistor could be directly attached to the Sonar board; no extra wiring.

                        S 1 Reply Last reply Reply Quote 0
                        • S Offline
                          spookyrufus @robert-hh
                          last edited by

                          @robert-hh I will definitely try the transistor way. I just received an answer from MaxBotix official support, and what they replied is as follows:

                          "We are not familiar with the Pycom microcontrollers, however, we have seen similar issues on the Raspberry Pi. It appears that you need a serial inverter (RS232 to TTL) to interface with this microcontroller. Implementing a serial inverter should solve the issue you are seeing. "

                          Which I believe is compatible with what Robert is saying .

                          1 Reply Last reply Reply Quote 0
                          • S Offline
                            spookyrufus
                            last edited by spookyrufus

                            Transistor finally arrived (had to order it). Put it into place - solution works like a charm. Thanks Robert for the help, I appreciate it very much.
                            If some mod wants to mark the thread as [SOLVED], it'd be now good to do so. I tried doing it myself but could not find how to edit my thread's title.

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

                              @spookyrufus It depends whthter you have a 736x or 738x model. When you operate the device from 3.3V, you shoul dbe able to connect the Serial out from the sensor directly to the Uart RX. If it is a 736x model, you'll need a Inverter, like you can do with a 2N7000: gate -> Sensor, Source -> GND, Drain -> RX, 10k Pullup-Resistor between RX and Vcc. You may also use an inverter chip, like 74hc04 ....

                              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