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?

  • Strange thing. That it works, when you place the Serial code into an impossible condition, must be due to the compiler optimizing the code away, so that effectively there is no Serial code in the sketch anymore. – chrisl Jan 1 '19 at 19:37
  • Thats what I figured, and why I tried the impossible condition - if int testing = 1, and it is never changed, then testing > 2 will never be true, and that code is likely optimized out. But what's weird and I cannot figure out is why, if there is a Serial.available() anywhere in the compiled code, the verify hangs and never finishes. – InfernusDoleo Jan 2 '19 at 2:26
  • Decided to just disable verification for the custom board type I made for this sort of connection/upload. Disabling that makes the upload run without a problem. I' – InfernusDoleo Jan 2 '19 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.