Arduino Serial Problem

hello friends. Firstly sorry my english.I know a little english not very well. I have a project about the esp8266.But I have a problem about Serial communication.I want to send a long String(max. 1000 byte) with Serial.Println() but data could not send correct to the opposite micro controller device with RX TX pins. How can I increase the buffer size or split the data before I sent . The problem not always shows up ,just It showed up when I try a few times

`    server.on("/runScript", HTTP_POST, [](AsyncWebServerRequest *request) {
        if (request->hasArg("command"))
        {
            String command = request->arg("command");
            Serial.println(command);
            // Handle the command as needed
            // You can add your logic here to process the command
            // For simplicity, just printing it to the Serial Monitor
        }
        request->send(200, "text/plain", "Command received");
    });
`

What kind of Arduino/MCU you have at the receiving side?

Please, provide a copy of the string/data bytes you want to transfer over the Serial Port.

I don't know what max size is, but just break the long string up into 100 byte chunks. print 9 of them and println the 10th (last)

Be aware that esp8266 have only one full serial port, the one connected to usb-serial.
Some devboards fail to use tx/rx pins for Serial.
If you only need to send (and not to receive), you could use Serial1 TX on pin Gpio2.
If your baudrate is low, you can also use softwareserial. Or swap Serial to Gpio 13/15

I have an atmega32U4 with in arduino pro micro.I am building an automation .My data like this
"SHELL terminator
STRING memory=$(free)
STRING sudo /bin/bash -c "echo $memory > $HOME/use_memory/memory.txt"
STRING cd $HOME/use_memory/ & python3 -m http.server
PORT http,5000,memory.txt,$USER"

Then I processes the data in atmega micro chip and send with keystroke to the computer

My baudrate:
#define BAUD_RATE 57200

1 Like

is this really problem that I am using the TX pin. I have connected cross over the cabless with atmega32U4.The problem usualy is being when I runed the command a few trys

Serial1 on Gpio2 pin or Serial on default TX pin?

default serial TX pin (TXD0)

If you only need to send, use Serial1 on Gpio2.
It would be easier for all of us if you post your whole code and wiring scheme.

1 Like

Actually, the main function of my code is to take the data coming from this web and send it via serial port by making a post request to "/runScript". I have already shared this page of my code at the top. I'm sharing part of my main web page that sends "command", part of loop() and setup()

`    <h1>Bash automation</h1>
    <form action="/runScript" method="post">
        <label for="command">Enter Command:</label>
        <textarea id="command" name="command" oninput="updateCharCount()" required></textarea>
        <div class="char-counter" id="charCount">Character Count: 0</div>
        <button type="submit">Run Command</button>
    </form>`

and

void loop()
{
  Reboot();
  
     button_state = digitalRead(BUTTON_PIN);
 
    if(prev_button_state == HIGH && button_state == LOW){
    
     WiFi.softAP(ssid, password, 1, 0);    
    }
}

and

`    Serial.begin(BAUD_RATE);
    delay(2000);
  
    EEPROM.begin(4096);
    SPIFFS.begin();
  
    WiFi.mode(WIFI_AP_STA);
    WiFi.softAP(ssid, password, 1, 0);

    //  /__('_')__\ WebPages  
    MDNS.addService("http", "tcp", 80);`

Yes, but it's not related to serial.

If your problem is serial communication, post your whole code, not some small pieces here and there.

I'm not even trying to read the whole code.
You have 3 lines for serial tx:
Serial.println(command);

and

if(debug) Serial.write(data, len);
  f.write(data, len);
  if(final){ 
    if(debug) Serial.printf("UploadEnd: %s, %u B\n", filename.c_str(), index+len);
    f.close();

Are they all intended to send data to "other MCU" ?

I can't follow, muting

i told you that the code can't help, there's only serial communication in one or two places in the code.Whatever.The problem seems to be caused by buffer from HardwareSerial of buffer size.i read that it was set from h and added the following "#define SERIAL_TX_BUFFER_SIZE 1024
#define SERIAL_RX_BUFFER_SIZE 512" but there is still the same error.Could this be due to the fact that I put a String expression in the serial phonjtion? Because the string has extra bytes and space.

You haven't publish any errors.
My point was just to verify that you really have working serial connection with your other MCU, not that your buffer size is correct.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.