I'm pretty new to microcontroller stuff and have some limited programming experience, but I cannot figure out why my ESP is restarting after I finish transferring some data over USB from my python script (PC) to my ESP32.
I made a very simple program using Serial Transfer library for both sending (PySerialTransfer) and recieving (SerialTransfer). These two libraries are compatible with each other. I am using my LCD to tell when it restarts (since I can't use Serial monitor for debugging, the com port is being used).
ESP CODE
#include "SerialTransfer.h"
#include "SPI.h"
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();
SerialTransfer myTransfer;
void setup()
{
Serial.begin(115200);
myTransfer.begin(Serial);
tft.begin();
tft.fillScreen(TFT_BLACK);
}
void loop()
{
if(myTransfer.available())
{
tft.fillScreen(TFT_BLUE);
}
}
PYTHON CODE
import time
from pySerialTransfer import pySerialTransfer as txfer
if __name__ == '__main__':
link = txfer.SerialTransfer('COM4')
link.open()
float = 5.234
float_size = link.tx_obj(float) # pack float into output buffer
link.send(float_size)
time.sleep(2) # sleep allows time to see color change before restart
link.close()
Problem
When I run my Python code, I expect my screen to turn from black to blue and stay blue, even after the connection is closed. Instead what I get is my screen turning blue for 2 seconds and then my ESP immediately restarting (screen flashes white and returns to black). If I place the code
float = 5.234
float_size = link.tx_obj(float) # pack float into output buffer
link.send(float_size)
from my python script into a while True: loop, the screen remains blue forever. It seems to me that the failing point is link.close()
in my python script. If I remove that, it still restarts at the termination of the python script anyways. I don't understand if this is intended behavior or not. My goal is to occasionally connect to my ESP while it is running, send it a large list of data from my PC, and display it on screen, without any restarts.
This kind of behavior is the same in my larger scripts of the same nature. My ESP will recieve all of the data fine and perform its operations successfully, but once my python script closes the serial connection, the ESP restarts.
Also sidenote, I don't know if using USB is ideal for this kind of goal, or if I should use bluetooth or wifi. I intend for this to be connected to my PC and powered 24/7 via USB so I assume USB would be easiest to transfer data.
Turns out I needed to disable DTR/RTS in my PC python script like so (using pyserial) in order to stop my ESP from restarting, I can't use the SerialTransfer library for this anymore so I will have to rewrite everything but at least it works
link = serial.Serial('COM4', 115200, dsrdtr=None)
link.setRTS(False)
link.setDTR(False)