Leonardo delay timing problems

I have written Lin bus to keyboard interface sketch for Teensy. It worked perfectly, then I bough Leonardo and modified the code for Leonardo and it did not work. Started troubleshooting and looks like the problem is Leonardo:

1) Sketch runs perfectly after the uploading is done 2) When I unplug from USB and re-plug the Leonardo to USB the keyboard sketch runs 10 times slower-delay(1000) equals approx 10 seconds 3) When I press the reset on board then the sketch runs normally again.

Basically this means that it is not possible to use the Leonardo as keyboard without pressing the reset first....

Problem occurs when using the board with any computer - tested with Mac, PC or Linux(Android);

The test sketch i used :

void setup() {

Keyboard.begin(); }

void loop() { delay(1000); Keyboard.print("First "); delay(1000); Keyboard.println(" Second"); delay(1000); }

Any advice is warmly welcomed :)

I can't reproduce that. Using your sketch, and unplugging the USB and plugging it back, it works the same.

Have you tried adding e.g. a delay(5000) call in setup(), in case the USB system needs more time to handshake with the computer?

Have tried delay(10000);
No help from that.
Have also tried
UDCON |= (1<<DETACH);
delay(10000);
UDCON &= ~(1<<DETACH);
No changes

If the system needs more time then it probably would work after some time but in my case it remains working slowly without reset. The questions is why and how ? Is there a different clock frequency available for bootloader, maybe it uses this?

As Nick can't reproduce the problem, I wonder whether the two of you are using different versions of the Arduino core and/or the bootloader?

In my case i think that the easiest solution would be to buy one more Leonardo or micro and try with it. I am using Arduino 1.05, about the bootloader - i don´t know how to get this info from board?

I've modified my bootloader detector sketch which normally works with an ICSP programmer to "self-read" the bootloader on the current board. This only works if your "lock bits" permit reading the bootloader. My standard Leonardo does that, so hopefully this will work.

Sketch is at:

http://gammon.com.au/Arduino/Atmega_Self_Read_Signature.zip

Unzip that (the whole folder which contains three files) into your sketches folder. Compile and upload, and open a serial monitor. You should see something like:

Signature detector.
Written by Nick Gammon.
Signature = 1E  95  87 
Fuses
Low = FF High = D8 Ext = CB Lock = FF 

Processor = ATmega32U4
Flash memory size = 32768
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 4096 bytes starting at 7000

Bootloader:

7000: 55 C0 00 00 6E C0 00 00 6C C0 00 00 6A C0 00 00 
7010: 68 C0 00 00 66 C0 00 00 64 C0 00 00 62 C0 00 00 
7020: 60 C0 00 00 5E C0 00 00 EE C4 00 00 5A C0 00 00 
...
7F70: 01 07 05 82 03 08 00 FF 09 04 01 00 02 0A 00 00 
7F80: 00 07 05 04 02 10 00 01 07 05 83 02 10 00 01 04 
7F90: 03 09 04 22 03 41 00 72 00 64 00 75 00 69 00 6E 
7FA0: 00 6F 00 20 00 4C 00 65 00 6F 00 6E 00 61 00 72 
7FB0: 00 64 00 6F 00 00 00 18 03 41 00 72 00 64 00 75 
7FC0: 00 69 00 6E 00 6F 00 20 00 4C 00 4C 00 43 00 00 
7FD0: 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 
7FE0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 
7FF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 

MD5 sum of bootloader = 53 E0 2C BC 87 F5 0B 68 2C 71 13 E0 ED 84 05 34

If you get the same MD5 sum, then you have the same bootloader as me. If not, can you report what you got please?