Arduino 1.6.7 is generating too large hex exported binary

Hello everybody, I'm new here and to Arduino in general. I'm trying to create a program to utilize the GSM library.

My program is 315 lines and it is basically reading incoming SMS and inspecting incoming calls. I'm using ATMega328P as an mcu.

The problem I have is when I compile and export the file as binary because I want to upload it to the mcu using avrdude and AVRISP MKII. The hex file size (even the one without the bootloader) is huge: 47k. While the ATMega328P flash can only store 32K.

If I compile the code with CodeVision, the result will be around 6K.

Why does Arduino generate such a large hex file? BTW: I'm using Duemilanove or Diecimila board and I'm using EEPROM.h and GSM.h libraries.

Thanks

How big is the GSM library?

the src folder for the GSM library contains multiple files (h & cpp) with total size 283K

A HEX file is an ASCII file, with each byte represented by two characters, plus additional characters for addresses, counts, checksums, etc. You CANNOT judge the size of the code by looking at the size of the HEX file, without knowing exactly what the HEX file represents.

Have you tried actually uploading the HEX file? You'll find it works just fine.

Regards, Ray L.

ns2016: The hex file size (even the one without the bootloader) is huge: 47k. While the ATMega328P flash can only store 32K.

In the .hex file each byte is represented in readable form, for example AB CD.

Thus at the very least, you could divide the file size by two, giving 23.5 k. Plus there are sumchecks at the end of lines, and addresses at the start.

If I compile the code with CodeVision, the result will be around 6K.

What result? The 315 lines? Or the file you actually upload?

Hex file line looks like this :101C40 000D92A236B107D9F711E0A2E6B0E001 C0CB

So you have a : , 3 bytes of address, 16 bytes of sketch data, and 2 bytes of checksum per line. So a 47K hex file is more like 16/22 of sketch data, more like 34K. Perhaps a touch big for a '328.

The 315 lines may be your sketch, but you don't see all the lines of code that are hidden behind the scenes and make the file a lot bigger.

CrossRoads, that is 43 bytes for your 16 bytes of sketch data (each byte of the sketch takes two characters in the file). Check the line length - it is 43. Plus add on carriage-return and linefeed, giving 45 bytes per line (which uploads as 16 bytes).

Thus the uploaded size is 16/45 not 16/22.

So a 47k file is really 47 * 16 / 45 = 16.7 k of program memory.

In all likelihood the OP is not comparing apples with apples. The 6k he quotes probably excludes the libraries.

You can find the generated code size by looking at the IDE output, eg.

Sketch uses 1,308 bytes (4%) of program storage space. Maximum is 32,256 bytes.

(That is for a different sketch, but it shows the idea). That particular hex file was 3708 bytes. Multiply 3708 by 16/45 and you get 1318 which is pretty close to what the IDE reported as the total size.

Ok, I was looking at it more like 00 0D was two bytes of binary read back in hex format, but I can see a byte per character of file storage now that you mention it.

Thanks everyone. Your explanation makes perfect sense.