I've uploaded the latest version to Freaduino Leonardo and Windows immediately showed a pop-up "USB device not recognized". Hopefully, I have Freaduino UNO that I've used as programmer to restore bootloader - it un-bricked the Leonardo.
I can upload any example sketch, such as "Blink" to Leonardo, it works. But as soon as I upload my code, it gets bricked.
Same code uploaded to UNO works kinky. It either hangs in the middle of the line 96, or, if I comment it and all other lines out, freezes around line 121. But at least UNO doesn't get bricked.
"Upload using programmer" doesn't work either - this approach also bricks Leonardo.
You use the String class in two functions. The String class always causes grief because it can't work effectively with a small amount of memory. A Leonardo has 2.5kB static ram which is only marginally more than in a UNO.
You should change all uses of the String class to null-terminated C strings.
[quote author=Nick Gammon link=topic=199794.msg1473405#msg1473405 date=1384816800]
What version of the IDE do you have?[/quote]
As a newbie, I was under impression that "if compiler says my code is OK, it will run". Probably, the use of String was a bad idea, and it was what caused my problem. Good that I have 2nd Arduino to unbrick the other one. If I had only single board, it would be a poor situation.
It's not at all easy to brick your Arduino. The Leonardo in particular can be idiosyncratic to upload new sketches to, but you rarely are in the position where you have lost if forever.
if compiler says my code is OK, it will run
If the compiler says it is OK, then its syntax is acceptable. But that's like saying:
King Arthur and his knights visited the Pentagon yesterday and ate three mile long hamburger buns on top of the asparagus.
It might make sense syntax-wise, but operationally, it doesn't.
Are you sure it's actually "bricked" ? On a leonardo it would be easy to write a sketch that causes the board to stop responding to USB traffic, but doing an actual hard reset via the RESET button should still get you to the bootloader...
westfw:
Are you sure it's actually "bricked" ? On a leonardo it would be easy to write a sketch that causes the board to stop responding to USB traffic, but doing an actual hard reset via the RESET button should still get you to the bootloader...
If the program disables USB then pressing RESET would just run that program again from the beginning. It's not a good 'feature' of the Leonardo, but it's not difficult to understand how it could be 'bricked' by bad software.
Yes, but if you hold reset down, and release it at the right moment, the bad sketch doesn't get a chance to run. However I agree the Leonardo can be annoying to program.
For example, if you take Blink.pde, and disable USB in setup:
void setup() {
PRR1 |= 1<<PRUSB; //disable USB
Then the board is "bricked" in the sense that no host-side actions will cause another sketch to upload successfully. USB has to be working in order to recognize the traffic that causes an auto-reset.
But hitting the reset button manually will still give you several seconds to upload a sketch that doesn't disable USB, and that should restore the leonardo.
It should be "When all else fails read the instructions"
Ah you sound like the younger generation where reading the instructions is considered as some form of defeat. My kids tell me off about reading instructions.
I have found it best to first of all not read the instructions, play about with it a bit and then read the manual. That way you have a grasp of what is important and what is not and often pick up useful tips and short cuts that you need as opposed to most short cuts which are in just because the programmer thought they would be fun to implement.