1

I have been through http://arduino.cc/en/Hacking/LibraryTutorial but I can't do it. Whenever I create a new sketch and try to save it as .cpp or .h from the Save As button in the Arduino IDE, it gets saved as _cpp and _h. I am not able to create a library this way. How do I create a new library? What am I missing here?

  • 1
    Welcome to Arduino! Could you tell us what you were trying, where you got stuck, what is it that is not clear, and what is the error message you are getting? Stack Exchange works best for Q&A, and not tutorials. See How to Ask. – asheeshr Mar 2 '14 at 3:23
  • Well I have created 2 programs with the code .h and .cpp but it keeps changing .h and .cpp to _h and _cpp. – user121855 Mar 2 '14 at 3:31
  • You said that the .cpp and .h files get renamed to _cpp and _h. Could you tell us how you are creating the files? Using the new file button on the right side of the Arduino IDE? Some other way? – asheeshr Mar 2 '14 at 3:54
  • A sketch and a library are two different things. For your first experiments, you will probably not need to create any library of your own. Just write your sketch with Arduino IDE and save it the usual way. – jfpoilpret Mar 2 '14 at 9:13
1

When you save a file using the Save As button from the Arduino IDE, it saves the current file as a sketch i.e. as an .ino file.

To create a .cpp and .h files for working on a new library, you need to create the files alongside a sketch. For this, you can use the Tab button on the top right (circled in red).

enter image description here

Click on it, and select New Tab. You will get a bar at the bottom of the screen asking for a file name. Enter the name with extension (test.cpp) and press Enter.

enter image description here

Your file has now been added to the current directory.

enter image description here

Similarly, follow the same steps for creating the .h file.

Once your library is complete and ready to ship, you can move the .cpp and .h files to a separate directory and then add it under libraries.

  • do i copy the same code in .h and .cpp and what do i do after this because the tutorial i have been following is unclear – user121855 Mar 2 '14 at 5:05
  • @user121855 That deserves a separate question. That will involve a purely code-related answer, while this was more about the file structure. – asheeshr Mar 2 '14 at 5:32
  • my other question is here arduino.stackexchange.com/questions/550/… – user121855 Mar 2 '14 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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