Using flash memory for data storage and retrieval

I am working on a project to develop a small payload package for model rockets. I have a bread board system working using a TTGO-T-Display ESP32 processor module(http://www.lilygo.cn/prod_view.aspx?TypeId=50033&Id=1126&FId=t3:50033:3), an MPU-6050, and a BMP280. Since the processor module has a built-in display that uses the only SPI bus, I am using the large flash memory to store the data in a large array. In my code at the end I use a while(!Serial) command to halt the Loop function and wait for a Serial port connection. This works fine while running off USB power, but for the rocket, the processor must run off a battery. When on battery power if I connect the usb and turn off battery and invoke the serial monitor from the IDE, the program never senses it and the data doesn't download to the monitor as it does when powered through the usb port.

Can anyone explain why this happens and if there might be a workaround I might use?

Thanks.

Using Serial requires running Serial.begin() which requires a serial connection then not later.

Maybe in void setup() you make a mode where if Serial connects the data in flash gets dumped and if it doesn't then data gets collected............. so your sketch acts different ways when started with and without the USB connection.

I'm not so sure of all your hardware and connections, this is my best guess.

Thanks for the suggestion. I can give that a try. It also occurred to me that I can try initiating the connection with one of the two buttons on the processor module. In either case recalling Serial.begin() is probably necessary. Thanks, again.

For one thing, does this package go up in the rocket? Then you might want power off for the landing.

You have an ESP32 in there. Why not use it to transmit the data instead of connecting to serial?

If you are going to connect serial to a powered device --- that's going to take a lot of care on common grounds.