Serial.print output corrupt
Posted: Fri Oct 29, 2021 11:09 pm
Hi All. Having trouble with serial output on my ESP32-CAM device.
I have two of them setup connected together with TX & RX joined, and I have another device with two serial ports that I can see whats being sent from both devices simultaneously.
All commands send between are prefixed with ESP_ and all lines are standard termination with Linefeed like from println()
I have a command processor that ignores anything without the ESP_ prefix, so I get debugging info and console without interference.
I load the same code into both devices, and the one that detects an SD card attached becomes module number 1.
Now - here's the (summarised view) of the setup code and output.
The systems stand alone work fine. I can issue commands and instruct and switch LEDs, take photos, get status etc.
When I join them, sometimes they get stuck at boot.
The serial output from the setup() code within 2-3 lines of code, already has corrupt serial transmission. (I'm running at 115200 baud)
Here's the output log example. Left is module 1 transmissions and number 2 on the right.
and the code that generates it
The last debug() command. Module 2 sends "Module 2 ready to server... message. The debug code sends this and then a couple of lines later sends it again with the command for Module to actually log this to sdCard..
But the second ourput is corrupted at the end by the showMem() output that comes next near the end of setup().
If there some buffer / flow control management I need in my serial prints ?
Coming from the old RS232 days I would day yes, but I can't believe that such a small amount of text being sent would cause issues here. And I also assumed that the Arduino Serial.print functions would handle this
Immediately following that last transmit from module 2, it seems to hang and not respond to further commands. But if I disconnect the two serial lines they continue to startup and run and will accept commands from my serial console.
Anyone with thoughts - I'd really like to hear it.
Thanks
And sorry for the messy code.
Hardy
I have two of them setup connected together with TX & RX joined, and I have another device with two serial ports that I can see whats being sent from both devices simultaneously.
All commands send between are prefixed with ESP_ and all lines are standard termination with Linefeed like from println()
I have a command processor that ignores anything without the ESP_ prefix, so I get debugging info and console without interference.
I load the same code into both devices, and the one that detects an SD card attached becomes module number 1.
Now - here's the (summarised view) of the setup code and output.
The systems stand alone work fine. I can issue commands and instruct and switch LEDs, take photos, get status etc.
When I join them, sometimes they get stuck at boot.
The serial output from the setup() code within 2-3 lines of code, already has corrupt serial transmission. (I'm running at 115200 baud)
Here's the output log example. Left is module 1 transmissions and number 2 on the right.
- 1: debug:Running as module number 1.
- 1: No log detected yet
- 1: Set Log=exists
- 2: debug:Cam setup done.
- 2: ESP_LOG=Cam setup done.
- 1: Listing directory: /
- 2: debug:Module 2 ready to serve...
- 1: DIR : /System Volume Information
- 1: FILE: /index.html SIZE:2 1048576
- 1: FILE: /foo.txt SIZE: 52file: Setting time: Mon Nov 1 12:00:
- 1: debug:Wifi begin
- 2: ESP_LOG=Module 2 ready to servTotal heap: 303272 Free heap: 219396 Total PSRAM: 4194220 Free PSRAM: 3426220
- 1: .-debug:Time init finished
- 1: Monday, November 01 2021 22:00:02
- 1: debug:got time
- 1: Wifi RSSI=-51
- 1: debug:Cam setup done.
- 1: debug:Go Green
- 1: Starting web server on port: '80'
- 1: Total heap: 300832 Free heap: 129220 Total PSRAM: 4194220 Free PSRAM: 3426220
- 1: Ready! Use 'http://10.101.196.63' to connect
- 1: debug:Module 1 ready to TX/RX with other module
and the code that generates it
- void showMem()
- {
- return;
- Serial.printf("Total heap: %7d ", ESP.getHeapSize());
- Serial.printf("Free heap: %7d ", ESP.getFreeHeap());
- Serial.printf("Total PSRAM: %7d ", ESP.getPsramSize());
- Serial.printf("Free PSRAM: %7d\n", ESP.getFreePsram());
- }
- void debug(char *txt)
- {
- Serial.printf("debug:%s\n",txt);
- if (moduleNumber==2) {
- // Send it for number 1 for logging
- Serial.printf("ESP_LOG=%s\n",txt);
- } else {
- sdAppendLog(txt);
- sdAppendLog("\n");
- }
- }
- // Heaps of other stuff here like Wifi setup, Camera setup etc.
- setup()
- {
- if (moduleNumber==1) {
- sd_init();
- sd_listdir();
- startCameraServer();
- showMem();
- Serial.print("Ready! Use 'http://");
- Serial.print(WiFi.localIP());
- Serial.println("' to connect");
- delay(2000);
- debug("Module 1 ready to TX/RX with other module");
- sendCmd("ESP_LED1=008000");
- } else {
- debug("Module 2 ready to serve...");
- delay(200);
- showMem();
- delay(200);
- lastTimeCheck=millis(); // Init timer
- }
- } // End of SETUP()
But the second ourput is corrupted at the end by the showMem() output that comes next near the end of setup().
If there some buffer / flow control management I need in my serial prints ?
Coming from the old RS232 days I would day yes, but I can't believe that such a small amount of text being sent would cause issues here. And I also assumed that the Arduino Serial.print functions would handle this
Immediately following that last transmit from module 2, it seems to hang and not respond to further commands. But if I disconnect the two serial lines they continue to startup and run and will accept commands from my serial console.
Anyone with thoughts - I'd really like to hear it.
Thanks
And sorry for the messy code.
Hardy