I'm deploying some DIY home automation devices, built around a 3.3v pro mini, a HC-10 module, and a relay board. The arduino is able to be programmed over the bluetooth module, so once it's in the wall, upgrades are easy.
The HC-10 is connected to the RX/TX pins of the arduino. The reset pin of the arduino is tied to one of the PIO pins of the HC-10 via a 100nf cap. I have a device I built that sets up the bluetooth connection, and once the upload starts, it toggles the PIO pin, pulling the cap low, thus resetting the arduino. The code then uploads over the bluetooth link as if it were direct USB.
Everything works great. I can upload code, test it, upload more code, etc etc. Works great.
UNTIL I try and upload code that relies on Serial... the moment my code has a while(Serial.available()) or Serial.read() in it, the upload 'hangs' about 80% of the way through, the IDE reporting an error.
Weird thing is - the code DID upload correctly. It seems it failed during the verify stage. If I comment out the Serial.available and Serial.read, it uploads great. I thought maybe the code started running before the verify was done, so I added a delay in the setup() section to allow the upload to finish before any serial activity started. That didn't help. I tried moving the Serial code into another function. That didn't help. I set a new variable, int testing = 1, and enclosed the Serial functions inside if(testing > 2), an impossible condition. THAT WORKED. Long story short - after lots of testing, if there exists the possibility of the Serial code running, even if it does NOT, the upload verify hangs and fails. If the code is commented out, or placed in an impossible situation, the code uploads fine.
Why would the mere presence of Serial code, even if it's not running until way after the upload finishes, screw up my upload?
I can live with the error - the code uploads and runs fine. Just annoying to not see a clean 'Done uploading' at the end.
Any idea why it's doing this?