Page 1 of 1

Error when uploading a sketch via Bluetooth

Posted: Mon Oct 13, 2014 8:36 pm
by a scanner darkly
Finally had the time to set up the IDE and test out the bluetooth connection, was able to upload different sketches from the library, and right after that managed to brick the 'b with my very first sketch :-)

It seems now I can't upload via bluetooth anymore, in the serial monitor window I get an error message about std bad memory allocation and then nothing, ERASEANDRESET doesn't work - I assume that's because there is a bootstrapper of some sort for the bluetooth upload which I managed to damage? I guess my only option to fix it at this point is to use the USB upload? (can't test this until tomorrow, need to get a Micro B cable)

Posted: Mon Oct 13, 2014 8:45 pm
by scottwilson
It's not bricked-bricked, but yes, if the BT doesn't respond, you have to use the USB cable to get a working sketch uploaded.

You have to have the EventManager::loop() in the Arduino loop() method... it's that code that monitors the incoming serial signal for commands (among other things). I haven't really leveraged this yet, except for one demo command (DEBUG ON) and the ERASEANDRESET command.

While actively debugging, it's usually faster to use the USB cable, and then switch to the BT connection when you know your sketches are solid and it's a convenient way to upload them without requiring a physical connection.

Let me know if anything else comes up.


Posted: Mon Oct 13, 2014 9:03 pm
by a scanner darkly
Oh yeah, sorry, "brick" was too strong of a word, figured a USB upload will fix this. I need to get a proper USB cable and it's just neat to be able to use BT to upload, it worked well even if a little slow.

Makes sense about the serial signal being processed in the loop(). I haven't looked at the code yet, but what about the Reset button, is it handled by the firmware or by the hardware? Thinking if there is still a way to reset it while using BT even if the main loop isn't running for some reason.

Posted: Mon Oct 13, 2014 9:53 pm
by scottwilson
The front-panel reset button is hardware - you won't lose that capability no matter what. However, all that does is reboot the device.

The ERASEANDRESET command does two things - it tells the microcontroller that the next time it boots, it should boot into the bootloader rather than the program memory. Then it reboots itself. This puts it in a state where the next thing it expects to receive is a new program to burn into flash memory.

The USB programming port does this through hardware that the bluetooth adapter just doesn't have access to, unfortunately - which is why I added that one-step command to be able to program it over BT.


Posted: Tue Oct 14, 2014 10:36 am
by a scanner darkly
Cool, that makes sense, thanks Scott! Will update via USB tonight.

Posted: Wed Oct 15, 2014 1:49 pm
by a scanner darkly
All is good, was able to upload a working sketch via the programming USB port!

I remember reading USB hubs can cause problems with sketch uploads, which turned out to be the case with one of my hubs - the upload would go up to 34% and then fail, switching to a different hub helped, so if you're getting errors during USB upload definitely try connecting it directly if you can.

By the way, I'm on Windows XP, so it definitely works on at least that version of Windows. Other than the upload failing through one of the hubs the process was smooth, no special steps of any sort, both Bluetooth and USB upload worked well.

I do need to see if there is a way to optimize the compilation time, it's really slow on my computer (but then it's pretty old, 6y+).