soft serial replace default serial

Issue #474 resolved
maike maker created an issue

Hi, John:
I need help,
I recently used a serial port to drive a TTS module, and now I want to use a soft serial port to drive it, leaving the default serial port to receive network data.
I don't know how to use a soft serial port to send the same control commands. Please give me some advice or demo

Comments (7)

  1. John Maloney repo owner

    As you guessed, you can just put the "hex 3F" block into the first argument slot of the "soft serial write byte" block.

    Soft serial can only send data, not receive it, but it can send it over any pin capable of digital output.

    The "soft serial write" block can only send one byte at a time. You can use a "for" loop to send a list of bytes.

    Soft serial uses the processor itself to generate the serial data signal (in contrast to hardware serial, which runs independently from the processor). That means that soft serial can interfere with time-critical tasks.

    The pilot release has timing adjustments that allow soft serial to work at higher baud rates than the version in the stable release.

    Good luck with your project!

  2. Tom Ming

    Hi @John Maloney , As we know that ESP32 use GPIO 16 and 17 as RXD2 TXD2.Is it possiable to custom the hard serial port ,for example RXD2--> GPIO25 TXD2-->GPIO26?

    Thanks.

  3. Tom Ming

    @John Maloney

    I have try it ,modify the serialOpen function of serialPrims.cpp as below, it works ,Thank for your help!

    static void serialOpen(int baudRate)
    {
        if (isOpen)
            serialClose();
        #if defined(ARDUINO_CITILAB_ED1)
            int txPin = mapDigitalPinNum(1);
            int rxPin = mapDigitalPinNum(2);
            SERIAL_PORT.begin(baudRate, SERIAL_8N1, rxPin, txPin);
        #elif defined(ESP32)
            int txPin = mapDigitalPinNum(25);
            int rxPin = mapDigitalPinNum(26);
            SERIAL_PORT.begin(baudRate, SERIAL_8N1, rxPin, txPin);
    
        #elif defined(RP2040_PHILHOWER)
        #if defined(PICO_ED)
        // pico:ed edge connector pins 0-3 are analog pins 26-29
        // so use pins 4-5 for serial
            SERIAL_PORT.setTX(4);
            SERIAL_PORT.setRX(5);
        #elif defined(XRP)
        // use pins 16-17 (servo 1 & 2) for serial on XRP
            SERIAL_PORT.setTX(16);
            SERIAL_PORT.setRX(17);
        #endif
            SERIAL_PORT.setFIFOSize(1023);
            SERIAL_PORT.setTimeout(1);
            SERIAL_PORT.begin(baudRate);
        delayMicroseconds(5);        // wait for garbage byte when first opening the serial port after a reset (seen at 115200 baud)
            SERIAL_PORT.begin(baudRate); // reset to discard garbage byte
        #else
            SERIAL_PORT.begin(baudRate);
        #endif
        isOpen = true;
    }
    

  4. Log in to comment