Notifications
Clear all

Can't find Object I created

22 Posts
5 Users
1 Reactions
307 Views
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2491
 

@tfmccarthy 

Yes I could learn to how to create a library but know my limits when it comes to how much I know when it comes to writing professional grade code worth offering to others in a library which involves a clear understanding of the hardware, algorithms and mathematics involved. I personally have no reason to create a library. Learning C++ was lots of fun but there are lots of other fun things (and necessary real world things) I have to find time for too.

However if @lom has the time and desire to get up to speed on the how to of writing a library then I wish him well.

 



   
ReplyQuote
 Lom
(@lom)
Member
Joined: 1 month ago
Posts: 27
Topic starter  

@TFMcCarthy 

Don't spend too much time on it in the alternative I can copy and paste the timer code in where I need it. It was just for convenance and learning that I wanted to create a timer object.

 

Hope you can read the screen shots

 

image

This is Timer.cpp

 

This is Timer.H

image


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 502
 

Posted by: @lom

Don't spend too much time on it

This is something that I've put off for too long. Library building is a first class development task and should be covered.

Posted by: @lom

Hope you can read the screen shots

suggestion: read the Forum Help Menu item

I think I'll just use the morse code example.


The one who has the most fun, wins!


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 502
 

@lom 

The purpose of this post is to demonstrate how to make an Arduino library from your source code modules that you can use in different sketches. The library is intended for "personal" use, i.e., not for distribution but still integrated into the Arduino IDE for ease of use.

The Good News® is that creating a library from existing code is trivial. The most difficult part is the integration with the Arduino IDE and even that isn't very complex.

I'll use the example from the Arduino documentation Writing a Library for Arduino | Arduino Documentation. That document discusses creating a module ready for code reuse.

The project SOS initially has two files, SOS.ino and Morse.h

dev folder 01

Disclaimer: When I initially created the files, I didn't pay attention to the case of the file names, which I should have. So the images show files "morse.h", etc., when they should be "Morse.h". This is important for both the compiler and the IDE support. Cave canem.

When you create the Morse class, you create the implementation file Morse.cpp

dev folder 02

At this point you're ready to place the file in the Arduino library folder, which is located in the Sketchbook folder. You can find the location of the Sketchbook in the Preferences dialog.

preference

Under the Sketchbook folder there should be a folder named libraries that contains all the third-party libraries you've installed using the IDE Library Manager.

sketchbook

What's important to know is that you can create your own folder to hold your library code and the IDE will pick it up. Here I've manually added the Morse folder and copied the library files into it.

sketchbook 02

If the Arduino IDE was open at that point the library won't show up under the "Include Library" submenu.

include lib 01

You need to restart the IDE in order for it to refresh the list. When you do, the Morse library will appear, and you can add it to your sketch. When you do, the IDE will automatically insert the header file for the library (the file with the same name as the library folder) into your sketch

#include <morse.h>  // added by IDE

#include <Morse.h>

//...

Case matters! As I mentioned, I used lowercase for the folder name and the file names, and the IDE followed my lead.

That's the bare minimum you need to use the library in your sketches.

build 0

At this stage the library is for personal use and is disconnected from the IDE library manager. This means that the library is maintained manually. To connect it to the IDE library manager you must add a library.properties file to the folder under Sketchbook. Additional information about the file is found on Library specification - Arduino CLI

After adding the library.properties and restarting the IDE the library manager should display the library.

lib mgr

The file keywords.txt allows the IDE to format the code for the library properly.

sketchbook 03

Caution: once the Library manager controls the library you need to keep a permanent copy of the folder in case you decide to uninstall the library.

 


The one who has the most fun, wins!


   
Lee G reacted
ReplyQuote
 Lom
(@lom)
Member
Joined: 1 month ago
Posts: 27
Topic starter  

@tfmccarthy

 thank you for going through that. I thought I followed the same tutorial you used but could not get it to work. I think you hit on what I might have done wrong (ie capitalization).

 I’ll take a look tomorrow



   
ReplyQuote
 Lom
(@lom)
Member
Joined: 1 month ago
Posts: 27
Topic starter  

@tfmccarthy

 

I couldn't wait till tomorrow following your recommendations I did find an incorrect case issue. I corrected it and Timer appeared in the IDE library list.

image

 

 

Thanks!



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 502
 

@lom

Posted by: @lom

I couldn't wait till tomorrow

::chuckle::

Called a "programmer's itch"

In any case, I'm happy it worked for you.


The one who has the most fun, wins!


   
ReplyQuote
Page 2 / 2