I wrote a small sketch to produce PPM output based on analog inputs. I initially started with an Arduino "UNO", then switched to an Arduino "Micro" due to size restrictions. However, when I compile the same sketch for the "Micro", the code is quite a bit larger, by almost 35%. Anyone have a reason for this? I would have assumed that since the "Micro" is a single CPU board, the code would be smaller. The "UNO" uses a co-processor to actually output the digital levels which would seem to require more overhead to shift data from the CPU to the "co-processor".
There is a reason.
The Micro is like the Leonardo. They use a software serial port via the usb. Uploading a sketch or using the serial monitor uses that software serial port via usb. Since the bootloader contains also the code for the software serial port, both the bootloader and the sketch are larger, and there is less available for your sketch.
Ahhhh. So since the USB serial port is always there (for sketch uploading), I will always have that small overhead?
The sketch uploading is controlled by the bootloader, which is a lot bigger for the Micro. Nothing you can do about that.
I understand the bootloader would be bigger to support the USB serial port. However, it still doesn't make sense that the compiled size of the sketch would be bigger. Unless the bootloader is added to the compiled sketch and both are uploaded every time a new upload is performed.
The Micro is like the Leonardo. They use a software serial port via the usb.
No, they don't. Both the USB input/output and the RX/TX input/output are handled in hardware. But, because there are two instances of the HardwareSerial class, with its input and output buffers, the sketch will be larger.
PaulS, the usb part inside the ATmega32u4 is hardware. The serial port with RX and TX at pin 0 and 1 is hardware but is not used. Not for uploading a sketch, not for the serial monitor. As far as I know, the serial port over the usb bus is a software implementation in the Arduino. Can you check it again, and explain ?
the usb part inside the ATmega32u4 is hardware.
The serial port with RX and TX at pin 0 and 1 is hardware
but is not used.
It can be.
Not for uploading a sketch, not for the serial monitor.
True, but you CAN connect an XBee or a GPS or a GPRS to it, and use hardware to send and receive data via those pins.
As far as I know, the serial port over the usb bus is a software implementation in the Arduino.
No, it isn't.
Ok, thanks for explaining. I have to read better what the CDC class is. Can you answer one more question ? In a normal sketch, a keyboard and mouse emulation and the serial monitor are all using the usb. Is that serial communication also the CDC class ? Or was I confusing the bootloader with the sketch serial port.
the serial port over the usb bus is a software implementation in the Arduino.
No, it isn't.
The 32u4-based Arduinos implement "Serial" as a CDC driver on top of the hardware USB peripheral. I don't know whether you'd want to consider that a "software implementation" or not, but the CDC driver IS significantly larger than the HWSerial driver on top of the UART hardware.
I don't know whether you'd want to consider that a "software implementation" or not,
I guess I should. I was thinking in terms of HardwareSerial vs. SoftwareSerial when I said that the USB I/O was not software based.