Pages: [1]   Go Down
Author Topic: writing arduino library  (Read 762 times)
0 Members and 1 Guest are viewing this topic.
Texas
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What program and how do I save as .h and .ccp for a library and open a libray for editing? The moorse tutorial shows turning a sketch into a library but I don't see is how to save it as a library
Logged

Texas
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

By the way I'm using iMac Lion. any help would be appreciated.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Generally a library consists of a class split across a .h and .cpp file. If you want to use them only in one sketch, you keep them in the same folder as the .ino or .pde file. If you want to "install" them as libraries, you create a folder under sketchbook/libraries withe the exact same name as the class and copy the .h and .cpp fieles there.
Notice you have to restart the ide after you make this copy to let Arduino be aware of the new library.
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 227
Posts: 14013
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


- http://www.arduino.cc/en/Hacking/LibraryTutorial -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Should have thought about that  smiley-roll-sweat
Logged

Texas
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help, but I worded it wrong. what I needed to know was, are the libraries written in the arduino sketch and ifs so how to save it as a library. I got it to work finally by saving the 2 arduino sketches "ABC1 and ABC2" then going to documents and opining them and cut/pasted them in a new folder named ABC into the documents/arduino/libraries and then open the ABC (folder)/ABC1.ino andABC2.ino and changing ABC1.ino to ABC.h for the header and ABC2.ino to ABC.cpp for the source. I never found anything on the web that gave a clear way to do this. Is their an easier way to save these files as .h and .cpp on an iMac lion oxs
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The library tutorial link posted before is clear IMHO.

What it is that you find so hard in what you described I don't understand.
Logged

Texas
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The library tutorial link was great at teaching writing the .h and .cpp sketch but when I saved it as Morse.h and Morse.cpp and put it in documents/arduino/libraries and restarted arduino it would not show up in sketch/import libraries and if I go to documents/arduino/libraries/Morse it shows up as Morse_h.ino and Morse_cpp.ino. But I figured out how to manually rename it to Morse.h and Morse.cpp and now it shows up and works.

I'm new to using iMac and I guess I'm use to clicking save as then clicking a file type drop down box and selecting a file type in Windows
 
Again thanks for the replies
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino IDE will always consider the file you're editing as a .ino sketch. If you save it, it will try to create a dir with the name you give, and save the current file as .ino inside it. The underscore between the name and the h extension make me think you gave Morse.h as filename and it substituted the dot with an underscore.
The .h and .cpp must be created with the "New tab" command in the Arduino IDE and then moved manually to the library folder under sketchbook/libraries, or written with a standalone editor.

Anyway I guess it doesn't really matter anymore if all of this makes sense or not, since you figured it out on you own. smiley
Logged

Texas
Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Tuxduino, You help out a lot just with the word "tab". This I can see lets you work on the sketch and name it for example "ABC" then create a tab and name it ABCh for the header code and ABCcpp for the sourse code and save it in libraries. then open the ABC folder and change the name of the the file ABCh.ino to ABC.h and ABCcpp.ino to ABC.cpp. At least this is what I had to do to get it to import to a new sketch on iMac. the cool thing about using the create a tab is its all in one folder.

Just a little info about Me. I an a newbie at Arduino. Two weeks ago I was looking for something I could control with a computer for example, turn a light on and off and was introduced to "Arduino" and so for I like it. So I will be the guy "for now" that if you ask me to walk to the store and get a piece of candy, you might have to teach me how to "walk" first before I can get there. I'm sure i will have plenty of questions that have simple answers but I a sure you, it will be appreciated.


It took a someone to invent a switch and someone else to take two of them and make the and/or gate circuit that led to the electronics we have today.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So I will be the guy "for now" that if you ask me to walk to the store and get a piece of candy, you might have to teach me how to "walk" first before I can get there

Nicest metaphor ever for "newbie" smiley

Logged

Maryland, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Juat an idea...I also use Mac OS X and I prefer XCODE for writing libraries.  Check out the Apple Developer website at: http://apple.developer.com/
You may have to join for $99/year though.

HTH,
Mr. T
Logged

Pages: [1]   Go Up
Jump to: