Pages: [1]   Go Down
Author Topic: Creating a Library file type issues  (Read 1503 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just recently received my first arduino Uno from UPS.  The reason i bought the arduino was because it was based off the C++ development language which i am quite familiar with.  Following the instructions given on the link below i attempted to create a simple Library.
http://arduino.cc/en/Hacking/LibraryTutorial
I wrote all the code for both the .h and the .cpp file as well as the .pde to run the code created by the library.  The code was designed to make the built in LED blink after a specified amount of run times were completed (designed to remove the necessity of a word variable).
This was really simple and just a test to see how the library's would work in the ardunio language.  This is when i discovered the issue that i could not save the .h and .cpp files with that extension.  I would type in powerBlink.h and the message would print out saying file name issues so it changed the name as powerBlink_h.pde which was a serious annoyance because i can't save the files as needed now.

 Some notes...
1.I have devC++ on my computer so all .h and .cpp files are defaulted to open in there.
2.I tried copy and pasting the .h file into a notepad file and saving it's type as .h and then open it from arduino i get the error "Processing can only it's own sketches and files ending in .pde"
3.Probably obvious from the above comment i'm running a windows but i have linux partitioned if need be.
4.I originally had a error trying to compile my .h file something to do with my instance variables so i commented them all out but then the developing enviorment came to the conclusion since it was a .pde file i needed a loop and a setup which since it was designed as a .h i don't have.

Code in order .h, .cpp, .pde
Code:
/*should hopefully blink the LED in just one library command
  also the pulseWidth will be decided on the length of runs on
  the run time clock.
*/
#ifndef powerBlink_h
#define powerBlink_h

#include "WProgram.h"

class powerBlink{
  public:
    powerBlink (); 
    powerBlink (unsigned int _pulseWidth);
    void blinkRunTime();
  private:
    const int ledPin =  13
    int ledState = LOW;
    unsigned int time = 0;
    unsigned int pulseWidth = 0;
};

#endif
Code:
//please blink

#include "WPorgram.h"
#include "powerBlink.h"

powerBlink::powerBlink(){
  pulseWidth = 3000;
}
powerBlink::powerBlink(unsigned int _pulseWidth){
  pulseWidth = _pulseWidth;
}
void powerBlink::blinkRunTime(){
  if(time == pulseWidth){
    time = 0;
    if(ledState==LOW)
      ledState = HIGH;
     else
      ledState = LOW;
  }else{
    time++;
  }
  digitalWrite(ledPin,ledState);
}
     

Code:
#include <powerBlink.h>

powerBlink blinker();

void setup(){
  //no setup just run time computations
}

void loop(){
  blinker.blinkRunTime();
}

Thanks for any help you can give.

Logged

0
Offline Offline
Sr. Member
****
Karma: 2
Posts: 360
I'm 15. I like making things. I like breaking things better.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What exactly is your problem? You don't need to compile the header and cpp files, arduino does that for you, all you have to do is include the header.
Logged

Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 644
Posts: 50457
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you could, please, elaborate on this:
Quote
(designed to remove the necessity of a word variable).

Then, I'm interested in this:
Quote
"Processing can only it's own sketches and files ending in .pde"
Processing can only deal with .pde files. Arduino can deal with .pde files, as well as .h, .c, and .cpp files.

However, in order for it to be able to do so, all the files must be in the same directory, and there must be a .pde file in that directory. If this condition is met, any additional files in the directory with recognizable extensions are opened in separate tabs.

If you are creating your library in some other directory, then you won't be able to use the Arduino IDE to edit them.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My problem is that as far as i can tell the library is not working properly and that the files are not actually saving as .h and .cpp Lastly when i go to Sketch -> ImportLibrary... -> powerBlink  and select this rather then placed a import for the .h Arduino just places a empty line which makes it rather clear that the library is not working properly

@PaulS - The word variable comment was just to try and lower the memory size because when you use the built in timer on the Arduino the value returned becomes to large for a int rather rapidly.  Also at the error your explanation makes sense i saved the file in just some random folder but i moved the file to the same directory as the rest of the library and the same error saying it can only open it's own sketches and others ending in .pde

Also just a question i placed the _h.pde and _cpp.pde files in a Libraries folder located where the save as function default takes me to... I found a Libraries folder located where the Ardunio developing environment was saved but as far as I can tell that is just where the default libraries are saved.
Logged

0
Offline Offline
Sr. Member
****
Karma: 2
Posts: 360
I'm 15. I like making things. I like breaking things better.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First of all, they must end in .cpp and .h and this is the name you should put in the include in the .h file. Then you must place them in the libraries folder as per the tutorial.
Logged

Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?"
The cat asked, "Where do you want to go?"
"I don't know," Ali

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so the files are in the libraries directory however as i stated earlier I can not save them as .h and .cpp

When i type into the name field of the saveas. option powerBlink.h and the save as type: is set to All Files the debug terminal says   

"The sketch name had to be modified. Sketch names can only consist
of ASCII characters and numbers (but cannot start with a number).
They should also be less less than 64 characters long."
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 644
Posts: 50457
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to develop the library in a sketch directory. You need to manually include the correct .h files. When the library works, THEN you move it the the libraries directory, and create a sample sketch and use the import function to validate that the library is importable.

You've got your cart way out in front of your horse.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so i have made a .h and .cpp in that order and since i can't verify the files according to bilbo I have to assume they are all correct.  Then I move the files to the libraries directory.  Then I make a test .pde file and put that in the sketch directory.  Then i include the .h file in the test file and verify that code.

I did this in that order and still have issues I have not changed any of the code and am attempting to verify the test file (.pde) but the terminal is giving me the error

"blinkMain.cpp:1:24: error: powerBlink.h: No such file or directory
blinkMain:2: error: 'powerBlink' does not name a type
blinkMain.cpp: In function 'void loop()':
blinkMain:9: error: 'blinker' was not declared in this scope"

Also should i make the .h and .cpp files in the Ardunio environment or somewhere else?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 644
Posts: 50457
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Ok so i have made a .h and .cpp in that order and since i can't verify the files according to bilbo I have to assume they are all correct.
Wrong premise and assumption.

Quote
Then I move the files to the libraries directory.
Why? If you don't know that the code works as part of a sketch folder, making it a library is premature.

Quote
Also should i make the .h and .cpp files in the Ardunio environment or somewhere else?
If you don't like the answer you got the first time you asked, asking again will not get you an answer you like any better, since the answer will be the same.

Start from the top, and read all the answers you've already been given.

You are too focused on creating a library. A library is simply a working .h file and corresponding .cpp file that are installed in the correct sub-folder under the libraries folder. You must start with a working .h file and .cpp file in a sketch folder in the sketches folder.
Logged

Pages: [1]   Go Up
Jump to: