I'm experimenting something new with my Arduino Leonardo. I removed its original bootloader and flashed it with LUFA mass storage example with added functionalities(now its a firmware). I'm trying to now add RFID reader(read/write) example to my firmware. For that I have to convert the sketch to a c++ code. So I copied relevant header file and cpp file from the library folder(libraries->rfid-master->bla.h,bla.cpp). But I'm confused what to do with the .ino file under examples(libraries->rfid-master->examples->ReadAndWrite->blabla.ino). I guess this code should be copied to the main class of my firmware. Any ideas?

1 Answer 1


Basically *.ino is *.cpp without headers. So you can

  • rename it to *.cpp,
  • If you have any functions which are used before they have been defined, provide declarations for each function before its first use
  • #include <Arduino.h> on the top
  • #include <Wire.h> if you are using Wire and so on

and you have "normal" CPP file.

If you are making library this way, than you create also *.h file, where you declare all exported functions and objects and #include that file in your *.cpp as first line (than you do not need/have to forward declare any of that exported functions)

You may like to take a look at https://github.com/arduino/Arduino.git https://github.com/sudar/Arduino-Makefile and https://github.com/ladislas/bare-arduino-project

the Bare Arduino have 2 projects each using 2 libraries, so you can get inspiration there

  • 2
    The Makefile you are linking to seems like a slightly outdated fork of Sudar Muthu's Arduino-Makefile. Why not link to the original instead? Commented Jan 4, 2017 at 16:43
  • Just because I first found the Bare-Arduino, which used this version (and then patched it with the sudar version as I now see). Anyway it is able to compile my files against Arduino 1.8.0, so it could work as starting point. Or the original Sudars makefile, but the Bare project have nice examples, how to organise your project, which I think would help @Isuru with the start. And later he can migrate to other version/system. (I build simple one over that too, to help my projects, nothing much but helped me to sort my mind faster)
    – gilhad
    Commented Jan 4, 2017 at 17:00
  • Whereas it makes sense to pull WeAreLeka/Arduino-Makefile as a submodule of ladislas/Bare-Arduino-Project, it doesn't make sense to provide a direct link to that fork, as it has no added value over the original. If you do want to give a direct link to Arduino-Makefile, you should edit your answer in order to link to the real project. Commented Jan 4, 2017 at 18:14
  • You forgot about having to predeclare functions.
    – Pharap
    Commented Aug 24, 2018 at 17:08
  • @Pharap "for each function, which is used before declaration write its header before first use" is (IMHO) exactly that... and functions used after declaration are already declared. Or are there some other cases, where usual ino -> cpp needs it?
    – gilhad
    Commented Aug 24, 2018 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.