Arduino Quine

One of the things programmers tend to learn how to do in every language they know is how to write a quine – that is, a program that echoes its own source code out to the user, without reading the source code directly. This is an inherently recursive operation, so language-based tricks are needed to get it to work.

The Arduino is programmed in C++, however, there is no std::cout. Instead, user input is usually through the USART on the Arduino, and as such needs to initialize and print out from that port.

Traditionally, C/C++ quines are written using the preprocessor and the printf command, as it allows for simple replacement of strings with characters, thereby overcoming the recursive operation. As such, I use the sprintf command below (Arduino’s HardwareSerial doesn’t support formatted prints, sadly enough).

Read more on Arduino Quine…