I can't upload a sketch with !!! in a string



Unfortunatly this is a string captured by a certain bootloader called STK500v2bootloader for the Mega versions of Arduino. The bootloader can be used on an Uno, however it does not appear to be installed on any of my original or clone Uno boards.

To avoid this problem you can either use a different bootloader or modify your code. I would not recommend replacing the bootloader as some bootloaders for the Mega do not support writing the entire flash memory and sketches will fail to upload or run once they reach the 128Kb size.

If you prefer to simply revise your code, remember to use only two exclamation marks, or separate them using two strings or two print statements. Depending on your implementation there are possibly many ways of handling !!! without inserting it directly into code.

Please note that the error explained here will affect any data that contains the binary equivalent of !!!, the snippets below illustrate two valid sketches that will fail to upload. 

char str[] = "An example string!!!";

void setup(){
  Serial.begin( 9600 );
  Serial.print( str );
}

void loop(){}
byte arr[] = { 0x14, 0x15, 0x21, 0x21, 0x21, 0x22 };

void setup(){
  Serial.begin( 9600 );
  Serial.write( arr, 6 );
}

void loop(){}

In the second example, the The actual use of this feature is explained here.

 A quick test of the monitor feature proved successful. At a baud rate of 115200 bps, you have to send in binary !!! within three seconds of resetting the Arduino. I was able to get this running in the IDE Serial monitor.

This caused an output of: 

!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!
Arduino explorer stk500V2 by MLS

Here is the output of a few commands.

  • Command: ?
    Bootloader>? CPU stats
    Arduino explorer stk500V2 by MLS
    Compiled on  = Sep  9 2010
    CPU Type     = ATmega2560
    __AVR_ARCH__ = 6
    GCC Version  = 4.3.3
    AVR LibC Ver = 1.6.7
    CPU signature= 1E9801
    Low fuse     = FF
    High fuse    = D8
    Ext fuse     = FD
    Lock fuse    = FF
    Bootloader>
  • Command: @
    Bootloader>@ EEPROM test
    Writting EE
    
    Arduino explorer stk500V2 by MLS Bootloader> Huh? Compiled on  =  CPU Type     =  __AVR_ARCH__ =  AVR LibC Ver =  GCC Version  =  CPU signature=  Low fuse     =  High fuse    =  Ext fuse     =  Lock fuse    =  Sep  9 2010 1.6.7 4.3.3 V#   ADDR   op code     instruction addr   Interrupt no vector rjmp   jmp  What port: Port not supported Must be a letter   Writting EE Reading EE eeprom error count= PORT 0=Zero address ctrs ?=CPU stats @=EEPROM test B=Blink LED E=Dump EEPROM F=Dump FLASH H=Help L=List I/O Por
    
    Reading EE
    
    Arduino explorer stk500V2 by MLS Bootloader> Huh? Compiled on  =  CPU Type     =  __AVR_ARCH__ =  AVR LibC Ver =  GCC Version  =  CPU signature=  Low fuse     =  High fuse    =  Ext fuse     =  Lock fuse    =  Sep  9 2010 1.6.7 4.3.3 V#   ADDR   op code     instruction addr   Interrupt no vector rjmp   jmp  What port: Port not supported Must be a letter   Writting EE Reading EE eeprom error count= PORT 0=Zero address ctrs ?=CPU stats @=EEPROM test B=Blink LED E=Dump EEPROM F=Dump FLASH H=Help L=List I/O Por
    
    eeprom error count=0
    
    Bootloader>
  • Command: L
    Bootloader>L List I/O Ports
    PORTA
    PORTB
    PORTC
    PORTD
    PORTE
    PORTF
    PORTG
    PORTH
    PORTJ
    PORTK
    PORTL
    Bootloader>

There are a few more options available and could be quite handy for debugging. So I hope this will clear up a lot of confusion as to why a sketch suddenly refuses to upload.

Tags: fail, upload
Last update:
2013-12-29 15:01
Author:
Christopher Andrews
Revision:
1.14
Average rating: 5 (2 Votes)

You can comment this FAQ

Chuck Norris has counted to infinity. Twice.